annotate src/userfunc.c @ 9731:f85d94eee05b v7.4.2141

commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 1 17:10:20 2016 +0200 patch 7.4.2141 Problem: Coverity reports bogus NULL check. Solution: When checking for a variable in the funccal scope don't pass the varname.
author Christian Brabandt <cb@256bit.org>
date Mon, 01 Aug 2016 17:15:06 +0200
parents 8436bb5134f5
children 59565cdd7261
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * eval.c: User defined function support
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 #include "vim.h"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 /* function flags */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 #define FC_ABORT 1 /* abort function on error */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 #define FC_RANGE 2 /* function accepts range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 #define FC_DICT 4 /* Dict function, uses "self" */
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
21 #define FC_CLOSURE 8 /* closure, uses outer scope variables */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
22 #define FC_DELETED 16 /* :delfunction used while uf_refcount > 0 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 /* From user function to hashitem and back. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 #define UF2HIKEY(fp) ((fp)->uf_name)
9593
8dced5ab4615 commit https://github.com/vim/vim/commit/0a0f641b9841189ba4180758109d04d0a26e50e3
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
26 #define HIKEY2UF(p) ((ufunc_T *)(p - offsetof(ufunc_T, uf_name)))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 #define HI2UF(hi) HIKEY2UF((hi)->hi_key)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 #define FUNCARG(fp, j) ((char_u **)(fp->uf_args.ga_data))[j]
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 #define FUNCLINE(fp, j) ((char_u **)(fp->uf_lines.ga_data))[j]
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 * All user-defined functions are found in this hashtable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 static hashtab_T func_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 /* Used by get_func_tv() */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 static garray_T funcargs = GA_EMPTY;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 /* pointer to funccal for currently active function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 funccall_T *current_funccal = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 /* pointer to list of previously used funccal, still around because some
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 * item in it is still being used. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 funccall_T *previous_funccal = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 static char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 static char *e_funcdict = N_("E717: Dictionary entry already exists");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 static char *e_funcref = N_("E718: Funcref required");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 static char *e_nofunc = N_("E130: Unknown function: %s");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 static void func_do_profile(ufunc_T *fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 static void prof_sort_list(FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 static void prof_func_line(FILE *fd, int count, proftime_T *total, proftime_T *self, int prefer_self);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 # ifdef __BORLANDC__
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 _RTLENTRYF
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 # endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 prof_total_cmp(const void *s1, const void *s2);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 # ifdef __BORLANDC__
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 _RTLENTRYF
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 # endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 prof_self_cmp(const void *s1, const void *s2);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 #endif
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
67 static void funccal_unref(funccall_T *fc, ufunc_T *fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 func_init()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 hash_init(&func_hashtab);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
75 /*
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
76 * Get function arguments.
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
77 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 get_function_args(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 char_u **argp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 char_u endchar,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 garray_T *newargs,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 int *varargs,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 int skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 int mustend = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 char_u *arg = *argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 char_u *p = arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 int c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 ga_init2(newargs, (int)sizeof(char_u *), 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 if (varargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 *varargs = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 * Isolate the arguments: "arg1, arg2, ...)"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 while (*p != endchar)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 if (p[0] == '.' && p[1] == '.' && p[2] == '.')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 if (varargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 *varargs = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 p += 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 mustend = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 arg = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 while (ASCII_ISALNUM(*p) || *p == '_')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 if (arg == p || isdigit(*arg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 || (p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 || (p - arg == 8 && STRNCMP(arg, "lastline", 8) == 0))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 if (!skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 EMSG2(_("E125: Illegal argument: %s"), arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 if (newargs != NULL && ga_grow(newargs, 1) == FAIL)
9612
0e7912e7064b commit https://github.com/vim/vim/commit/19df5cc04de93519145901d9cbc78c44d0c47c5d
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
124 goto err_ret;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 c = *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 arg = vim_strsave(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 if (arg == NULL)
9612
0e7912e7064b commit https://github.com/vim/vim/commit/19df5cc04de93519145901d9cbc78c44d0c47c5d
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
131 {
0e7912e7064b commit https://github.com/vim/vim/commit/19df5cc04de93519145901d9cbc78c44d0c47c5d
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
132 *p = c;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 goto err_ret;
9612
0e7912e7064b commit https://github.com/vim/vim/commit/19df5cc04de93519145901d9cbc78c44d0c47c5d
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
134 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 /* Check for duplicate argument name. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 for (i = 0; i < newargs->ga_len; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 if (STRCMP(((char_u **)(newargs->ga_data))[i], arg) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 EMSG2(_("E853: Duplicate argument name: %s"), arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 vim_free(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 goto err_ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 ((char_u **)(newargs->ga_data))[newargs->ga_len] = arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 newargs->ga_len++;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 *p = c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 if (*p == ',')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152 mustend = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 if (mustend && *p != endchar)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 if (!skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 EMSG2(_(e_invarg2), *argp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 }
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
162 if (*p != endchar)
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
163 goto err_ret;
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
164 ++p; /* skip "endchar" */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 *argp = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 return OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 err_ret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 ga_clear_strings(newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 return FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 /*
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
176 * Register function "fp" as using "current_funccal" as its scope.
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
177 */
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
178 static int
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
179 register_closure(ufunc_T *fp)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
180 {
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
181 funccal_unref(fp->uf_scoped, NULL);
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
182 fp->uf_scoped = current_funccal;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
183 current_funccal->fc_refcount++;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
184 if (ga_grow(&current_funccal->fc_funcs, 1) == FAIL)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
185 return FAIL;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
186 ((ufunc_T **)current_funccal->fc_funcs.ga_data)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
187 [current_funccal->fc_funcs.ga_len++] = fp;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
188 func_ptr_ref(current_funccal->func);
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
189 return OK;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
190 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
191
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
192 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 * Parse a lambda expression and get a Funcref from "*arg".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 * Return OK or FAIL. Returns NOTDONE for dict or {expr}.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
198 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 garray_T newargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200 garray_T newlines;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
201 garray_T *pnewargs;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202 ufunc_T *fp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 int varargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204 int ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
205 char_u *start = skipwhite(*arg + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206 char_u *s, *e;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 static int lambda_no = 0;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
208 int *old_eval_lavars = eval_lavars_used;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
209 int eval_lavars = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 ga_init(&newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 ga_init(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 /* First, check if this is a lambda expression. "->" must exist. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 ret = get_function_args(&start, '-', NULL, NULL, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216 if (ret == FAIL || *start != '>')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217 return NOTDONE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219 /* Parse the arguments again. */
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
220 if (evaluate)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
221 pnewargs = &newargs;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
222 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
223 pnewargs = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
224 *arg = skipwhite(*arg + 1);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
225 ret = get_function_args(arg, '-', pnewargs, &varargs, FALSE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 if (ret == FAIL || **arg != '>')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
229 /* Set up a flag for checking local variables and arguments. */
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
230 if (evaluate)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
231 eval_lavars_used = &eval_lavars;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
232
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 /* Get the start and the end of the expression. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 *arg = skipwhite(*arg + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235 s = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 ret = skip_expr(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237 if (ret == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 e = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240 *arg = skipwhite(*arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
241 if (**arg != '}')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 ++*arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 if (evaluate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
247 int len, flags = 0;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
248 char_u *p;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
249 char_u name[20];
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
250 partial_T *pt;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
252 sprintf((char*)name, "<lambda>%d", ++lambda_no);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
253
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
254 fp = (ufunc_T *)alloc_clear((unsigned)(sizeof(ufunc_T) + STRLEN(name)));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256 goto errret;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
257 pt = (partial_T *)alloc_clear((unsigned)sizeof(partial_T));
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
258 if (pt == NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
259 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
260 vim_free(fp);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
261 goto errret;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
262 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264 ga_init2(&newlines, (int)sizeof(char_u *), 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
265 if (ga_grow(&newlines, 1) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
266 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
267
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
268 /* Add "return " before the expression. */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
269 len = 7 + e - s + 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
270 p = (char_u *)alloc(len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
271 if (p == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
272 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 STRCPY(p, "return ");
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
275 vim_strncpy(p + 7, s, e - s);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
277 fp->uf_refcount = 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 STRCPY(fp->uf_name, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
279 hash_add(&func_hashtab, UF2HIKEY(fp));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280 fp->uf_args = newargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 fp->uf_lines = newlines;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
282 if (current_funccal != NULL && eval_lavars)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
283 {
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
284 flags |= FC_CLOSURE;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
285 if (register_closure(fp) == FAIL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
286 goto errret;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
287 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
288 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
289 fp->uf_scoped = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
290
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
291 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 fp->uf_tml_count = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 fp->uf_tml_total = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294 fp->uf_tml_self = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
295 fp->uf_profiling = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
296 if (prof_def_func())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 func_do_profile(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
298 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
299 fp->uf_varargs = TRUE;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
300 fp->uf_flags = flags;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301 fp->uf_calls = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 fp->uf_script_ID = current_SID;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
304 pt->pt_func = fp;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
305 pt->pt_refcount = 1;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
306 rettv->vval.v_partial = pt;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
307 rettv->v_type = VAR_PARTIAL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
309
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
310 eval_lavars_used = old_eval_lavars;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 return OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
312
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 errret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 ga_clear_strings(&newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315 ga_clear_strings(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 vim_free(fp);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
317 eval_lavars_used = old_eval_lavars;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
318 return FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
319 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
320
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322 * Check if "name" is a variable of type VAR_FUNC. If so, return the function
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 * name it contains, otherwise return "name".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324 * If "partialp" is not NULL, and "name" is of type VAR_PARTIAL also set
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
325 * "partialp".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
328 deref_func_name(char_u *name, int *lenp, partial_T **partialp, int no_autoload)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
329 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
330 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
331 int cc;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
332 char_u *s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
333
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 if (partialp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
335 *partialp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 cc = name[*lenp];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 name[*lenp] = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339 v = find_var(name, NULL, no_autoload);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
340 name[*lenp] = cc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
341 if (v != NULL && v->di_tv.v_type == VAR_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
342 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
343 if (v->di_tv.vval.v_string == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
344 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 *lenp = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346 return (char_u *)""; /* just in case */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
348 s = v->di_tv.vval.v_string;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
349 *lenp = (int)STRLEN(s);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
350 return s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
351 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 if (v != NULL && v->di_tv.v_type == VAR_PARTIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 partial_T *pt = v->di_tv.vval.v_partial;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
356
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 if (pt == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359 *lenp = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
360 return (char_u *)""; /* just in case */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
361 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
362 if (partialp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
363 *partialp = pt;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
364 s = partial_name(pt);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
365 *lenp = (int)STRLEN(s);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
366 return s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
367 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
368
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
369 return name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
370 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
371
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
372 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
373 * Give an error message with a function name. Handle <SNR> things.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
374 * "ermsg" is to be passed without translation, use N_() instead of _().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
375 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
376 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
377 emsg_funcname(char *ermsg, char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
379 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
380
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381 if (*name == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 p = concat_str((char_u *)"<SNR>", name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
383 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
384 p = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
385 EMSG2(_(ermsg), p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
386 if (p != name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
387 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
388 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
389
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
391 * Allocate a variable for the result of a function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
392 * Return OK or FAIL.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
393 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
394 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395 get_func_tv(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 char_u *name, /* name of the function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 int len, /* length of "name" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 typval_T *rettv,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
399 char_u **arg, /* argument, pointing to the '(' */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
400 linenr_T firstline, /* first line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
401 linenr_T lastline, /* last line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402 int *doesrange, /* return: function handled range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
403 int evaluate,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 partial_T *partial, /* for extra arguments */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 dict_T *selfdict) /* Dictionary for "self" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
406 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
407 char_u *argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
408 int ret = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
409 typval_T argvars[MAX_FUNC_ARGS + 1]; /* vars for arguments */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
410 int argcount = 0; /* number of arguments found */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
411
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
412 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
413 * Get the arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
414 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
415 argp = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 while (argcount < MAX_FUNC_ARGS - (partial == NULL ? 0 : partial->pt_argc))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
417 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
418 argp = skipwhite(argp + 1); /* skip the '(' or ',' */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
419 if (*argp == ')' || *argp == ',' || *argp == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
420 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
421 if (eval1(&argp, &argvars[argcount], evaluate) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 ret = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
425 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
426 ++argcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
427 if (*argp != ',')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
428 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430 if (*argp == ')')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
431 ++argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 ret = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
434
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
435 if (ret == OK)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 int i = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 if (get_vim_var_nr(VV_TESTING))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
440 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441 /* Prepare for calling test_garbagecollect_now(), need to know
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
442 * what variables are used on the call stack. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 if (funcargs.ga_itemsize == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 ga_init2(&funcargs, (int)sizeof(typval_T *), 50);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
445 for (i = 0; i < argcount; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 if (ga_grow(&funcargs, 1) == OK)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 ((typval_T **)funcargs.ga_data)[funcargs.ga_len++] =
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448 &argvars[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
451 ret = call_func(name, len, rettv, argcount, argvars, NULL,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
452 firstline, lastline, doesrange, evaluate, partial, selfdict);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454 funcargs.ga_len -= i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
456 else if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
457 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458 if (argcount == MAX_FUNC_ARGS)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
459 emsg_funcname(N_("E740: Too many arguments for function %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
460 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
461 emsg_funcname(N_("E116: Invalid arguments for function %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
462 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
463
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464 while (--argcount >= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465 clear_tv(&argvars[argcount]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 *arg = skipwhite(argp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
468 return ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
470
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 #define FLEN_FIXED 40
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
473 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 * Return TRUE if "p" starts with "<SID>" or "s:".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 * Only works if eval_fname_script() returned non-zero for "p"!
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
478 eval_fname_sid(char_u *p)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480 return (*p == 's' || TOUPPER_ASC(p[2]) == 'I');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484 * In a script change <SID>name() and s:name() to K_SNR 123_name().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 * Change <SNR>123_name() to K_SNR 123_name().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 * Use "fname_buf[FLEN_FIXED + 1]" when it fits, otherwise allocate memory
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 * (slow).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
489 static char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 int llen;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 char_u *fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
495
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 llen = eval_fname_script(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 if (llen > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
498 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 fname_buf[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500 fname_buf[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 fname_buf[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 i = 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 if (eval_fname_sid(name)) /* "<SID>" or "s:" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
504 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 if (current_SID <= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 *error = ERROR_SCRIPT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
509 sprintf((char *)fname_buf + 3, "%ld_", (long)current_SID);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 i = (int)STRLEN(fname_buf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
511 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
512 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 if (i + STRLEN(name + llen) < FLEN_FIXED)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
514 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
515 STRCPY(fname_buf + i, name + llen);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 fname = fname_buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
517 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
518 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 fname = alloc((unsigned)(i + STRLEN(name + llen) + 1));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521 if (fname == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522 *error = ERROR_OTHER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 *tofree = fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
526 mch_memmove(fname, fname_buf, (size_t)i);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
527 STRCPY(fname + i, name + llen);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
530 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 fname = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533 return fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 * Find a function by name, return pointer to it in ufuncs.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 * Return NULL for unknown function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
539 */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
540 ufunc_T *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 find_func(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543 hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 hi = hash_find(&func_hashtab, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
547 return HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
550
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
551 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
552 * Copy the function name of "fp" to buffer "buf".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
553 * "buf" must be able to hold the function name plus three bytes.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
554 * Takes care of script-local function names.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
555 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
556 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
557 cat_func_name(char_u *buf, ufunc_T *fp)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
558 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
559 if (fp->uf_name[0] == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
560 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
561 STRCPY(buf, "<SNR>");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
562 STRCAT(buf, fp->uf_name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
563 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
565 STRCPY(buf, fp->uf_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 * Add a number variable "name" to dict "dp" with value "nr".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572 add_nr_var(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 dict_T *dp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574 dictitem_T *v,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 char *name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
576 varnumber_T nr)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578 STRCPY(v->di_key, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
579 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580 hash_add(&dp->dv_hashtab, DI2HIKEY(v));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 v->di_tv.v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
582 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 v->di_tv.vval.v_number = nr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
584 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
585
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
586 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587 * Free "fc" and what it contains.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
589 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 free_funccal(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591 funccall_T *fc,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
592 int free_val) /* a: vars were allocated */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
593 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
594 listitem_T *li;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
595 int i;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
596
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
597 for (i = 0; i < fc->fc_funcs.ga_len; ++i)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
598 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
599 ufunc_T *fp = ((ufunc_T **)(fc->fc_funcs.ga_data))[i];
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
600
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
601 if (fp != NULL)
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
602 {
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
603 /* Function may have been redefined and point to another
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
604 * funccall_T, don't clear it then. */
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
605 if (fp->uf_scoped == fc)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
606 fp->uf_scoped = NULL;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
607 func_ptr_unref(fc->func);
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
608 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
609 }
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
610 ga_clear(&fc->fc_funcs);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
611
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
612 /* The a: variables typevals may not have been allocated, only free the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 * allocated variables. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 vars_clear_ext(&fc->l_avars.dv_hashtab, free_val);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
616 /* free all l: variables */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 vars_clear(&fc->l_vars.dv_hashtab);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619 /* Free the a:000 variables if they were allocated. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 if (free_val)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
621 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 clear_tv(&li->li_tv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
624 func_ptr_unref(fc->func);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 vim_free(fc);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
626 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
627
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
629 * Call a user function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
630 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632 call_user_func(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633 ufunc_T *fp, /* pointer to function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 int argcount, /* nr of args */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635 typval_T *argvars, /* arguments */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
636 typval_T *rettv, /* return value */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
637 linenr_T firstline, /* first line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
638 linenr_T lastline, /* last line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
639 dict_T *selfdict) /* Dictionary for "self" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
640 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
641 char_u *save_sourcing_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642 linenr_T save_sourcing_lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
643 scid_T save_current_SID;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
644 funccall_T *fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
645 int save_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
646 static int depth = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
647 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
648 int fixvar_idx = 0; /* index in fixvar[] */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
649 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
650 int ai;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
651 int islambda = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
652 char_u numbuf[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
653 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
654 size_t len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
655 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
656 proftime_T wait_start;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
657 proftime_T call_start;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
658 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
659
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
660 /* If depth of calling is getting too high, don't execute the function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
661 if (depth >= p_mfd)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
662 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
663 EMSG(_("E132: Function call depth is higher than 'maxfuncdepth'"));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
664 rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
665 rettv->vval.v_number = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
667 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
668 ++depth;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
669
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
670 line_breakcheck(); /* check for CTRL-C hit */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
672 fc = (funccall_T *)alloc(sizeof(funccall_T));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
673 fc->caller = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
674 current_funccal = fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
675 fc->func = fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
676 fc->rettv = rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
677 rettv->vval.v_number = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
678 fc->linenr = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
679 fc->returned = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
680 fc->level = ex_nesting_level;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
681 /* Check if this function has a breakpoint. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682 fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
683 fc->dbg_tick = debug_tick;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
684 /* Set up fields for closure. */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
685 fc->fc_refcount = 0;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
686 fc->fc_copyID = 0;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
687 ga_init2(&fc->fc_funcs, sizeof(ufunc_T *), 1);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
688 func_ptr_ref(fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
689
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
690 if (STRNCMP(fp->uf_name, "<lambda>", 8) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691 islambda = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
692
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
693 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
694 * Note about using fc->fixvar[]: This is an array of FIXVAR_CNT variables
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
695 * with names up to VAR_SHORT_LEN long. This avoids having to alloc/free
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
696 * each argument variable and saves a lot of time.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
697 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
698 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 * Init l: variables.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
700 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
701 init_var_dict(&fc->l_vars, &fc->l_vars_var, VAR_DEF_SCOPE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
702 if (selfdict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
703 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
704 /* Set l:self to "selfdict". Use "name" to avoid a warning from
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
705 * some compiler that checks the destination size. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
706 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
707 name = v->di_key;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
708 STRCPY(name, "self");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
709 v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
710 hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
711 v->di_tv.v_type = VAR_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
712 v->di_tv.v_lock = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
713 v->di_tv.vval.v_dict = selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
714 ++selfdict->dv_refcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
715 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
716
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718 * Init a: variables.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
719 * Set a:0 to "argcount".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
720 * Set a:000 to a list with room for the "..." arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
721 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
722 init_var_dict(&fc->l_avars, &fc->l_avars_var, VAR_SCOPE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "0",
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
724 (varnumber_T)(argcount - fp->uf_args.ga_len));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725 /* Use "name" to avoid a warning from some compiler that checks the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
726 * destination size. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
728 name = v->di_key;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
729 STRCPY(name, "000");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
730 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
731 hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
732 v->di_tv.v_type = VAR_LIST;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
733 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
734 v->di_tv.vval.v_list = &fc->l_varlist;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735 vim_memset(&fc->l_varlist, 0, sizeof(list_T));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
736 fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
737 fc->l_varlist.lv_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
738
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
739 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
740 * Set a:firstline to "firstline" and a:lastline to "lastline".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
741 * Set a:name to named arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
742 * Set a:N to the "..." arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
743 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
744 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "firstline",
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
745 (varnumber_T)firstline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
746 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "lastline",
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
747 (varnumber_T)lastline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
748 for (i = 0; i < argcount; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
749 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
750 int addlocal = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
751
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
752 ai = i - fp->uf_args.ga_len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
753 if (ai < 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
754 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
755 /* named argument a:name */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
756 name = FUNCARG(fp, i);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
757 if (islambda)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
758 addlocal = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
759 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
760 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
761 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
762 /* "..." argument a:1, a:2, etc. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
763 sprintf((char *)numbuf, "%d", ai + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
764 name = numbuf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
765 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
766 if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
767 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
768 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
769 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
770 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
772 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
773 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774 + STRLEN(name)));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
775 if (v == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
776 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
777 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX | DI_FLAGS_ALLOC;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
778 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
779 STRCPY(v->di_key, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
780
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
781 /* Note: the values are copied directly to avoid alloc/free.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
782 * "argvars" must have VAR_FIXED for v_lock. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
783 v->di_tv = argvars[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
784 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
785
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
786 if (addlocal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
787 {
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
788 /* Named arguments should be accessed without the "a:" prefix in
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
789 * lambda expressions. Add to the l: dict. */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
790 copy_tv(&v->di_tv, &v->di_tv);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
791 hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
792 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
793 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
794 hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
796 if (ai >= 0 && ai < MAX_FUNC_ARGS)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
798 list_append(&fc->l_varlist, &fc->l_listitems[ai]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
799 fc->l_listitems[ai].li_tv = argvars[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
800 fc->l_listitems[ai].li_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
801 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
802 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
803
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 /* Don't redraw while executing the function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 ++RedrawingDisabled;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806 save_sourcing_name = sourcing_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
807 save_sourcing_lnum = sourcing_lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
808 sourcing_lnum = 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
809 /* need space for function name + ("function " + 3) or "[number]" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
810 len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
811 + STRLEN(fp->uf_name) + 20;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
812 sourcing_name = alloc((unsigned)len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
813 if (sourcing_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
814 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
815 if (save_sourcing_name != NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
816 && STRNCMP(save_sourcing_name, "function ", 9) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
817 sprintf((char *)sourcing_name, "%s[%d]..",
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
818 save_sourcing_name, (int)save_sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
819 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
820 STRCPY(sourcing_name, "function ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 cat_func_name(sourcing_name + STRLEN(sourcing_name), fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
822
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
823 if (p_verbose >= 12)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
824 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
825 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
826 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
827
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
828 smsg((char_u *)_("calling %s"), sourcing_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
829 if (p_verbose >= 14)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
830 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
831 char_u buf[MSG_BUF_LEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
832 char_u numbuf2[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
833 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
834 char_u *s;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
835
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
836 msg_puts((char_u *)"(");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
837 for (i = 0; i < argcount; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
838 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
839 if (i > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
840 msg_puts((char_u *)", ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
841 if (argvars[i].v_type == VAR_NUMBER)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
842 msg_outnum((long)argvars[i].vval.v_number);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
843 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
844 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
845 /* Do not want errors such as E724 here. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
846 ++emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
847 s = tv2string(&argvars[i], &tofree, numbuf2, 0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
848 --emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
849 if (s != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
850 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 if (vim_strsize(s) > MSG_BUF_CLEN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
852 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
854 s = buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
855 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
856 msg_puts(s);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
857 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
858 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
859 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
860 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
861 msg_puts((char_u *)")");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
862 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
863 msg_puts((char_u *)"\n"); /* don't overwrite this either */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
864
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
865 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
866 --no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
867 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
868 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
869 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
870 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
871 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
872 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
873 func_do_profile(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
874 if (fp->uf_profiling
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
875 || (fc->caller != NULL && fc->caller->func->uf_profiling))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
876 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
877 ++fp->uf_tm_count;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
878 profile_start(&call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
879 profile_zero(&fp->uf_tm_children);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
880 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
881 script_prof_save(&wait_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
882 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
883 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
884
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
885 save_current_SID = current_SID;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
886 current_SID = fp->uf_script_ID;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
887 save_did_emsg = did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
888 did_emsg = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
889
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
890 /* call do_cmdline() to execute the lines */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
891 do_cmdline(NULL, get_func_line, (void *)fc,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
892 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
893
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
894 --RedrawingDisabled;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
895
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
896 /* when the function was aborted because of an error, return -1 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
897 if ((did_emsg && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
898 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
899 clear_tv(rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
900 rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
901 rettv->vval.v_number = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
902 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
903
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
904 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
905 if (do_profiling == PROF_YES && (fp->uf_profiling
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
906 || (fc->caller != NULL && fc->caller->func->uf_profiling)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
907 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
908 profile_end(&call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
909 profile_sub_wait(&wait_start, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
910 profile_add(&fp->uf_tm_total, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
911 profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
912 if (fc->caller != NULL && fc->caller->func->uf_profiling)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
913 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
914 profile_add(&fc->caller->func->uf_tm_children, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
915 profile_add(&fc->caller->func->uf_tml_children, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
916 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
917 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
918 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
919
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
920 /* when being verbose, mention the return value */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
921 if (p_verbose >= 12)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
922 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
923 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
924 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
925
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
926 if (aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
927 smsg((char_u *)_("%s aborted"), sourcing_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
928 else if (fc->rettv->v_type == VAR_NUMBER)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
929 smsg((char_u *)_("%s returning #%ld"), sourcing_name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
930 (long)fc->rettv->vval.v_number);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
931 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
932 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
933 char_u buf[MSG_BUF_LEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
934 char_u numbuf2[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
935 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
936 char_u *s;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
937
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
938 /* The value may be very long. Skip the middle part, so that we
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
939 * have some idea how it starts and ends. smsg() would always
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
940 * truncate it at the end. Don't want errors such as E724 here. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
941 ++emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
942 s = tv2string(fc->rettv, &tofree, numbuf2, 0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
943 --emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
944 if (s != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
945 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
946 if (vim_strsize(s) > MSG_BUF_CLEN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
947 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
948 trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
949 s = buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
950 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
951 smsg((char_u *)_("%s returning %s"), sourcing_name, s);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
952 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
953 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
954 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
955 msg_puts((char_u *)"\n"); /* don't overwrite this either */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
956
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
957 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958 --no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
960
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
961 vim_free(sourcing_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
962 sourcing_name = save_sourcing_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
963 sourcing_lnum = save_sourcing_lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
964 current_SID = save_current_SID;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
965 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
966 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
967 script_prof_restore(&wait_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
968 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
969
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
970 if (p_verbose >= 12 && sourcing_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
971 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
972 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
973 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
974
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
975 smsg((char_u *)_("continuing in %s"), sourcing_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
976 msg_puts((char_u *)"\n"); /* don't overwrite this either */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
977
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
978 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
979 --no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
980 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
981
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
982 did_emsg |= save_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
983 current_funccal = fc->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
984 --depth;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
985
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
986 /* If the a:000 list and the l: and a: dicts are not referenced and there
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
987 * is no closure using it, we can free the funccall_T and what's in it. */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
988 if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
989 && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
990 && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
991 && fc->fc_refcount <= 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
992 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
993 free_funccal(fc, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
994 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
995 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
996 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
997 hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
998 listitem_T *li;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
999 int todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1000
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1001 /* "fc" is still in use. This can happen when returning "a:000",
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1002 * assigning "l:" to a global variable or defining a closure.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1003 * Link "fc" in the list for garbage collection later. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1004 fc->caller = previous_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1005 previous_funccal = fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1006
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1007 /* Make a copy of the a: variables, since we didn't do that above. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1008 todo = (int)fc->l_avars.dv_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1009 for (hi = fc->l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1010 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1011 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1012 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1013 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1014 v = HI2DI(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1015 copy_tv(&v->di_tv, &v->di_tv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1016 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1017 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1018
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1019 /* Make a copy of the a:000 items, since we didn't do that above. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1020 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1021 copy_tv(&li->li_tv, &li->li_tv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1022 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1023 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1024
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1025 /*
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1026 * Unreference "fc": decrement the reference count and free it when it
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1027 * becomes zero. If "fp" is not NULL, "fp" is detached from "fc".
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1028 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1029 static void
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1030 funccal_unref(funccall_T *fc, ufunc_T *fp)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1031 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1032 funccall_T **pfc;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1033 int i;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1034 int freed = FALSE;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1035
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1036 if (fc == NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1037 return;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1038
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1039 if (--fc->fc_refcount <= 0)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1040 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1041 for (pfc = &previous_funccal; *pfc != NULL; pfc = &(*pfc)->caller)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1042 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1043 if (fc == *pfc)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1044 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1045 if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1046 && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1047 && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1048 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1049 *pfc = fc->caller;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1050 free_funccal(fc, TRUE);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1051 freed = TRUE;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1052 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1053 break;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1054 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1055 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1056 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1057 if (!freed)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1058 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1059 func_ptr_unref(fc->func);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1060
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1061 if (fp != NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1062 for (i = 0; i < fc->fc_funcs.ga_len; ++i)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1063 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1064 if (((ufunc_T **)(fc->fc_funcs.ga_data))[i] == fp)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1065 ((ufunc_T **)(fc->fc_funcs.ga_data))[i] = NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1066 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1067 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1068 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1069
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1070 /*
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1071 * Remove the function from the function hashtable. If the function was
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1072 * deleted while it still has references this was already done.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1073 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1074 static void
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1075 func_remove(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1076 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1077 hashitem_T *hi = hash_find(&func_hashtab, UF2HIKEY(fp));
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1078
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1079 if (!HASHITEM_EMPTY(hi))
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1080 hash_remove(&func_hashtab, hi);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1081 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1082
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1083 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1084 * Free a function and remove it from the list of functions.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1085 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1086 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1087 func_free(ufunc_T *fp)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1088 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1089 /* clear this function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1090 ga_clear_strings(&(fp->uf_args));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1091 ga_clear_strings(&(fp->uf_lines));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1092 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1093 vim_free(fp->uf_tml_count);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1094 vim_free(fp->uf_tml_total);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1095 vim_free(fp->uf_tml_self);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1096 #endif
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1097 func_remove(fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1098
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1099 funccal_unref(fp->uf_scoped, fp);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1100
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1101 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1102 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1103
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1104 #if defined(EXITFREE) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1105 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1106 free_all_functions(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1107 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1108 hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1109
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1110 /* Need to start all over every time, because func_free() may change the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1111 * hash table. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1112 while (func_hashtab.ht_used > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1113 for (hi = func_hashtab.ht_array; ; ++hi)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1114 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1115 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1116 func_free(HI2UF(hi));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1117 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1118 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1119 hash_clear(&func_hashtab);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1120 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1121 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1122
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1123 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1124 * Return TRUE if "name" looks like a builtin function name: starts with a
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1125 * lower case letter and doesn't contain AUTOLOAD_CHAR.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1126 * "len" is the length of "name", or -1 for NUL terminated.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1127 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1128 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1129 builtin_function(char_u *name, int len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1130 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1131 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1132
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1133 if (!ASCII_ISLOWER(name[0]))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1134 return FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1135 p = vim_strchr(name, AUTOLOAD_CHAR);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1136 return p == NULL || (len > 0 && p > name + len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1137 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1138
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1139 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1140 func_call(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1141 char_u *name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1142 typval_T *args,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1143 partial_T *partial,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1144 dict_T *selfdict,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1145 typval_T *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1146 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1147 listitem_T *item;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1148 typval_T argv[MAX_FUNC_ARGS + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1149 int argc = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1150 int dummy;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1151 int r = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1152
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1153 for (item = args->vval.v_list->lv_first; item != NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1154 item = item->li_next)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1155 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1156 if (argc == MAX_FUNC_ARGS - (partial == NULL ? 0 : partial->pt_argc))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1157 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1158 EMSG(_("E699: Too many arguments"));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1159 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1160 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1161 /* Make a copy of each argument. This is needed to be able to set
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1162 * v_lock to VAR_FIXED in the copy without changing the original list.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1163 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1164 copy_tv(&item->li_tv, &argv[argc++]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1165 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1166
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1167 if (item == NULL)
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1168 r = call_func(name, (int)STRLEN(name), rettv, argc, argv, NULL,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1169 curwin->w_cursor.lnum, curwin->w_cursor.lnum,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1170 &dummy, TRUE, partial, selfdict);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1171
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1172 /* Free the arguments. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1173 while (argc > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1174 clear_tv(&argv[--argc]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1175
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1176 return r;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1177 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1178
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1179 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1180 * Call a function with its resolved parameters
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1181 *
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1182 * "argv_func", when not NULL, can be used to fill in arguments only when the
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1183 * invoked function uses them. It is called like this:
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1184 * new_argcount = argv_func(current_argcount, argv, called_func_argcount)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1185 *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1186 * Return FAIL when the function can't be called, OK otherwise.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1187 * Also returns OK when an error was encountered while executing the function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1188 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1189 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1190 call_func(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1191 char_u *funcname, /* name of the function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1192 int len, /* length of "name" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1193 typval_T *rettv, /* return value goes here */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1194 int argcount_in, /* number of "argvars" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1195 typval_T *argvars_in, /* vars for arguments, must have "argcount"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1196 PLUS ONE elements! */
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1197 int (* argv_func)(int, typval_T *, int),
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1198 /* function to fill in argvars */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1199 linenr_T firstline, /* first line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1200 linenr_T lastline, /* last line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1201 int *doesrange, /* return: function handled range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1202 int evaluate,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1203 partial_T *partial, /* optional, can be NULL */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1204 dict_T *selfdict_in) /* Dictionary for "self" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1205 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1206 int ret = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1207 int error = ERROR_NONE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1208 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1209 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1210 char_u fname_buf[FLEN_FIXED + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1211 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1212 char_u *fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1213 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1214 int argcount = argcount_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1215 typval_T *argvars = argvars_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1216 dict_T *selfdict = selfdict_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1217 typval_T argv[MAX_FUNC_ARGS + 1]; /* used when "partial" is not NULL */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1218 int argv_clear = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1219
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1220 /* Make a copy of the name, if it comes from a funcref variable it could
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1221 * be changed or deleted in the called function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1222 name = vim_strnsave(funcname, len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1223 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1224 return ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1225
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1226 fname = fname_trans_sid(name, fname_buf, &tofree, &error);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1227
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1228 *doesrange = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1229
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1230 if (partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1231 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1232 /* When the function has a partial with a dict and there is a dict
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1233 * argument, use the dict argument. That is backwards compatible.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1234 * When the dict was bound explicitly use the one from the partial. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1235 if (partial->pt_dict != NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1236 && (selfdict_in == NULL || !partial->pt_auto))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1237 selfdict = partial->pt_dict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1238 if (error == ERROR_NONE && partial->pt_argc > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1239 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1240 for (argv_clear = 0; argv_clear < partial->pt_argc; ++argv_clear)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1241 copy_tv(&partial->pt_argv[argv_clear], &argv[argv_clear]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1242 for (i = 0; i < argcount_in; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1243 argv[i + argv_clear] = argvars_in[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1244 argvars = argv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1245 argcount = partial->pt_argc + argcount_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1246 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1247 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1248
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1249
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1250 /* execute the function if no errors detected and executing */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1251 if (evaluate && error == ERROR_NONE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1252 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1253 char_u *rfname = fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1254
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1255 /* Ignore "g:" before a function name. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1256 if (fname[0] == 'g' && fname[1] == ':')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1257 rfname = fname + 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1258
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1259 rettv->v_type = VAR_NUMBER; /* default rettv is number zero */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1260 rettv->vval.v_number = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1261 error = ERROR_UNKNOWN;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1262
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1263 if (!builtin_function(rfname, -1))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1264 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1265 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1266 * User defined function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1267 */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1268 if (partial != NULL && partial->pt_func != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1269 fp = partial->pt_func;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1270 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1271 fp = find_func(rfname);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1272
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1273 #ifdef FEAT_AUTOCMD
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1274 /* Trigger FuncUndefined event, may load the function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1275 if (fp == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1276 && apply_autocmds(EVENT_FUNCUNDEFINED,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1277 rfname, rfname, TRUE, NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1278 && !aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1279 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1280 /* executed an autocommand, search for the function again */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1281 fp = find_func(rfname);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1282 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1283 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1284 /* Try loading a package. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1285 if (fp == NULL && script_autoload(rfname, TRUE) && !aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1286 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1287 /* loaded a package, search for the function again */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1288 fp = find_func(rfname);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1289 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1290
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1291 if (fp != NULL && (fp->uf_flags & FC_DELETED))
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1292 error = ERROR_DELETED;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1293 else if (fp != NULL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1294 {
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1295 if (argv_func != NULL)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1296 argcount = argv_func(argcount, argvars, fp->uf_args.ga_len);
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1297
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1298 if (fp->uf_flags & FC_RANGE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1299 *doesrange = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1300 if (argcount < fp->uf_args.ga_len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1301 error = ERROR_TOOFEW;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1302 else if (!fp->uf_varargs && argcount > fp->uf_args.ga_len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1303 error = ERROR_TOOMANY;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1304 else if ((fp->uf_flags & FC_DICT) && selfdict == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1305 error = ERROR_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1306 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1307 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1308 int did_save_redo = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1309
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1310 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1311 * Call the user function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1312 * Save and restore search patterns, script variables and
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1313 * redo buffer.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1314 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1315 save_search_patterns();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1316 #ifdef FEAT_INS_EXPAND
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1317 if (!ins_compl_active())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1318 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1319 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1320 saveRedobuff();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1321 did_save_redo = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1322 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1323 ++fp->uf_calls;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1324 call_user_func(fp, argcount, argvars, rettv,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1325 firstline, lastline,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1326 (fp->uf_flags & FC_DICT) ? selfdict : NULL);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1327 if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1328 /* Function was unreferenced while being used, free it
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1329 * now. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1330 func_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1331 if (did_save_redo)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1332 restoreRedobuff();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1333 restore_search_patterns();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1334 error = ERROR_NONE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1335 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1336 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1337 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1338 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1339 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1340 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1341 * Find the function name in the table, call its implementation.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1342 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1343 error = call_internal_func(fname, argcount, argvars, rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1344 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1345 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1346 * The function call (or "FuncUndefined" autocommand sequence) might
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1347 * have been aborted by an error, an interrupt, or an explicitly thrown
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1348 * exception that has not been caught so far. This situation can be
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1349 * tested for by calling aborting(). For an error in an internal
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1350 * function or for the "E132" error in call_user_func(), however, the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1351 * throw point at which the "force_abort" flag (temporarily reset by
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1352 * emsg()) is normally updated has not been reached yet. We need to
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1353 * update that flag first to make aborting() reliable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1354 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1355 update_force_abort();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1356 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1357 if (error == ERROR_NONE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1358 ret = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1359
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1360 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1361 * Report an error unless the argument evaluation or function call has been
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1362 * cancelled due to an aborting error, an interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1363 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1364 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1365 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1366 switch (error)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1367 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1368 case ERROR_UNKNOWN:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1369 emsg_funcname(N_("E117: Unknown function: %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1370 break;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1371 case ERROR_DELETED:
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1372 emsg_funcname(N_("E933: Function was deleted: %s"), name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1373 break;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1374 case ERROR_TOOMANY:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1375 emsg_funcname((char *)e_toomanyarg, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1376 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1377 case ERROR_TOOFEW:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1378 emsg_funcname(N_("E119: Not enough arguments for function: %s"),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1379 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1380 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1381 case ERROR_SCRIPT:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1382 emsg_funcname(N_("E120: Using <SID> not in a script context: %s"),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1383 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1384 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1385 case ERROR_DICT:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1386 emsg_funcname(N_("E725: Calling dict function without Dictionary: %s"),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1387 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1388 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1389 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1390 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1391
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1392 while (argv_clear > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1393 clear_tv(&argv[--argv_clear]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1394 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1395 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1396
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1397 return ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1398 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1399
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1400 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1401 * List the head of the function: "name(arg1, arg2)".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1402 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1403 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1404 list_func_head(ufunc_T *fp, int indent)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1405 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1406 int j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1407
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1408 msg_start();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1409 if (indent)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1410 MSG_PUTS(" ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1411 MSG_PUTS("function ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1412 if (fp->uf_name[0] == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1413 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1414 MSG_PUTS_ATTR("<SNR>", hl_attr(HLF_8));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1415 msg_puts(fp->uf_name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1416 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1417 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1418 msg_puts(fp->uf_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1419 msg_putchar('(');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1420 for (j = 0; j < fp->uf_args.ga_len; ++j)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1421 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1422 if (j)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1423 MSG_PUTS(", ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1424 msg_puts(FUNCARG(fp, j));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1425 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1426 if (fp->uf_varargs)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1427 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1428 if (j)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1429 MSG_PUTS(", ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1430 MSG_PUTS("...");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1431 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1432 msg_putchar(')');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1433 if (fp->uf_flags & FC_ABORT)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1434 MSG_PUTS(" abort");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1435 if (fp->uf_flags & FC_RANGE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1436 MSG_PUTS(" range");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1437 if (fp->uf_flags & FC_DICT)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1438 MSG_PUTS(" dict");
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1439 if (fp->uf_flags & FC_CLOSURE)
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1440 MSG_PUTS(" closure");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1441 msg_clr_eos();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1442 if (p_verbose > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1443 last_set_msg(fp->uf_script_ID);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1444 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1445
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1446 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1447 * Get a function name, translating "<SID>" and "<SNR>".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1448 * Also handles a Funcref in a List or Dictionary.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1449 * Returns the function name in allocated memory, or NULL for failure.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1450 * flags:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1451 * TFN_INT: internal function name OK
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1452 * TFN_QUIET: be quiet
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1453 * TFN_NO_AUTOLOAD: do not use script autoloading
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
1454 * TFN_NO_DEREF: do not dereference a Funcref
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1455 * Advances "pp" to just after the function name (if no error).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1456 */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1457 char_u *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1458 trans_function_name(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1459 char_u **pp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1460 int skip, /* only find the end, don't evaluate */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1461 int flags,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1462 funcdict_T *fdp, /* return: info about dictionary used */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1463 partial_T **partial) /* return: partial of a FuncRef */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1464 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1465 char_u *name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1466 char_u *start;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1467 char_u *end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1468 int lead;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1469 char_u sid_buf[20];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1470 int len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1471 lval_T lv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1472
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1473 if (fdp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1474 vim_memset(fdp, 0, sizeof(funcdict_T));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1475 start = *pp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1476
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1477 /* Check for hard coded <SNR>: already translated function ID (from a user
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1478 * command). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1479 if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1480 && (*pp)[2] == (int)KE_SNR)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1481 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1482 *pp += 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1483 len = get_id_len(pp) + 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1484 return vim_strnsave(start, len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1485 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1486
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1487 /* A name starting with "<SID>" or "<SNR>" is local to a script. But
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1488 * don't skip over "s:", get_lval() needs it for "s:dict.func". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1489 lead = eval_fname_script(start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1490 if (lead > 2)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1491 start += lead;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1492
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1493 /* Note that TFN_ flags use the same values as GLV_ flags. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1494 end = get_lval(start, NULL, &lv, FALSE, skip, flags,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1495 lead > 2 ? 0 : FNE_CHECK_START);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1496 if (end == start)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1497 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1498 if (!skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1499 EMSG(_("E129: Function name required"));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1500 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1501 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1502 if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1503 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1504 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1505 * Report an invalid expression in braces, unless the expression
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1506 * evaluation has been cancelled due to an aborting error, an
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1507 * interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1508 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1509 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1510 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1511 if (end != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1512 EMSG2(_(e_invarg2), start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1513 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1514 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1515 *pp = find_name_end(start, NULL, NULL, FNE_INCL_BR);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1516 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1517 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1518
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1519 if (lv.ll_tv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1520 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1521 if (fdp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1522 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1523 fdp->fd_dict = lv.ll_dict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1524 fdp->fd_newkey = lv.ll_newkey;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1525 lv.ll_newkey = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1526 fdp->fd_di = lv.ll_di;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1527 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1528 if (lv.ll_tv->v_type == VAR_FUNC && lv.ll_tv->vval.v_string != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1529 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1530 name = vim_strsave(lv.ll_tv->vval.v_string);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1531 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1532 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1533 else if (lv.ll_tv->v_type == VAR_PARTIAL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1534 && lv.ll_tv->vval.v_partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1535 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1536 name = vim_strsave(partial_name(lv.ll_tv->vval.v_partial));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1537 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1538 if (partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1539 *partial = lv.ll_tv->vval.v_partial;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1540 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1541 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1542 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1543 if (!skip && !(flags & TFN_QUIET) && (fdp == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1544 || lv.ll_dict == NULL || fdp->fd_newkey == NULL))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1545 EMSG(_(e_funcref));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1546 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1547 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1548 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1549 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1550 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1551 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1552
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1553 if (lv.ll_name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1554 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1555 /* Error found, but continue after the function name. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1556 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1557 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1558 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1559
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1560 /* Check if the name is a Funcref. If so, use the value. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1561 if (lv.ll_exp_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1562 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1563 len = (int)STRLEN(lv.ll_exp_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1564 name = deref_func_name(lv.ll_exp_name, &len, partial,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1565 flags & TFN_NO_AUTOLOAD);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1566 if (name == lv.ll_exp_name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1567 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1568 }
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
1569 else if (!(flags & TFN_NO_DEREF))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1570 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1571 len = (int)(end - *pp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1572 name = deref_func_name(*pp, &len, partial, flags & TFN_NO_AUTOLOAD);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1573 if (name == *pp)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1574 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1575 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1576 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1577 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1578 name = vim_strsave(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1579 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1580 if (STRNCMP(name, "<SNR>", 5) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1581 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1582 /* Change "<SNR>" to the byte sequence. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1583 name[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1584 name[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1585 name[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1586 mch_memmove(name + 3, name + 5, STRLEN(name + 5) + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1587 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1588 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1589 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1590
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1591 if (lv.ll_exp_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1592 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1593 len = (int)STRLEN(lv.ll_exp_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1594 if (lead <= 2 && lv.ll_name == lv.ll_exp_name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1595 && STRNCMP(lv.ll_name, "s:", 2) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1596 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1597 /* When there was "s:" already or the name expanded to get a
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1598 * leading "s:" then remove it. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1599 lv.ll_name += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1600 len -= 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1601 lead = 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1602 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1603 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1604 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1605 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1606 /* skip over "s:" and "g:" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1607 if (lead == 2 || (lv.ll_name[0] == 'g' && lv.ll_name[1] == ':'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1608 lv.ll_name += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1609 len = (int)(end - lv.ll_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1610 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1611
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1612 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1613 * Copy the function name to allocated memory.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1614 * Accept <SID>name() inside a script, translate into <SNR>123_name().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1615 * Accept <SNR>123_name() outside a script.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1616 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1617 if (skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1618 lead = 0; /* do nothing */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1619 else if (lead > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1620 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1621 lead = 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1622 if ((lv.ll_exp_name != NULL && eval_fname_sid(lv.ll_exp_name))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1623 || eval_fname_sid(*pp))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1624 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1625 /* It's "s:" or "<SID>" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1626 if (current_SID <= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1627 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1628 EMSG(_(e_usingsid));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1629 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1630 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1631 sprintf((char *)sid_buf, "%ld_", (long)current_SID);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1632 lead += (int)STRLEN(sid_buf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1633 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1634 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1635 else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1636 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1637 EMSG2(_("E128: Function name must start with a capital or \"s:\": %s"),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1638 start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1639 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1640 }
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
1641 if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1642 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1643 char_u *cp = vim_strchr(lv.ll_name, ':');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1644
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1645 if (cp != NULL && cp < end)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1646 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1647 EMSG2(_("E884: Function name cannot contain a colon: %s"), start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1648 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1649 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1650 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1651
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1652 name = alloc((unsigned)(len + lead + 1));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1653 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1654 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1655 if (lead > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1656 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1657 name[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1658 name[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1659 name[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1660 if (lead > 3) /* If it's "<SID>" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1661 STRCPY(name + 3, sid_buf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1662 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1663 mch_memmove(name + lead, lv.ll_name, (size_t)len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1664 name[lead + len] = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1665 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1666 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1667
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1668 theend:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1669 clear_lval(&lv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1670 return name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1671 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1672
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1673 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1674 * ":function"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1675 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1676 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1677 ex_function(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1678 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1679 char_u *theline;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1680 int j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1681 int c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1682 int saved_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1683 int saved_wait_return = need_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1684 char_u *name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1685 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1686 char_u *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1687 char_u *line_arg = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1688 garray_T newargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1689 garray_T newlines;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1690 int varargs = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1691 int flags = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1692 ufunc_T *fp;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1693 int overwrite = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1694 int indent;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1695 int nesting;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1696 char_u *skip_until = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1697 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1698 funcdict_T fudi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1699 static int func_nr = 0; /* number for nameless function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1700 int paren;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1701 hashtab_T *ht;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1702 int todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1703 hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1704 int sourcing_lnum_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1705
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1706 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1707 * ":function" without argument: list functions.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1708 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1709 if (ends_excmd(*eap->arg))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1710 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1711 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1712 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1713 todo = (int)func_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1714 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1715 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1716 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1717 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1718 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1719 fp = HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1720 if (!isdigit(*fp->uf_name))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1721 list_func_head(fp, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1722 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1723 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1724 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1725 eap->nextcmd = check_nextcmd(eap->arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1726 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1727 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1728
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1729 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1730 * ":function /pat": list functions matching pattern.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1731 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1732 if (*eap->arg == '/')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1733 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1734 p = skip_regexp(eap->arg + 1, '/', TRUE, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1735 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1736 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1737 regmatch_T regmatch;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1738
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1739 c = *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1740 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1741 regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1742 *p = c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1743 if (regmatch.regprog != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1744 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1745 regmatch.rm_ic = p_ic;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1746
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1747 todo = (int)func_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1748 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1749 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1750 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1751 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1752 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1753 fp = HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1754 if (!isdigit(*fp->uf_name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1755 && vim_regexec(&regmatch, fp->uf_name, 0))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1756 list_func_head(fp, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1757 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1758 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1759 vim_regfree(regmatch.regprog);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1760 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1761 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1762 if (*p == '/')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1763 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1764 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1765 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1766 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1767
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1768 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1769 * Get the function name. There are these situations:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1770 * func normal function name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1771 * "name" == func, "fudi.fd_dict" == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1772 * dict.func new dictionary entry
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1773 * "name" == NULL, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1774 * "fudi.fd_di" == NULL, "fudi.fd_newkey" == func
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1775 * dict.func existing dict entry with a Funcref
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1776 * "name" == func, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1777 * "fudi.fd_di" set, "fudi.fd_newkey" == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1778 * dict.func existing dict entry that's not a Funcref
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1779 * "name" == NULL, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1780 * "fudi.fd_di" set, "fudi.fd_newkey" == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1781 * s:func script-local function name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1782 * g:func global function name, same as "func"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1783 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1784 p = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1785 name = trans_function_name(&p, eap->skip, 0, &fudi, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786 paren = (vim_strchr(p, '(') != NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1787 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1788 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1789 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1790 * Return on an invalid expression in braces, unless the expression
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1791 * evaluation has been cancelled due to an aborting error, an
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1792 * interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1793 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1794 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1795 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1796 if (!eap->skip && fudi.fd_newkey != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1797 EMSG2(_(e_dictkey), fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1798 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1799 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1800 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1801 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1802 eap->skip = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1803 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1804
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1805 /* An error in a function call during evaluation of an expression in magic
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1806 * braces should not cause the function not to be defined. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1807 saved_did_emsg = did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1808 did_emsg = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1809
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1810 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1811 * ":function func" with only function name: list function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1812 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1813 if (!paren)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1814 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1815 if (!ends_excmd(*skipwhite(p)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1816 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1817 EMSG(_(e_trailing));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1818 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1819 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1820 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1821 if (eap->nextcmd != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1822 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1823 if (!eap->skip && !got_int)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1824 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1825 fp = find_func(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1826 if (fp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1827 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1828 list_func_head(fp, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1829 for (j = 0; j < fp->uf_lines.ga_len && !got_int; ++j)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1830 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1831 if (FUNCLINE(fp, j) == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1832 continue;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1833 msg_putchar('\n');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1834 msg_outnum((long)(j + 1));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1835 if (j < 9)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1836 msg_putchar(' ');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1837 if (j < 99)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1838 msg_putchar(' ');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1839 msg_prt_line(FUNCLINE(fp, j), FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1840 out_flush(); /* show a line at a time */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1841 ui_breakcheck();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1842 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1843 if (!got_int)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1844 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1845 msg_putchar('\n');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1846 msg_puts((char_u *)" endfunction");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1847 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1848 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1849 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1850 emsg_funcname(N_("E123: Undefined function: %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1851 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1852 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1853 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1854
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1855 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1856 * ":function name(arg1, arg2)" Define function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1857 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1858 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1859 if (*p != '(')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1860 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1861 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1862 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1863 EMSG2(_("E124: Missing '(': %s"), eap->arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1864 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1865 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1866 /* attempt to continue by skipping some text */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1867 if (vim_strchr(p, '(') != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1868 p = vim_strchr(p, '(');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1869 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1870 p = skipwhite(p + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1871
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1872 ga_init2(&newlines, (int)sizeof(char_u *), 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1873
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1874 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1875 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1876 /* Check the name of the function. Unless it's a dictionary function
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1877 * (that we are overwriting). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1878 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1879 arg = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1880 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1881 arg = fudi.fd_newkey;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1882 if (arg != NULL && (fudi.fd_di == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1883 || (fudi.fd_di->di_tv.v_type != VAR_FUNC
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1884 && fudi.fd_di->di_tv.v_type != VAR_PARTIAL)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1885 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1886 if (*arg == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1887 j = 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1888 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1889 j = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1890 while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j])
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1891 : eval_isnamec(arg[j])))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1892 ++j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1893 if (arg[j] != NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1894 emsg_funcname((char *)e_invarg2, arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1895 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1896 /* Disallow using the g: dict. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1897 if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1898 EMSG(_("E862: Cannot use g: here"));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1899 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1900
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1901 if (get_function_args(&p, ')', &newargs, &varargs, eap->skip) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1902 goto errret_2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1903
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1904 /* find extra arguments "range", "dict", "abort" and "closure" */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1905 for (;;)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1906 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1907 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1908 if (STRNCMP(p, "range", 5) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1909 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1910 flags |= FC_RANGE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1911 p += 5;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1912 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1913 else if (STRNCMP(p, "dict", 4) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1914 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1915 flags |= FC_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1916 p += 4;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1917 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1918 else if (STRNCMP(p, "abort", 5) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1919 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1920 flags |= FC_ABORT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1921 p += 5;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1922 }
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1923 else if (STRNCMP(p, "closure", 7) == 0)
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1924 {
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1925 flags |= FC_CLOSURE;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1926 p += 7;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1927 if (current_funccal == NULL)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1928 {
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1929 emsg_funcname(N_("E932 Closure function should not be at top level: %s"),
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1930 name == NULL ? (char_u *)"" : name);
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1931 goto erret;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
1932 }
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1933 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1934 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1935 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1936 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1937
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1938 /* When there is a line break use what follows for the function body.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1939 * Makes 'exe "func Test()\n...\nendfunc"' work. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1940 if (*p == '\n')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1941 line_arg = p + 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1942 else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1943 EMSG(_(e_trailing));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1944
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1945 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1946 * Read the body of the function, until ":endfunction" is found.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1947 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1948 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1949 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1950 /* Check if the function already exists, don't let the user type the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1951 * whole function before telling him it doesn't work! For a script we
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1952 * need to skip the body to be able to find what follows. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1953 if (!eap->skip && !eap->forceit)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1954 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1955 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1956 EMSG(_(e_funcdict));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1957 else if (name != NULL && find_func(name) != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1958 emsg_funcname(e_funcexts, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1959 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1960
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1961 if (!eap->skip && did_emsg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1962 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1963
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1964 msg_putchar('\n'); /* don't overwrite the function name */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1965 cmdline_row = msg_row;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1966 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1967
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1968 indent = 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1969 nesting = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1970 for (;;)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1971 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1972 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1973 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1974 msg_scroll = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1975 saved_wait_return = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1976 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1977 need_wait_return = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1978 sourcing_lnum_off = sourcing_lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1979
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1980 if (line_arg != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1981 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1982 /* Use eap->arg, split up in parts by line breaks. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1983 theline = line_arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1984 p = vim_strchr(theline, '\n');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1985 if (p == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1986 line_arg += STRLEN(line_arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1987 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1988 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1989 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1990 line_arg = p + 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1991 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1992 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1993 else if (eap->getline == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1994 theline = getcmdline(':', 0L, indent);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1995 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1996 theline = eap->getline(':', eap->cookie, indent);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1997 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1998 lines_left = Rows - 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1999 if (theline == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2000 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2001 EMSG(_("E126: Missing :endfunction"));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2002 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2003 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2004
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2005 /* Detect line continuation: sourcing_lnum increased more than one. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2006 if (sourcing_lnum > sourcing_lnum_off + 1)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2007 sourcing_lnum_off = sourcing_lnum - sourcing_lnum_off - 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2008 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2009 sourcing_lnum_off = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2010
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2011 if (skip_until != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2012 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2013 /* between ":append" and "." and between ":python <<EOF" and "EOF"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2014 * don't check for ":endfunc". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2015 if (STRCMP(theline, skip_until) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2016 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2017 vim_free(skip_until);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2018 skip_until = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2019 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2020 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2021 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2022 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2023 /* skip ':' and blanks*/
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2024 for (p = theline; vim_iswhite(*p) || *p == ':'; ++p)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2025 ;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2026
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2027 /* Check for "endfunction". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2028 if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2029 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2030 if (line_arg == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2031 vim_free(theline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2032 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2033 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2034
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2035 /* Increase indent inside "if", "while", "for" and "try", decrease
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2036 * at "end". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2037 if (indent > 2 && STRNCMP(p, "end", 3) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2038 indent -= 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2039 else if (STRNCMP(p, "if", 2) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2040 || STRNCMP(p, "wh", 2) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2041 || STRNCMP(p, "for", 3) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2042 || STRNCMP(p, "try", 3) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2043 indent += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2044
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2045 /* Check for defining a function inside this function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2046 if (checkforcmd(&p, "function", 2))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2047 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2048 if (*p == '!')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2049 p = skipwhite(p + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2050 p += eval_fname_script(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2051 vim_free(trans_function_name(&p, TRUE, 0, NULL, NULL));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2052 if (*skipwhite(p) == '(')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2053 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2054 ++nesting;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2055 indent += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2056 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2057 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2058
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2059 /* Check for ":append" or ":insert". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2060 p = skip_range(p, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2061 if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2062 || (p[0] == 'i'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2063 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2064 && (!ASCII_ISALPHA(p[2]) || (p[2] == 's'))))))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2065 skip_until = vim_strsave((char_u *)".");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2066
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2067 /* Check for ":python <<EOF", ":tcl <<EOF", etc. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2068 arg = skipwhite(skiptowhite(p));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2069 if (arg[0] == '<' && arg[1] =='<'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2070 && ((p[0] == 'p' && p[1] == 'y'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2071 && (!ASCII_ISALPHA(p[2]) || p[2] == 't'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2072 || (p[0] == 'p' && p[1] == 'e'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2073 && (!ASCII_ISALPHA(p[2]) || p[2] == 'r'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2074 || (p[0] == 't' && p[1] == 'c'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2075 && (!ASCII_ISALPHA(p[2]) || p[2] == 'l'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2076 || (p[0] == 'l' && p[1] == 'u' && p[2] == 'a'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2077 && !ASCII_ISALPHA(p[3]))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2078 || (p[0] == 'r' && p[1] == 'u' && p[2] == 'b'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2079 && (!ASCII_ISALPHA(p[3]) || p[3] == 'y'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2080 || (p[0] == 'm' && p[1] == 'z'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2081 && (!ASCII_ISALPHA(p[2]) || p[2] == 's'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2082 ))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2083 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2084 /* ":python <<" continues until a dot, like ":append" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2085 p = skipwhite(arg + 2);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2086 if (*p == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2087 skip_until = vim_strsave((char_u *)".");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2088 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2089 skip_until = vim_strsave(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2090 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2091 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2092
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2093 /* Add the line to the function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2094 if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2095 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2096 if (line_arg == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2097 vim_free(theline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2098 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2099 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2100
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2101 /* Copy the line to newly allocated memory. get_one_sourceline()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2102 * allocates 250 bytes per line, this saves 80% on average. The cost
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2103 * is an extra alloc/free. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2104 p = vim_strsave(theline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2105 if (p != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2106 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2107 if (line_arg == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2108 vim_free(theline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2109 theline = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2110 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2111
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2112 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2113
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2114 /* Add NULL lines for continuation lines, so that the line count is
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2115 * equal to the index in the growarray. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2116 while (sourcing_lnum_off-- > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2117 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2118
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2119 /* Check for end of eap->arg. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2120 if (line_arg != NULL && *line_arg == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2121 line_arg = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2122 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2123
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2124 /* Don't define the function when skipping commands or when an error was
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2125 * detected. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2126 if (eap->skip || did_emsg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2127 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2128
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2129 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2130 * If there are no errors, add the function
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2131 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2132 if (fudi.fd_dict == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2133 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2134 v = find_var(name, &ht, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2135 if (v != NULL && v->di_tv.v_type == VAR_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2136 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2137 emsg_funcname(N_("E707: Function name conflicts with variable: %s"),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2138 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2139 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2140 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2141
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2142 fp = find_func(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2143 if (fp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2144 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2145 if (!eap->forceit)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2146 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2147 emsg_funcname(e_funcexts, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2148 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2149 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2150 if (fp->uf_calls > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2151 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2152 emsg_funcname(N_("E127: Cannot redefine function %s: It is in use"),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2153 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2154 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2155 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2156 if (fp->uf_refcount > 1)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2157 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2158 /* This function is referenced somewhere, don't redefine it but
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2159 * create a new one. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2160 --fp->uf_refcount;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2161 fp = NULL;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2162 overwrite = TRUE;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2163 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2164 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2165 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2166 /* redefine existing function */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2167 ga_clear_strings(&(fp->uf_args));
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2168 ga_clear_strings(&(fp->uf_lines));
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2169 vim_free(name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2170 name = NULL;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2171 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2172 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2173 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2174 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2175 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2176 char numbuf[20];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2177
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2178 fp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2179 if (fudi.fd_newkey == NULL && !eap->forceit)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2180 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2181 EMSG(_(e_funcdict));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2182 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2183 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2184 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2185 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2186 /* Can't add a function to a locked dictionary */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2187 if (tv_check_lock(fudi.fd_dict->dv_lock, eap->arg, FALSE))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2188 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2189 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2190 /* Can't change an existing function if it is locked */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2191 else if (tv_check_lock(fudi.fd_di->di_tv.v_lock, eap->arg, FALSE))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2192 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2193
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2194 /* Give the function a sequential number. Can only be used with a
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2195 * Funcref! */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2196 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2197 sprintf(numbuf, "%d", ++func_nr);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2198 name = vim_strsave((char_u *)numbuf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2199 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2200 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2201 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2202
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2203 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2204 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2205 if (fudi.fd_dict == NULL && vim_strchr(name, AUTOLOAD_CHAR) != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2206 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2207 int slen, plen;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2208 char_u *scriptname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2209
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2210 /* Check that the autoload name matches the script name. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2211 j = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2212 if (sourcing_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2213 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2214 scriptname = autoload_name(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2215 if (scriptname != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2216 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2217 p = vim_strchr(scriptname, '/');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2218 plen = (int)STRLEN(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2219 slen = (int)STRLEN(sourcing_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2220 if (slen > plen && fnamecmp(p,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2221 sourcing_name + slen - plen) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2222 j = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2223 vim_free(scriptname);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2224 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2225 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2226 if (j == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2227 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2228 EMSG2(_("E746: Function name does not match script file name: %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2229 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2230 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2231 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2232
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2233 fp = (ufunc_T *)alloc_clear((unsigned)(sizeof(ufunc_T) + STRLEN(name)));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2234 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2235 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2236
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2237 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2238 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2239 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2240 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2241 /* add new dict entry */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2242 fudi.fd_di = dictitem_alloc(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2243 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2244 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2245 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2246 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2247 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2248 if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2249 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2250 vim_free(fudi.fd_di);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2251 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2252 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2253 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2254 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2255 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2256 /* overwrite existing dict entry */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2257 clear_tv(&fudi.fd_di->di_tv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2258 fudi.fd_di->di_tv.v_type = VAR_FUNC;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2259 fudi.fd_di->di_tv.v_lock = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2260 fudi.fd_di->di_tv.vval.v_string = vim_strsave(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2261
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2262 /* behave like "dict" was used */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2263 flags |= FC_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2264 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2265
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2266 /* insert the new function in the function list */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2267 STRCPY(fp->uf_name, name);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2268 if (overwrite)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2269 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2270 hi = hash_find(&func_hashtab, name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2271 hi->hi_key = UF2HIKEY(fp);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2272 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2273 else if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2274 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2275 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2276 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2277 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2278 fp->uf_refcount = 1;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2279 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2280 fp->uf_args = newargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2281 fp->uf_lines = newlines;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2282 if ((flags & FC_CLOSURE) != 0)
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2283 {
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2284 if (register_closure(fp) == FAIL)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2285 goto erret;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2286 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2287 else
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2288 fp->uf_scoped = NULL;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2289
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2290 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2291 fp->uf_tml_count = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2292 fp->uf_tml_total = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2293 fp->uf_tml_self = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2294 fp->uf_profiling = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2295 if (prof_def_func())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2296 func_do_profile(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2297 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2298 fp->uf_varargs = varargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2299 fp->uf_flags = flags;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2300 fp->uf_calls = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2301 fp->uf_script_ID = current_SID;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2302 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2303
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2304 erret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2305 ga_clear_strings(&newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2306 errret_2:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2307 ga_clear_strings(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2308 ret_free:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2309 vim_free(skip_until);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2310 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2311 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2312 did_emsg |= saved_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2313 need_wait_return |= saved_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2314 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2315
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2316 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2317 * Return 5 if "p" starts with "<SID>" or "<SNR>" (ignoring case).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2318 * Return 2 if "p" starts with "s:".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2319 * Return 0 otherwise.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2320 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2321 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2322 eval_fname_script(char_u *p)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2323 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2324 /* Use MB_STRICMP() because in Turkish comparing the "I" may not work with
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2325 * the standard library function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2326 if (p[0] == '<' && (MB_STRNICMP(p + 1, "SID>", 4) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2327 || MB_STRNICMP(p + 1, "SNR>", 4) == 0))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2328 return 5;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2329 if (p[0] == 's' && p[1] == ':')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2330 return 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2331 return 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2332 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2333
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2334 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2335 translated_function_exists(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2336 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2337 if (builtin_function(name, -1))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2338 return find_internal_func(name) >= 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2339 return find_func(name) != NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2340 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2341
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2342 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2343 * Return TRUE if a function "name" exists.
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2344 * If "no_defef" is TRUE, do not dereference a Funcref.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2345 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2346 int
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2347 function_exists(char_u *name, int no_deref)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2348 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2349 char_u *nm = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2350 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2351 int n = FALSE;
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2352 int flag;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2353
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2354 flag = TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2355 if (no_deref)
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2356 flag |= TFN_NO_DEREF;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2357 p = trans_function_name(&nm, FALSE, flag, NULL, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2358 nm = skipwhite(nm);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2359
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2360 /* Only accept "funcname", "funcname ", "funcname (..." and
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2361 * "funcname(...", not "funcname!...". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2362 if (p != NULL && (*nm == NUL || *nm == '('))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2363 n = translated_function_exists(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2364 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2365 return n;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2366 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2367
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2368 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2369 get_expanded_name(char_u *name, int check)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2370 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2371 char_u *nm = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2372 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2373
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2374 p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET, NULL, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2375
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2376 if (p != NULL && *nm == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2377 if (!check || translated_function_exists(p))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2378 return p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2379
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2380 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2381 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2382 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2383
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2384 #if defined(FEAT_PROFILE) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2385 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2386 * Start profiling function "fp".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2387 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2388 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2389 func_do_profile(ufunc_T *fp)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2390 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2391 int len = fp->uf_lines.ga_len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2392
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2393 if (len == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2394 len = 1; /* avoid getting error for allocating zero bytes */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2395 fp->uf_tm_count = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2396 profile_zero(&fp->uf_tm_self);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2397 profile_zero(&fp->uf_tm_total);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2398 if (fp->uf_tml_count == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2399 fp->uf_tml_count = (int *)alloc_clear((unsigned) (sizeof(int) * len));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2400 if (fp->uf_tml_total == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2401 fp->uf_tml_total = (proftime_T *)alloc_clear((unsigned)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2402 (sizeof(proftime_T) * len));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2403 if (fp->uf_tml_self == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2404 fp->uf_tml_self = (proftime_T *)alloc_clear((unsigned)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2405 (sizeof(proftime_T) * len));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2406 fp->uf_tml_idx = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2407 if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2408 || fp->uf_tml_self == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409 return; /* out of memory */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411 fp->uf_profiling = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2412 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2413
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2414 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2415 * Dump the profiling results for all functions in file "fd".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2416 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2417 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2418 func_dump_profile(FILE *fd)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2419 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2420 hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2421 int todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2422 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2423 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2424 ufunc_T **sorttab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2425 int st_len = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2426
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2427 todo = (int)func_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2428 if (todo == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2429 return; /* nothing to dump */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2430
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2431 sorttab = (ufunc_T **)alloc((unsigned)(sizeof(ufunc_T *) * todo));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2432
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2433 for (hi = func_hashtab.ht_array; todo > 0; ++hi)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2434 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2435 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2436 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2437 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2438 fp = HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2439 if (fp->uf_profiling)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2440 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2441 if (sorttab != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2442 sorttab[st_len++] = fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2443
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2444 if (fp->uf_name[0] == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2445 fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2446 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2447 fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2448 if (fp->uf_tm_count == 1)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2449 fprintf(fd, "Called 1 time\n");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2451 fprintf(fd, "Called %d times\n", fp->uf_tm_count);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452 fprintf(fd, "Total time: %s\n", profile_msg(&fp->uf_tm_total));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2453 fprintf(fd, " Self time: %s\n", profile_msg(&fp->uf_tm_self));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2454 fprintf(fd, "\n");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2455 fprintf(fd, "count total (s) self (s)\n");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2456
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2457 for (i = 0; i < fp->uf_lines.ga_len; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2458 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2459 if (FUNCLINE(fp, i) == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2460 continue;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2461 prof_func_line(fd, fp->uf_tml_count[i],
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2462 &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2463 fprintf(fd, "%s\n", FUNCLINE(fp, i));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2464 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2465 fprintf(fd, "\n");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2466 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2467 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2468 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2469
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2470 if (sorttab != NULL && st_len > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2471 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2472 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2473 prof_total_cmp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2474 prof_sort_list(fd, sorttab, st_len, "TOTAL", FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2475 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2476 prof_self_cmp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2477 prof_sort_list(fd, sorttab, st_len, "SELF", TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2478 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2479
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2480 vim_free(sorttab);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2481 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2482
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2483 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2484 prof_sort_list(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2485 FILE *fd,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2486 ufunc_T **sorttab,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2487 int st_len,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2488 char *title,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2489 int prefer_self) /* when equal print only self time */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2490 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2491 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2492 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2493
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2494 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2495 fprintf(fd, "count total (s) self (s) function\n");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2496 for (i = 0; i < 20 && i < st_len; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2497 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2498 fp = sorttab[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2499 prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2500 prefer_self);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2501 if (fp->uf_name[0] == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2502 fprintf(fd, " <SNR>%s()\n", fp->uf_name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2503 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2504 fprintf(fd, " %s()\n", fp->uf_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2505 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2506 fprintf(fd, "\n");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2507 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2508
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2509 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2510 * Print the count and times for one function or function line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2511 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2512 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2513 prof_func_line(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2514 FILE *fd,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2515 int count,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2516 proftime_T *total,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2517 proftime_T *self,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2518 int prefer_self) /* when equal print only self time */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2519 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2520 if (count > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2521 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2522 fprintf(fd, "%5d ", count);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2523 if (prefer_self && profile_equal(total, self))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2524 fprintf(fd, " ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2525 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2526 fprintf(fd, "%s ", profile_msg(total));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2527 if (!prefer_self && profile_equal(total, self))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2528 fprintf(fd, " ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2529 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2530 fprintf(fd, "%s ", profile_msg(self));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2531 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2532 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2533 fprintf(fd, " ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2534 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2535
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2536 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2537 * Compare function for total time sorting.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2538 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2539 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2540 #ifdef __BORLANDC__
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2541 _RTLENTRYF
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2542 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2543 prof_total_cmp(const void *s1, const void *s2)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2544 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2545 ufunc_T *p1, *p2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2546
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2547 p1 = *(ufunc_T **)s1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2548 p2 = *(ufunc_T **)s2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2549 return profile_cmp(&p1->uf_tm_total, &p2->uf_tm_total);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2550 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2551
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2552 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2553 * Compare function for self time sorting.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2554 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2555 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2556 #ifdef __BORLANDC__
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2557 _RTLENTRYF
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2558 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2559 prof_self_cmp(const void *s1, const void *s2)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2560 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2561 ufunc_T *p1, *p2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2563 p1 = *(ufunc_T **)s1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2564 p2 = *(ufunc_T **)s2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2565 return profile_cmp(&p1->uf_tm_self, &p2->uf_tm_self);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2566 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2567
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2568 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2569 * Prepare profiling for entering a child or something else that is not
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2570 * counted for the script/function itself.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2571 * Should always be called in pair with prof_child_exit().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2572 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2573 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2574 prof_child_enter(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2575 proftime_T *tm) /* place to store waittime */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2576 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2577 funccall_T *fc = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2578
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2579 if (fc != NULL && fc->func->uf_profiling)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2580 profile_start(&fc->prof_child);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2581 script_prof_save(tm);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2582 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2583
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2584 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2585 * Take care of time spent in a child.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2586 * Should always be called after prof_child_enter().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2587 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2588 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2589 prof_child_exit(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2590 proftime_T *tm) /* where waittime was stored */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2591 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2592 funccall_T *fc = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2593
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2594 if (fc != NULL && fc->func->uf_profiling)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2595 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2596 profile_end(&fc->prof_child);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2597 profile_sub_wait(tm, &fc->prof_child); /* don't count waiting time */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2598 profile_add(&fc->func->uf_tm_children, &fc->prof_child);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2599 profile_add(&fc->func->uf_tml_children, &fc->prof_child);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2600 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2601 script_prof_restore(tm);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2602 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2603
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2604 #endif /* FEAT_PROFILE */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2605
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2606 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2607
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2608 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2609 * Function given to ExpandGeneric() to obtain the list of user defined
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2610 * function names.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2611 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2612 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2613 get_user_func_name(expand_T *xp, int idx)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2614 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2615 static long_u done;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2616 static hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2617 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2618
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2619 if (idx == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2620 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2621 done = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2622 hi = func_hashtab.ht_array;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2623 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2624 if (done < func_hashtab.ht_used)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2625 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2626 if (done++ > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2627 ++hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2628 while (HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2629 ++hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2630 fp = HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2631
9638
af0d98d8836e commit https://github.com/vim/vim/commit/b49edc11a1872fa99befa9a4a8ea6c8537868038
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
2632 if ((fp->uf_flags & FC_DICT)
af0d98d8836e commit https://github.com/vim/vim/commit/b49edc11a1872fa99befa9a4a8ea6c8537868038
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
2633 || STRNCMP(fp->uf_name, "<lambda>", 8) == 0)
af0d98d8836e commit https://github.com/vim/vim/commit/b49edc11a1872fa99befa9a4a8ea6c8537868038
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
2634 return (char_u *)""; /* don't show dict and lambda functions */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2635
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2636 if (STRLEN(fp->uf_name) + 4 >= IOSIZE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2637 return fp->uf_name; /* prevents overflow */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2638
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2639 cat_func_name(IObuff, fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2640 if (xp->xp_context != EXPAND_USER_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2641 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2642 STRCAT(IObuff, "(");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2643 if (!fp->uf_varargs && fp->uf_args.ga_len == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2644 STRCAT(IObuff, ")");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2645 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2646 return IObuff;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2647 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2648 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2649 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2650
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2651 #endif /* FEAT_CMDL_COMPL */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2652
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2653 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2654 * ":delfunction {name}"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2655 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2656 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2657 ex_delfunction(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2658 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2659 ufunc_T *fp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2660 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2661 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2662 funcdict_T fudi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2663
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2664 p = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2665 name = trans_function_name(&p, eap->skip, 0, &fudi, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2666 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2667 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2668 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2669 if (fudi.fd_dict != NULL && !eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2670 EMSG(_(e_funcref));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2671 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2672 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2673 if (!ends_excmd(*skipwhite(p)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2674 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2675 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2676 EMSG(_(e_trailing));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2677 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2678 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2679 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2680 if (eap->nextcmd != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2681 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2682
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2683 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2684 fp = find_func(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2685 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2686
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2687 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2688 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2689 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2690 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2691 EMSG2(_(e_nofunc), eap->arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2692 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2693 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2694 if (fp->uf_calls > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2695 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2696 EMSG2(_("E131: Cannot delete function %s: It is in use"), eap->arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2697 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2698 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2699
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2700 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2701 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2702 /* Delete the dict item that refers to the function, it will
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2703 * invoke func_unref() and possibly delete the function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2704 dictitem_remove(fudi.fd_dict, fudi.fd_di);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2705 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2706 else
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2707 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2708 /* Normal functions (not numbered functions and lambdas) have a
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2709 * refcount of 1 for the entry in the hashtable. When deleting
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2710 * them and the refcount is more than one, it should be kept.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2711 * Numbered functions and lambdas snould be kept if the refcount is
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2712 * one or more. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2713 if (fp->uf_refcount > (isdigit(fp->uf_name[0])
9727
8436bb5134f5 commit https://github.com/vim/vim/commit/0588d4f9d2741f35a271400a37fddbdd72d84219
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
2714 || fp->uf_name[0] == '<' ? 0 : 1))
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2715 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2716 /* Function is still referenced somewhere. Don't free it but
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2717 * do remove it from the hashtable. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2718 func_remove(fp);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2719 fp->uf_flags |= FC_DELETED;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2720 fp->uf_refcount--;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2721 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2722 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2723 func_free(fp);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2724 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2725 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2726 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2727
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2728 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2729 * Unreference a Function: decrement the reference count and free it when it
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2730 * becomes zero.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2731 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2732 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2733 func_unref(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2734 {
9655
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2735 ufunc_T *fp = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2736
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2737 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2738 return;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2739 fp = find_func(name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2740 if (fp == NULL && isdigit(*name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2741 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2742 #ifdef EXITFREE
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2743 if (!entered_free_all_mem)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2744 #endif
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2745 EMSG2(_(e_intern2), "func_unref()");
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2746 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2747 if (fp != NULL && --fp->uf_refcount <= 0)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2748 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2749 /* Only delete it when it's not being used. Otherwise it's done
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2750 * when "uf_calls" becomes zero. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2751 if (fp->uf_calls == 0)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2752 func_free(fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2753 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2754 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2755
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2756 /*
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2757 * Unreference a Function: decrement the reference count and free it when it
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2758 * becomes zero.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2759 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2760 void
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2761 func_ptr_unref(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2762 {
9655
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2763 if (fp != NULL && --fp->uf_refcount <= 0)
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2764 {
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2765 /* Only delete it when it's not being used. Otherwise it's done
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2766 * when "uf_calls" becomes zero. */
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2767 if (fp->uf_calls == 0)
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2768 func_free(fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2769 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2770 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2771
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2772 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2773 * Count a reference to a Function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2774 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2775 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2776 func_ref(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2777 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2778 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2779
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2780 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2781 return;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2782 fp = find_func(name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2783 if (fp != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2784 ++fp->uf_refcount;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2785 else if (isdigit(*name))
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2786 /* Only give an error for a numbered function.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2787 * Fail silently, when named or lambda function isn't found. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2788 EMSG2(_(e_intern2), "func_ref()");
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2789 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2790
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2791 /*
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2792 * Count a reference to a Function.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2793 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2794 void
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2795 func_ptr_ref(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2796 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2797 if (fp != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2798 ++fp->uf_refcount;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2799 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2800
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2801 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2802 * Return TRUE if items in "fc" do not have "copyID". That means they are not
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2803 * referenced from anywhere that is in use.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2804 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2805 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2806 can_free_funccal(funccall_T *fc, int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2807 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2808 return (fc->l_varlist.lv_copyID != copyID
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2809 && fc->l_vars.dv_copyID != copyID
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
2810 && fc->l_avars.dv_copyID != copyID
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
2811 && fc->fc_copyID != copyID);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2812 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2813
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2814 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2815 * ":return [expr]"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2816 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2817 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2818 ex_return(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2819 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2820 char_u *arg = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2821 typval_T rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2822 int returning = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2823
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2824 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2825 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2826 EMSG(_("E133: :return not inside a function"));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2827 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2828 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2829
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2830 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2831 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2832
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2833 eap->nextcmd = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2834 if ((*arg != NUL && *arg != '|' && *arg != '\n')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2835 && eval0(arg, &rettv, &eap->nextcmd, !eap->skip) != FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2836 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2837 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2838 returning = do_return(eap, FALSE, TRUE, &rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2839 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2840 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2841 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2842 /* It's safer to return also on error. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2843 else if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2844 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2845 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2846 * Return unless the expression evaluation has been cancelled due to an
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2847 * aborting error, an interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2848 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2849 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2850 returning = do_return(eap, FALSE, TRUE, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2851 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2852
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2853 /* When skipping or the return gets pending, advance to the next command
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2854 * in this line (!returning). Otherwise, ignore the rest of the line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2855 * Following lines will be ignored by get_func_line(). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2856 if (returning)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2857 eap->nextcmd = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2858 else if (eap->nextcmd == NULL) /* no argument */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2859 eap->nextcmd = check_nextcmd(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2860
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2861 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2862 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2863 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2864
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2865 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2866 * ":1,25call func(arg1, arg2)" function call.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2867 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2868 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2869 ex_call(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2870 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2871 char_u *arg = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2872 char_u *startarg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2873 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2874 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2875 int len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2876 typval_T rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2877 linenr_T lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2878 int doesrange;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2879 int failed = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2880 funcdict_T fudi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2881 partial_T *partial = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2882
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2883 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2884 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2885 /* trans_function_name() doesn't work well when skipping, use eval0()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2886 * instead to skip to any following command, e.g. for:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2887 * :if 0 | call dict.foo().bar() | endif */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2888 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2889 if (eval0(eap->arg, &rettv, &eap->nextcmd, FALSE) != FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2890 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2891 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2892 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2893 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2894
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2895 tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi, &partial);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2896 if (fudi.fd_newkey != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2897 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2898 /* Still need to give an error message for missing key. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2899 EMSG2(_(e_dictkey), fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2900 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2901 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2902 if (tofree == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2903 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2904
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2905 /* Increase refcount on dictionary, it could get deleted when evaluating
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2906 * the arguments. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2907 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2908 ++fudi.fd_dict->dv_refcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2909
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2910 /* If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2911 * contents. For VAR_PARTIAL get its partial, unless we already have one
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2912 * from trans_function_name(). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2913 len = (int)STRLEN(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2914 name = deref_func_name(tofree, &len,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2915 partial != NULL ? NULL : &partial, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2916
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2917 /* Skip white space to allow ":call func ()". Not good, but required for
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2918 * backward compatibility. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2919 startarg = skipwhite(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2920 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2921
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2922 if (*startarg != '(')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2923 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2924 EMSG2(_("E107: Missing parentheses: %s"), eap->arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2925 goto end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2926 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2927
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2928 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2929 * When skipping, evaluate the function once, to find the end of the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2930 * arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2931 * When the function takes a range, this is discovered after the first
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2932 * call, and the loop is broken.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2933 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2934 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2935 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2936 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2937 lnum = eap->line2; /* do it once, also with an invalid range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2938 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2939 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2940 lnum = eap->line1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2941 for ( ; lnum <= eap->line2; ++lnum)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2942 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2943 if (!eap->skip && eap->addr_count > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2944 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2945 curwin->w_cursor.lnum = lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2946 curwin->w_cursor.col = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2947 #ifdef FEAT_VIRTUALEDIT
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2948 curwin->w_cursor.coladd = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2949 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2950 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2951 arg = startarg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2952 if (get_func_tv(name, (int)STRLEN(name), &rettv, &arg,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2953 eap->line1, eap->line2, &doesrange,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2954 !eap->skip, partial, fudi.fd_dict) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2955 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2956 failed = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2957 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2958 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2959
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2960 /* Handle a function returning a Funcref, Dictionary or List. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2961 if (handle_subscript(&arg, &rettv, !eap->skip, TRUE) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2962 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2963 failed = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2964 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2965 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2966
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2967 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2968 if (doesrange || eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2969 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2970
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2971 /* Stop when immediately aborting on error, or when an interrupt
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2972 * occurred or an exception was thrown but not caught.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2973 * get_func_tv() returned OK, so that the check for trailing
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2974 * characters below is executed. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2975 if (aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2976 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2977 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2978 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2979 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2980
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2981 if (!failed)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2982 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2983 /* Check for trailing illegal characters and a following command. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2984 if (!ends_excmd(*arg))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2985 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2986 emsg_severe = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2987 EMSG(_(e_trailing));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2988 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2989 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2990 eap->nextcmd = check_nextcmd(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2991 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2992
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2993 end:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2994 dict_unref(fudi.fd_dict);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2995 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2996 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2997
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2998 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2999 * Return from a function. Possibly makes the return pending. Also called
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3000 * for a pending return at the ":endtry" or after returning from an extra
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3001 * do_cmdline(). "reanimate" is used in the latter case. "is_cmd" is set
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3002 * when called due to a ":return" command. "rettv" may point to a typval_T
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3003 * with the return rettv. Returns TRUE when the return can be carried out,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3004 * FALSE when the return gets pending.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3005 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3006 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3007 do_return(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3008 exarg_T *eap,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3009 int reanimate,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3010 int is_cmd,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3011 void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3012 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3013 int idx;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3014 struct condstack *cstack = eap->cstack;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3015
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3016 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3017 /* Undo the return. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3018 current_funccal->returned = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3019
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3020 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3021 * Cleanup (and inactivate) conditionals, but stop when a try conditional
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3022 * not in its finally clause (which then is to be executed next) is found.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3023 * In this case, make the ":return" pending for execution at the ":endtry".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3024 * Otherwise, return normally.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3025 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3026 idx = cleanup_conditionals(eap->cstack, 0, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3027 if (idx >= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3028 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3029 cstack->cs_pending[idx] = CSTP_RETURN;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3030
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3031 if (!is_cmd && !reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3032 /* A pending return again gets pending. "rettv" points to an
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3033 * allocated variable with the rettv of the original ":return"'s
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3034 * argument if present or is NULL else. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3035 cstack->cs_rettv[idx] = rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3036 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3037 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3038 /* When undoing a return in order to make it pending, get the stored
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3039 * return rettv. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3040 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3041 rettv = current_funccal->rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3042
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3043 if (rettv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3044 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3045 /* Store the value of the pending return. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3046 if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3047 *(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3048 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3049 EMSG(_(e_outofmem));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3050 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3051 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3052 cstack->cs_rettv[idx] = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3053
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3054 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3055 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3056 /* The pending return value could be overwritten by a ":return"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3057 * without argument in a finally clause; reset the default
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3058 * return value. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3059 current_funccal->rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3060 current_funccal->rettv->vval.v_number = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3061 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3062 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3063 report_make_pending(CSTP_RETURN, rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3064 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3065 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3066 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3067 current_funccal->returned = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3068
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3069 /* If the return is carried out now, store the return value. For
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3070 * a return immediately after reanimation, the value is already
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3071 * there. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3072 if (!reanimate && rettv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3073 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3074 clear_tv(current_funccal->rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3075 *current_funccal->rettv = *(typval_T *)rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3076 if (!is_cmd)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3077 vim_free(rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3078 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3079 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3080
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3081 return idx < 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3082 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3083
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3084 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3085 * Free the variable with a pending return value.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3086 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3087 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3088 discard_pending_return(void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3089 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3090 free_tv((typval_T *)rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3091 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3092
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3093 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3094 * Generate a return command for producing the value of "rettv". The result
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3095 * is an allocated string. Used by report_pending() for verbose messages.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3096 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3097 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3098 get_return_cmd(void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3099 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3100 char_u *s = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3101 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3102 char_u numbuf[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3103
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3104 if (rettv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3105 s = echo_string((typval_T *)rettv, &tofree, numbuf, 0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3106 if (s == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3107 s = (char_u *)"";
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3108
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3109 STRCPY(IObuff, ":return ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3110 STRNCPY(IObuff + 8, s, IOSIZE - 8);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3111 if (STRLEN(s) + 8 >= IOSIZE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3112 STRCPY(IObuff + IOSIZE - 4, "...");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3113 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3114 return vim_strsave(IObuff);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3115 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3116
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3117 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3118 * Get next function line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3119 * Called by do_cmdline() to get the next line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3120 * Returns allocated string, or NULL for end of function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3121 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3122 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3123 get_func_line(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3124 int c UNUSED,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3125 void *cookie,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3126 int indent UNUSED)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3127 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3128 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3129 ufunc_T *fp = fcp->func;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3130 char_u *retval;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3131 garray_T *gap; /* growarray with function lines */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3132
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3133 /* If breakpoints have been added/deleted need to check for it. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3134 if (fcp->dbg_tick != debug_tick)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3135 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3136 fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3137 sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3138 fcp->dbg_tick = debug_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3139 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3140 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3141 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3142 func_line_end(cookie);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3143 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3144
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3145 gap = &fp->uf_lines;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3146 if (((fp->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3147 || fcp->returned)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3148 retval = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3149 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3150 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3151 /* Skip NULL lines (continuation lines). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3152 while (fcp->linenr < gap->ga_len
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3153 && ((char_u **)(gap->ga_data))[fcp->linenr] == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3154 ++fcp->linenr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3155 if (fcp->linenr >= gap->ga_len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3156 retval = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3157 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3158 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3159 retval = vim_strsave(((char_u **)(gap->ga_data))[fcp->linenr++]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3160 sourcing_lnum = fcp->linenr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3161 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3162 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3163 func_line_start(cookie);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3164 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3165 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3166 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3167
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3168 /* Did we encounter a breakpoint? */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3169 if (fcp->breakpoint != 0 && fcp->breakpoint <= sourcing_lnum)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3170 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3171 dbg_breakpoint(fp->uf_name, sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3172 /* Find next breakpoint. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3173 fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3174 sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3175 fcp->dbg_tick = debug_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3176 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3177
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3178 return retval;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3179 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3180
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3181 #if defined(FEAT_PROFILE) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3182 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3183 * Called when starting to read a function line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3184 * "sourcing_lnum" must be correct!
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3185 * When skipping lines it may not actually be executed, but we won't find out
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3186 * until later and we need to store the time now.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3187 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3188 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3189 func_line_start(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3190 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3191 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3192 ufunc_T *fp = fcp->func;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3193
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3194 if (fp->uf_profiling && sourcing_lnum >= 1
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3195 && sourcing_lnum <= fp->uf_lines.ga_len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3196 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3197 fp->uf_tml_idx = sourcing_lnum - 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3198 /* Skip continuation lines. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3199 while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3200 --fp->uf_tml_idx;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3201 fp->uf_tml_execed = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3202 profile_start(&fp->uf_tml_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3203 profile_zero(&fp->uf_tml_children);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3204 profile_get_wait(&fp->uf_tml_wait);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3205 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3206 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3207
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3208 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3209 * Called when actually executing a function line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3210 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3211 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3212 func_line_exec(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3213 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3214 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3215 ufunc_T *fp = fcp->func;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3216
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3217 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3218 fp->uf_tml_execed = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3219 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3220
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3221 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3222 * Called when done with a function line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3223 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3224 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3225 func_line_end(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3226 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3227 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3228 ufunc_T *fp = fcp->func;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3229
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3230 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3231 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3232 if (fp->uf_tml_execed)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3233 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3234 ++fp->uf_tml_count[fp->uf_tml_idx];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3235 profile_end(&fp->uf_tml_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3236 profile_sub_wait(&fp->uf_tml_wait, &fp->uf_tml_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3237 profile_add(&fp->uf_tml_total[fp->uf_tml_idx], &fp->uf_tml_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3238 profile_self(&fp->uf_tml_self[fp->uf_tml_idx], &fp->uf_tml_start,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3239 &fp->uf_tml_children);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3240 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3241 fp->uf_tml_idx = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3242 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3243 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3244 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3245
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3246 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3247 * Return TRUE if the currently active function should be ended, because a
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3248 * return was encountered or an error occurred. Used inside a ":while".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3249 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3250 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3251 func_has_ended(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3252 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3253 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3254
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3255 /* Ignore the "abort" flag if the abortion behavior has been changed due to
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3256 * an error inside a try conditional. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3257 return (((fcp->func->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3258 || fcp->returned);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3259 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3260
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3261 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3262 * return TRUE if cookie indicates a function which "abort"s on errors.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3263 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3264 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3265 func_has_abort(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3266 void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3267 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3268 return ((funccall_T *)cookie)->func->uf_flags & FC_ABORT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3269 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3270
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3271
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3272 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3273 * Turn "dict.Func" into a partial for "Func" bound to "dict".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3274 * Don't do this when "Func" is already a partial that was bound
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3275 * explicitly (pt_auto is FALSE).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3276 * Changes "rettv" in-place.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3277 * Returns the updated "selfdict_in".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3278 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3279 dict_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3280 make_partial(dict_T *selfdict_in, typval_T *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3281 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3282 char_u *fname;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3283 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3284 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3285 char_u fname_buf[FLEN_FIXED + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3286 int error;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3287 dict_T *selfdict = selfdict_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3288
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3289 if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial->pt_func != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3290 fp = rettv->vval.v_partial->pt_func;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3291 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3292 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3293 fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3294 : rettv->vval.v_partial->pt_name;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3295 /* Translate "s:func" to the stored function name. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3296 fname = fname_trans_sid(fname, fname_buf, &tofree, &error);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3297 fp = find_func(fname);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3298 vim_free(tofree);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3299 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3300
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3301 if (fp != NULL && (fp->uf_flags & FC_DICT))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3302 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3303 partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3304
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3305 if (pt != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3306 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3307 pt->pt_refcount = 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3308 pt->pt_dict = selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3309 pt->pt_auto = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3310 selfdict = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3311 if (rettv->v_type == VAR_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3312 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3313 /* Just a function: Take over the function name and use
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3314 * selfdict. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3315 pt->pt_name = rettv->vval.v_string;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3316 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3317 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3318 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3319 partial_T *ret_pt = rettv->vval.v_partial;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3320 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3321
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3322 /* Partial: copy the function name, use selfdict and copy
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3323 * args. Can't take over name or args, the partial might
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3324 * be referenced elsewhere. */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3325 if (ret_pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3326 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3327 pt->pt_name = vim_strsave(ret_pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3328 func_ref(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3329 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3330 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3331 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3332 pt->pt_func = ret_pt->pt_func;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3333 func_ptr_ref(pt->pt_func);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3334 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3335 if (ret_pt->pt_argc > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3336 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3337 pt->pt_argv = (typval_T *)alloc(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3338 sizeof(typval_T) * ret_pt->pt_argc);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3339 if (pt->pt_argv == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3340 /* out of memory: drop the arguments */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3341 pt->pt_argc = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3342 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3343 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3344 pt->pt_argc = ret_pt->pt_argc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3345 for (i = 0; i < pt->pt_argc; i++)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3346 copy_tv(&ret_pt->pt_argv[i], &pt->pt_argv[i]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3347 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3348 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3349 partial_unref(ret_pt);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3350 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3351 rettv->v_type = VAR_PARTIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3352 rettv->vval.v_partial = pt;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3353 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3354 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3355 return selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3356 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3357
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3358 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3359 * Return the name of the executed function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3360 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3361 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3362 func_name(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3363 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3364 return ((funccall_T *)cookie)->func->uf_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3365 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3366
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3367 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3368 * Return the address holding the next breakpoint line for a funccall cookie.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3369 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3370 linenr_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3371 func_breakpoint(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3372 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3373 return &((funccall_T *)cookie)->breakpoint;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3374 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3375
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3376 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3377 * Return the address holding the debug tick for a funccall cookie.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3378 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3379 int *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3380 func_dbg_tick(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3381 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3382 return &((funccall_T *)cookie)->dbg_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3383 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3384
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3385 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3386 * Return the nesting level for a funccall cookie.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3387 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3388 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3389 func_level(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3390 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3391 return ((funccall_T *)cookie)->level;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3392 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3393
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3394 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3395 * Return TRUE when a function was ended by a ":return" command.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3396 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3397 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3398 current_func_returned(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3399 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3400 return current_funccal->returned;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3401 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3402
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3403 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3404 * Save the current function call pointer, and set it to NULL.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3405 * Used when executing autocommands and for ":source".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3406 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3407 void *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3408 save_funccal(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3409 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3410 funccall_T *fc = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3411
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3412 current_funccal = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3413 return (void *)fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3414 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3415
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3416 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3417 restore_funccal(void *vfc)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3418 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3419 funccall_T *fc = (funccall_T *)vfc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3420
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3421 current_funccal = fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3422 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3423
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3424 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3425 free_unref_funccal(int copyID, int testing)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3426 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3427 int did_free = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3428 int did_free_funccal = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3429 funccall_T *fc, **pfc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3430
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3431 for (pfc = &previous_funccal; *pfc != NULL; )
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3432 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3433 if (can_free_funccal(*pfc, copyID))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3434 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3435 fc = *pfc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3436 *pfc = fc->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3437 free_funccal(fc, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3438 did_free = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3439 did_free_funccal = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3440 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3441 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3442 pfc = &(*pfc)->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3443 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3444 if (did_free_funccal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3445 /* When a funccal was freed some more items might be garbage
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3446 * collected, so run again. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3447 (void)garbage_collect(testing);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3448
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3449 return did_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3450 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3451
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3452 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3453 * Get function call environment based on bactrace debug level
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3454 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3455 static funccall_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3456 get_funccal(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3457 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3458 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3459 funccall_T *funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3460 funccall_T *temp_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3461
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3462 funccal = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3463 if (debug_backtrace_level > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3464 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3465 for (i = 0; i < debug_backtrace_level; i++)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3466 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3467 temp_funccal = funccal->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3468 if (temp_funccal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3469 funccal = temp_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3470 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3471 /* backtrace level overflow. reset to max */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3472 debug_backtrace_level = i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3473 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3474 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3475 return funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3476 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3477
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3478 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3479 * Return the hashtable used for local variables in the current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3480 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3481 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3482 hashtab_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3483 get_funccal_local_ht()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3484 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3485 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3486 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3487 return &get_funccal()->l_vars.dv_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3488 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3489
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3490 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3491 * Return the l: scope variable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3492 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3493 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3494 dictitem_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3495 get_funccal_local_var()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3496 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3497 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3498 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3499 return &get_funccal()->l_vars_var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3500 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3501
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3502 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3503 * Return the hashtable used for argument in the current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3504 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3505 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3506 hashtab_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3507 get_funccal_args_ht()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3508 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3509 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3510 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3511 return &get_funccal()->l_avars.dv_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3512 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3513
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3514 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3515 * Return the a: scope variable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3516 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3517 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3518 dictitem_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3519 get_funccal_args_var()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3520 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3521 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3522 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3523 return &current_funccal->l_avars_var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3524 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3525
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3526 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3527 * Clear the current_funccal and return the old value.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3528 * Caller is expected to invoke restore_current_funccal().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3529 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3530 void *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3531 clear_current_funccal()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3532 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3533 funccall_T *f = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3534
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3535 current_funccal = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3536 return f;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3537 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3538
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3539 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3540 restore_current_funccal(void *f)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3541 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3542 current_funccal = f;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3543 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3544
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3545 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3546 * List function variables, if there is a function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3547 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3548 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3549 list_func_vars(int *first)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3550 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3551 if (current_funccal != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3552 list_hashtable_vars(&current_funccal->l_vars.dv_hashtab,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3553 (char_u *)"l:", FALSE, first);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3554 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3555
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3556 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3557 * If "ht" is the hashtable for local variables in the current funccal, return
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3558 * the dict that contains it.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3559 * Otherwise return NULL.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3560 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3561 dict_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3562 get_current_funccal_dict(hashtab_T *ht)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3563 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3564 if (current_funccal != NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3565 && ht == &current_funccal->l_vars.dv_hashtab)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3566 return &current_funccal->l_vars;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3567 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3568 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3569
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3570 /*
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3571 * Search hashitem in parent scope.
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3572 */
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3573 hashitem_T *
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3574 find_hi_in_scoped_ht(char_u *name, hashtab_T **pht)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3575 {
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3576 funccall_T *old_current_funccal = current_funccal;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3577 hashtab_T *ht;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3578 hashitem_T *hi = NULL;
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3579 char_u *varname;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3580
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3581 if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL)
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3582 return NULL;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3583
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3584 /* Search in parent scope which is possible to reference from lambda */
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3585 current_funccal = current_funccal->func->uf_scoped;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3586 while (current_funccal != NULL)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3587 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3588 ht = find_var_ht(name, &varname);
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3589 if (ht != NULL && *varname != NUL)
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3590 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3591 hi = hash_find(ht, varname);
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3592 if (!HASHITEM_EMPTY(hi))
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3593 {
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3594 *pht = ht;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3595 break;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3596 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3597 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3598 if (current_funccal == current_funccal->func->uf_scoped)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3599 break;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3600 current_funccal = current_funccal->func->uf_scoped;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3601 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3602 current_funccal = old_current_funccal;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3603
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3604 return hi;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3605 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3606
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3607 /*
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3608 * Search variable in parent scope.
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3609 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3610 dictitem_T *
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3611 find_var_in_scoped_ht(char_u *name, int no_autoload)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3612 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3613 dictitem_T *v = NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3614 funccall_T *old_current_funccal = current_funccal;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3615 hashtab_T *ht;
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3616 char_u *varname;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3617
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3618 if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3619 return NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3620
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3621 /* Search in parent scope which is possible to reference from lambda */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3622 current_funccal = current_funccal->func->uf_scoped;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3623 while (current_funccal)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3624 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3625 ht = find_var_ht(name, &varname);
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3626 if (ht != NULL && *varname != NUL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3627 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3628 v = find_var_in_ht(ht, *name, varname, no_autoload);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3629 if (v != NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3630 break;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3631 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3632 if (current_funccal == current_funccal->func->uf_scoped)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3633 break;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3634 current_funccal = current_funccal->func->uf_scoped;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3635 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3636 current_funccal = old_current_funccal;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3637
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3638 return v;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3639 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3640
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3641 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3642 * Set "copyID + 1" in previous_funccal and callers.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3643 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3644 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3645 set_ref_in_previous_funccal(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3646 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3647 int abort = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3648 funccall_T *fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3649
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3650 for (fc = previous_funccal; fc != NULL; fc = fc->caller)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3651 {
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3652 fc->fc_copyID = copyID + 1;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3653 abort = abort || set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID + 1,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3654 NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3655 abort = abort || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID + 1,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3656 NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3657 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3658 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3659 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3660
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3661 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3662 * Set "copyID" in all local vars and arguments in the call stack.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3663 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3664 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3665 set_ref_in_call_stack(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3666 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3667 int abort = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3668 funccall_T *fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3669
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3670 for (fc = current_funccal; fc != NULL; fc = fc->caller)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3671 {
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3672 fc->fc_copyID = copyID;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3673 abort = abort || set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3674 abort = abort || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3675 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3676 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3677 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3678
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3679 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3680 * Set "copyID" in all function arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3681 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3682 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3683 set_ref_in_func_args(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3684 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3685 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3686 int abort = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3687
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3688 for (i = 0; i < funcargs.ga_len; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3689 abort = abort || set_ref_in_item(((typval_T **)funcargs.ga_data)[i],
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3690 copyID, NULL, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3691 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3692 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3693
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3694 /*
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3695 * Mark all lists and dicts referenced through function "name" with "copyID".
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3696 * "list_stack" is used to add lists to be marked. Can be NULL.
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3697 * "ht_stack" is used to add hashtabs to be marked. Can be NULL.
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3698 *
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3699 * Returns TRUE if setting references failed somehow.
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3700 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3701 int
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3702 set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3703 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3704 ufunc_T *fp = fp_in;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3705 funccall_T *fc;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3706 int error = ERROR_NONE;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3707 char_u fname_buf[FLEN_FIXED + 1];
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3708 char_u *tofree = NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3709 char_u *fname;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3710
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3711 if (name == NULL && fp_in == NULL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3712 return FALSE;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3713
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3714 if (fp_in == NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3715 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3716 fname = fname_trans_sid(name, fname_buf, &tofree, &error);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3717 fp = find_func(fname);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3718 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3719 if (fp != NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3720 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3721 for (fc = fp->uf_scoped; fc != NULL; fc = fc->func->uf_scoped)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3722 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3723 if (fc->fc_copyID != copyID)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3724 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3725 fc->fc_copyID = copyID;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3726 set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID, NULL);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3727 set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID, NULL);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3728 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3729 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3730 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3731 vim_free(tofree);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3732 return FALSE;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3733 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3734
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3735 #endif /* FEAT_EVAL */