annotate src/userfunc.c @ 17462:9088fafff9b3 v8.1.1729

patch 8.1.1729: heredoc with trim not properly handled in function commit https://github.com/vim/vim/commit/ecaa75b4cea329a3902b8565e028b32279b8322b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 21 23:04:21 2019 +0200 patch 8.1.1729: heredoc with trim not properly handled in function Problem: Heredoc with trim not properly handled in function. Solution: Allow for missing indent. (FUJIWARA Takuya, closes https://github.com/vim/vim/issues/4713)
author Bram Moolenaar <Bram@vim.org>
date Sun, 21 Jul 2019 23:15:05 +0200
parents 8f44c630c366
children ff097edaae89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9951
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
9562
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)
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
17 // flags used in uf_flags
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
18 #define FC_ABORT 0x01 // abort function on error
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
19 #define FC_RANGE 0x02 // function accepts range
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
20 #define FC_DICT 0x04 // Dict function, uses "self"
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
21 #define FC_CLOSURE 0x08 // closure, uses outer scope variables
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
22 #define FC_DELETED 0x10 // :delfunction used while uf_refcount > 0
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
23 #define FC_REMOVED 0x20 // function redefined while uf_refcount > 0
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
24 #define FC_SANDBOX 0x40 // function defined in the sandbox
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 #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
27
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 * 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
30 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 static hashtab_T func_hashtab;
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 /* Used by get_func_tv() */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 static garray_T funcargs = GA_EMPTY;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
36 // pointer to funccal for currently active function
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
37 static funccall_T *current_funccal = NULL;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
38
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
39 // Pointer to list of previously used funccal, still around because some
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
40 // item in it is still being used.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
41 static funccall_T *previous_funccal = NULL;
9562
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 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
44 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
45 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
46 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
47
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
48 static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 func_init()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 hash_init(&func_hashtab);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
56 /*
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
57 * Return the function hash table
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
58 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
59 hashtab_T *
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
60 func_tbl_get(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
61 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
62 return &func_hashtab;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
63 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
64
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
65 /*
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
66 * Get function arguments.
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
67 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 get_function_args(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 char_u **argp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 char_u endchar,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 garray_T *newargs,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 int *varargs,
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
74 garray_T *default_args,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 int skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 int mustend = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 char_u *arg = *argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 char_u *p = arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 int c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 int i;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
82 int any_default = FALSE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
83 char_u *expr;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 ga_init2(newargs, (int)sizeof(char_u *), 3);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
87 if (default_args != NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
88 ga_init2(default_args, (int)sizeof(char_u *), 3);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 if (varargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 *varargs = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 * Isolate the arguments: "arg1, arg2, ...)"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 while (*p != endchar)
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 if (p[0] == '.' && p[1] == '.' && p[2] == '.')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 if (varargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 *varargs = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 p += 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 mustend = TRUE;
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 arg = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 while (ASCII_ISALNUM(*p) || *p == '_')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 if (arg == p || isdigit(*arg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 || (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
112 || (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
113 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 if (!skip)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
115 semsg(_("E125: Illegal argument: %s"), arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 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
119 goto err_ret;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 c = *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 arg = vim_strsave(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 if (arg == NULL)
9612
0e7912e7064b commit https://github.com/vim/vim/commit/19df5cc04de93519145901d9cbc78c44d0c47c5d
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
126 {
0e7912e7064b commit https://github.com/vim/vim/commit/19df5cc04de93519145901d9cbc78c44d0c47c5d
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
127 *p = c;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 goto err_ret;
9612
0e7912e7064b commit https://github.com/vim/vim/commit/19df5cc04de93519145901d9cbc78c44d0c47c5d
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
129 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 /* Check for duplicate argument name. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 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
133 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
134 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
135 semsg(_("E853: Duplicate argument name: %s"), arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 vim_free(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 goto err_ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 ((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
140 newargs->ga_len++;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 *p = c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 }
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
144 if (*skipwhite(p) == '=' && default_args != NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
145 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
146 typval_T rettv;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
147
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
148 any_default = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
149 p = skipwhite(p) + 1;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
150 p = skipwhite(p);
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
151 expr = p;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
152 if (eval1(&p, &rettv, FALSE) != FAIL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
153 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
154 if (ga_grow(default_args, 1) == FAIL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
155 goto err_ret;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
156
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
157 // trim trailing whitespace
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
158 while (p > expr && VIM_ISWHITE(p[-1]))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
159 p--;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
160 c = *p;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
161 *p = NUL;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
162 expr = vim_strsave(expr);
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
163 if (expr == NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
164 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
165 *p = c;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
166 goto err_ret;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
167 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
168 ((char_u **)(default_args->ga_data))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
169 [default_args->ga_len] = expr;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
170 default_args->ga_len++;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
171 *p = c;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
172 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
173 else
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
174 mustend = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
175 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
176 else if (any_default)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
177 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
178 emsg(_("E989: Non-default argument follows default argument"));
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
179 mustend = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
180 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 if (*p == ',')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 mustend = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187 if (mustend && *p != endchar)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 if (!skip)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
190 semsg(_(e_invarg2), *argp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 }
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
194 if (*p != endchar)
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
195 goto err_ret;
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
196 ++p; /* skip "endchar" */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
198 *argp = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 return OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 err_ret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 ga_clear_strings(newargs);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
204 if (default_args != NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
205 ga_clear_strings(default_args);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206 return FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 /*
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
210 * 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
211 */
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
212 static int
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
213 register_closure(ufunc_T *fp)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
214 {
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
215 if (fp->uf_scoped == current_funccal)
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
216 /* no change */
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
217 return OK;
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
218 funccal_unref(fp->uf_scoped, fp, FALSE);
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
219 fp->uf_scoped = current_funccal;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
220 current_funccal->fc_refcount++;
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
221
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
222 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
223 return FAIL;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
224 ((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
225 [current_funccal->fc_funcs.ga_len++] = fp;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
226 return OK;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
227 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
228
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
229 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
230 * 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
231 * 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
232 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 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
235 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 garray_T newargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237 garray_T newlines;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
238 garray_T *pnewargs;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 ufunc_T *fp = NULL;
15820
bd75c9df2a14 patch 8.1.0917: double free when running out of memory
Bram Moolenaar <Bram@vim.org>
parents: 15780
diff changeset
240 partial_T *pt = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
241 int varargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 int ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 char_u *start = skipwhite(*arg + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244 char_u *s, *e;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 static int lambda_no = 0;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
246 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
247 int eval_lavars = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 ga_init(&newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
250 ga_init(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 /* First, check if this is a lambda expression. "->" must exist. */
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
253 ret = get_function_args(&start, '-', NULL, NULL, NULL, TRUE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 if (ret == FAIL || *start != '>')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 return NOTDONE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 /* Parse the arguments again. */
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
258 if (evaluate)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
259 pnewargs = &newargs;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
260 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
261 pnewargs = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262 *arg = skipwhite(*arg + 1);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
263 ret = get_function_args(arg, '-', pnewargs, &varargs, NULL, FALSE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264 if (ret == FAIL || **arg != '>')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
265 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
266
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
267 /* 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
268 if (evaluate)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
269 eval_lavars_used = &eval_lavars;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
270
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
271 /* 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
272 *arg = skipwhite(*arg + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 s = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 ret = skip_expr(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 if (ret == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
277 e = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 *arg = skipwhite(*arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
279 if (**arg != '}')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 ++*arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
282
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
283 if (evaluate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
284 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
285 int len, flags = 0;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
286 char_u *p;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
287 char_u name[20];
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
288
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
289 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
290
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
291 fp = alloc_clear(sizeof(ufunc_T) + STRLEN(name));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 goto errret;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
294 pt = ALLOC_CLEAR_ONE(partial_T);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
295 if (pt == NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
296 goto errret;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
298 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
299 if (ga_grow(&newlines, 1) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
302 /* Add "return " before the expression. */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303 len = 7 + e - s + 1;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
304 p = alloc(len);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 if (p == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307 ((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
308 STRCPY(p, "return ");
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
309 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
310
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 fp->uf_refcount = 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
312 STRCPY(fp->uf_name, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 hash_add(&func_hashtab, UF2HIKEY(fp));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 fp->uf_args = newargs;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
315 ga_init(&fp->uf_def_args);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 fp->uf_lines = newlines;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
317 if (current_funccal != NULL && eval_lavars)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
318 {
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
319 flags |= FC_CLOSURE;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
320 if (register_closure(fp) == FAIL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
321 goto errret;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
322 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
323 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
324 fp->uf_scoped = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
325
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327 if (prof_def_func())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
328 func_do_profile(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
329 #endif
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
330 if (sandbox)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
331 flags |= FC_SANDBOX;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
332 fp->uf_varargs = TRUE;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
333 fp->uf_flags = flags;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 fp->uf_calls = 0;
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
335 fp->uf_script_ctx = current_sctx;
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
336 fp->uf_script_ctx.sc_lnum += sourcing_lnum - newlines.ga_len;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
338 pt->pt_func = fp;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
339 pt->pt_refcount = 1;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
340 rettv->vval.v_partial = pt;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
341 rettv->v_type = VAR_PARTIAL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
342 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
343
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
344 eval_lavars_used = old_eval_lavars;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 return OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 errret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 ga_clear_strings(&newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 ga_clear_strings(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 vim_free(fp);
15820
bd75c9df2a14 patch 8.1.0917: double free when running out of memory
Bram Moolenaar <Bram@vim.org>
parents: 15780
diff changeset
351 vim_free(pt);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
352 eval_lavars_used = old_eval_lavars;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 return FAIL;
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
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 * 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
358 * name it contains, otherwise return "name".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359 * 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
360 * "partialp".
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 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
363 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
364 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
366 int cc;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
367 char_u *s;
9562
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 if (partialp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
370 *partialp = NULL;
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 cc = name[*lenp];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
373 name[*lenp] = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
374 v = find_var(name, NULL, no_autoload);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
375 name[*lenp] = cc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
376 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
377 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378 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
379 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
380 *lenp = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381 return (char_u *)""; /* just in case */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
383 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
384 *lenp = (int)STRLEN(s);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
385 return s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
386 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
387
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
388 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
389 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 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
391
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
392 if (pt == NULL)
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 *lenp = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395 return (char_u *)""; /* just in case */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 if (partialp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 *partialp = pt;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
399 s = partial_name(pt);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
400 *lenp = (int)STRLEN(s);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
401 return s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
403
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 return name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 }
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
408 * 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
409 * "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
410 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
411 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
412 emsg_funcname(char *ermsg, char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
413 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
414 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
415
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 if (*name == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
417 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
418 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
419 p = name;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
420 semsg(_(ermsg), p);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
421 if (p != name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424
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 * 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
427 * Return OK or FAIL.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
428 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430 get_func_tv(
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
431 char_u *name, // name of the function
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
432 int len, // length of "name" or -1 to use strlen()
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 typval_T *rettv,
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
434 char_u **arg, // argument, pointing to the '('
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
435 linenr_T firstline, // first line of range
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
436 linenr_T lastline, // last line of range
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
437 int *doesrange, // return: function handled range
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438 int evaluate,
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
439 partial_T *partial, // for extra arguments
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
440 dict_T *selfdict) // Dictionary for "self"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
442 char_u *argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 int ret = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 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
445 int argcount = 0; /* number of arguments found */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448 * Get the arguments.
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 argp = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
451 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
452 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 argp = skipwhite(argp + 1); /* skip the '(' or ',' */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454 if (*argp == ')' || *argp == ',' || *argp == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
456 if (eval1(&argp, &argvars[argcount], evaluate) == FAIL)
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 ret = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
459 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
460 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
461 ++argcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
462 if (*argp != ',')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
463 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465 if (*argp == ')')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466 ++argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
468 ret = FAIL;
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 if (ret == OK)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 int i = 0;
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 if (get_vim_var_nr(VV_TESTING))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476 /* 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
477 * 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
478 if (funcargs.ga_itemsize == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 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
480 for (i = 0; i < argcount; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 if (ga_grow(&funcargs, 1) == OK)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 ((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
483 &argvars[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
486 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
487 firstline, lastline, doesrange, evaluate, partial, selfdict);
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 funcargs.ga_len -= i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491 else if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 if (argcount == MAX_FUNC_ARGS)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 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
495 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 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
497 }
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 while (--argcount >= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500 clear_tv(&argvars[argcount]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 *arg = skipwhite(argp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 return ret;
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 #define FLEN_FIXED 40
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507
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 * 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
510 * 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
511 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
512 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 eval_fname_sid(char_u *p)
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 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
516 }
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 * 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
520 * 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
521 * 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
522 * (slow).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 static char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 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
526 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
527 int llen;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 char_u *fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529 int i;
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 llen = eval_fname_script(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 if (llen > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 fname_buf[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 fname_buf[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536 fname_buf[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 i = 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 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
539 {
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
540 if (current_sctx.sc_sid <= 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 *error = ERROR_SCRIPT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543 {
16378
3d6b282e2d6e patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents: 16003
diff changeset
544 sprintf((char *)fname_buf + 3, "%ld_",
3d6b282e2d6e patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents: 16003
diff changeset
545 (long)current_sctx.sc_sid);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 i = (int)STRLEN(fname_buf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
547 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 if (i + STRLEN(name + llen) < FLEN_FIXED)
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 STRCPY(fname_buf + i, name + llen);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
552 fname = fname_buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
553 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
554 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
555 {
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16708
diff changeset
556 fname = alloc(i + STRLEN(name + llen) + 1);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
557 if (fname == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
558 *error = ERROR_OTHER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
559 else
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 *tofree = fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
562 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
563 STRCPY(fname + i, name + llen);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
565 }
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 fname = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 return fname;
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 * 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
574 * Return NULL for unknown function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
576 ufunc_T *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577 find_func(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
579 hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 hi = hash_find(&func_hashtab, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
582 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 return HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
584 return NULL;
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 * 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
589 * "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
590 * Takes care of script-local function names.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
592 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
593 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
594 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
595 if (fp->uf_name[0] == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
596 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
597 STRCPY(buf, "<SNR>");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
598 STRCAT(buf, fp->uf_name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
600 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
601 STRCPY(buf, fp->uf_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 * 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
606 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 add_nr_var(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609 dict_T *dp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 dictitem_T *v,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
611 char *name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
612 varnumber_T nr)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 STRCPY(v->di_key, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615 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
616 hash_add(&dp->dv_hashtab, DI2HIKEY(v));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 v->di_tv.v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619 v->di_tv.vval.v_number = nr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
621
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 /*
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
623 * Free "fc".
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
624 */
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
625 static void
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
626 free_funccal(funccall_T *fc)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
627 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
628 int i;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
629
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
630 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
631 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
632 ufunc_T *fp = ((ufunc_T **)(fc->fc_funcs.ga_data))[i];
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
633
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
634 // When garbage collecting a funccall_T may be freed before the
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
635 // function that references it, clear its uf_scoped field.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
636 // The function may have been redefined and point to another
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
637 // funccall_T, don't clear it then.
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
638 if (fp != NULL && fp->uf_scoped == fc)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
639 fp->uf_scoped = NULL;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
640 }
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
641 ga_clear(&fc->fc_funcs);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
643 func_ptr_unref(fc->func);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
644 vim_free(fc);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
645 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
646
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
647 /*
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
648 * Free "fc" and what it contains.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
649 * Can be called only when "fc" is kept beyond the period of it called,
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
650 * i.e. after cleanup_function_call(fc).
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
651 */
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
652 static void
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
653 free_funccal_contents(funccall_T *fc)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
654 {
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
655 listitem_T *li;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
656
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
657 // Free all l: variables.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
658 vars_clear(&fc->l_vars.dv_hashtab);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
659
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
660 // Free all a: variables.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
661 vars_clear(&fc->l_avars.dv_hashtab);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
662
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
663 // Free the a:000 variables.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
664 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
665 clear_tv(&li->li_tv);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
666
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
667 free_funccal(fc);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
668 }
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
669
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
670 /*
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
671 * Handle the last part of returning from a function: free the local hashtable.
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
672 * Unless it is still in use by a closure.
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
673 */
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
674 static void
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
675 cleanup_function_call(funccall_T *fc)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
676 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
677 int may_free_fc = fc->fc_refcount <= 0;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
678 int free_fc = TRUE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
679
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
680 current_funccal = fc->caller;
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
681
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
682 // Free all l: variables if not referred.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
683 if (may_free_fc && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
684 vars_clear(&fc->l_vars.dv_hashtab);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
685 else
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
686 free_fc = FALSE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
687
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
688 // If the a:000 list and the l: and a: dicts are not referenced and
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
689 // there is no closure using it, we can free the funccall_T and what's
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
690 // in it.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
691 if (may_free_fc && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
692 vars_clear_ext(&fc->l_avars.dv_hashtab, FALSE);
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
693 else
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
694 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
695 int todo;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
696 hashitem_T *hi;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
697 dictitem_T *di;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
698
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
699 free_fc = FALSE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
700
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
701 // Make a copy of the a: variables, since we didn't do that above.
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
702 todo = (int)fc->l_avars.dv_hashtab.ht_used;
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
703 for (hi = fc->l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
704 {
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
705 if (!HASHITEM_EMPTY(hi))
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
706 {
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
707 --todo;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
708 di = HI2DI(hi);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
709 copy_tv(&di->di_tv, &di->di_tv);
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
710 }
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
711 }
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
712 }
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
713
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
714 if (may_free_fc && fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
715 fc->l_varlist.lv_first = NULL;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
716 else
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
717 {
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
718 listitem_T *li;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
719
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
720 free_fc = FALSE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
721
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
722 // Make a copy of the a:000 items, since we didn't do that above.
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
723 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
724 copy_tv(&li->li_tv, &li->li_tv);
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
725 }
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
726
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
727 if (free_fc)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
728 free_funccal(fc);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
729 else
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
730 {
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
731 static int made_copy = 0;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
732
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
733 // "fc" is still in use. This can happen when returning "a:000",
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
734 // assigning "l:" to a global variable or defining a closure.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
735 // Link "fc" in the list for garbage collection later.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
736 fc->caller = previous_funccal;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
737 previous_funccal = fc;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
738
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
739 if (want_garbage_collect)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
740 // If garbage collector is ready, clear count.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
741 made_copy = 0;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
742 else if (++made_copy >= (int)((4096 * 1024) / sizeof(*fc)))
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
743 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
744 // We have made a lot of copies, worth 4 Mbyte. This can happen
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
745 // when repetitively calling a function that creates a reference to
15721
e84eb23f4670 patch 8.1.0868: crash if triggering garbage collector after a function call
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
746 // itself somehow. Call the garbage collector soon to avoid using
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
747 // too much memory.
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
748 made_copy = 0;
15721
e84eb23f4670 patch 8.1.0868: crash if triggering garbage collector after a function call
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
749 want_garbage_collect = TRUE;
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
750 }
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
751 }
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
752 }
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
753
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
754 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
755 * Call a user function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
756 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
757 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
758 call_user_func(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
759 ufunc_T *fp, /* pointer to function */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
760 int argcount, /* nr of args */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
761 typval_T *argvars, /* arguments */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
762 typval_T *rettv, /* return value */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
763 linenr_T firstline, /* first line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
764 linenr_T lastline, /* last line of range */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
765 dict_T *selfdict) /* Dictionary for "self" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
766 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
767 char_u *save_sourcing_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
768 linenr_T save_sourcing_lnum;
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
769 sctx_T save_current_sctx;
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
770 int using_sandbox = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 funccall_T *fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
772 int save_did_emsg;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
773 int default_arg_err = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774 static int depth = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
775 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
776 int fixvar_idx = 0; /* index in fixvar[] */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
777 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
778 int ai;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
779 int islambda = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
780 char_u numbuf[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
781 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
782 size_t len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
783 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
784 proftime_T wait_start;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
785 proftime_T call_start;
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
786 int started_profiling = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
787 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
788
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
789 /* 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
790 if (depth >= p_mfd)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
791 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
792 emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
793 rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794 rettv->vval.v_number = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
796 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 ++depth;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
798
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
799 line_breakcheck(); /* check for CTRL-C hit */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
800
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
801 fc = ALLOC_CLEAR_ONE(funccall_T);
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
802 if (fc == NULL)
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
803 return;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 fc->caller = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 current_funccal = fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806 fc->func = fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
807 fc->rettv = rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
808 rettv->vval.v_number = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
809 fc->linenr = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
810 fc->returned = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
811 fc->level = ex_nesting_level;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
812 /* Check if this function has a breakpoint. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
813 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
814 fc->dbg_tick = debug_tick;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
815 /* Set up fields for closure. */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
816 fc->fc_refcount = 0;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
817 fc->fc_copyID = 0;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
818 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
819 func_ptr_ref(fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
820
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 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
822 islambda = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
823
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 * 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
826 * 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
827 * 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
828 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
829 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
830 * Init l: variables.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
831 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
832 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
833 if (selfdict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
834 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
835 /* 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
836 * some compiler that checks the destination size. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
837 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
838 name = v->di_key;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
839 STRCPY(name, "self");
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15721
diff changeset
840 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
841 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
842 v->di_tv.v_type = VAR_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
843 v->di_tv.v_lock = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
844 v->di_tv.vval.v_dict = selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
845 ++selfdict->dv_refcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
846 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
847
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
848 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
849 * Init a: variables.
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
850 * Set a:0 to "argcount" less number of named arguments, if >= 0.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 * 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
852 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 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
854 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "0",
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
855 (varnumber_T)(argcount >= fp->uf_args.ga_len
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
856 ? argcount - fp->uf_args.ga_len : 0));
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15721
diff changeset
857 fc->l_avars.dv_lock = VAR_FIXED;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
858 /* 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
859 * destination size. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
860 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
861 name = v->di_key;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
862 STRCPY(name, "000");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
863 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
864 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
865 v->di_tv.v_type = VAR_LIST;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
866 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
867 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
868 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
869 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
870 fc->l_varlist.lv_lock = VAR_FIXED;
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
873 * 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
874 * Set a:name to named arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
875 * Set a:N to the "..." arguments.
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 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
878 (varnumber_T)firstline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
879 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
880 (varnumber_T)lastline);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
881 for (i = 0; i < argcount || i < fp->uf_args.ga_len; ++i)
9562
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 int addlocal = FALSE;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
884 typval_T def_rettv;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
885 int isdefault = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
886
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
887 ai = i - fp->uf_args.ga_len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
888 if (ai < 0)
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 /* named argument a:name */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
891 name = FUNCARG(fp, i);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
892 if (islambda)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
893 addlocal = TRUE;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
894
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
895 // evaluate named argument default expression
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
896 isdefault = ai + fp->uf_def_args.ga_len >= 0
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
897 && (i >= argcount || (argvars[i].v_type == VAR_SPECIAL
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
898 && argvars[i].vval.v_number == VVAL_NONE));
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
899 if (isdefault)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
900 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
901 char_u *default_expr = NULL;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
902 def_rettv.v_type = VAR_NUMBER;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
903 def_rettv.vval.v_number = -1;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
904
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
905 default_expr = ((char_u **)(fp->uf_def_args.ga_data))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
906 [ai + fp->uf_def_args.ga_len];
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
907 if (eval1(&default_expr, &def_rettv, TRUE) == FAIL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
908 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
909 default_arg_err = 1;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
910 break;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
911 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
912 }
9562
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
915 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
916 /* "..." argument a:1, a:2, etc. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
917 sprintf((char *)numbuf, "%d", ai + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
918 name = numbuf;
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 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
921 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
922 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
923 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
924 STRCPY(v->di_key, name);
9562
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
927 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
928 v = dictitem_alloc(name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
929 if (v == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
930 break;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
931 v->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX;
9562
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
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
934 // Note: the values are copied directly to avoid alloc/free.
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
935 // "argvars" must have VAR_FIXED for v_lock.
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
936 v->di_tv = isdefault ? def_rettv : argvars[i];
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
937 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
938
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
939 if (addlocal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
940 {
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
941 /* 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
942 * 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
943 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
944 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
945 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
946 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
947 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
948
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
949 if (ai >= 0 && ai < MAX_FUNC_ARGS)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
950 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
951 listitem_T *li = &fc->l_listitems[ai];
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
952
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
953 li->li_tv = argvars[i];
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
954 li->li_tv.v_lock = VAR_FIXED;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
955 list_append(&fc->l_varlist, li);
9562
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 /* Don't redraw while executing the function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
960 ++RedrawingDisabled;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
961 save_sourcing_name = sourcing_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
962 save_sourcing_lnum = sourcing_lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
963 sourcing_lnum = 1;
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
964
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
965 if (fp->uf_flags & FC_SANDBOX)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
966 {
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
967 using_sandbox = TRUE;
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
968 ++sandbox;
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
969 }
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
970
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
971 /* 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
972 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
973 + STRLEN(fp->uf_name) + 20;
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16708
diff changeset
974 sourcing_name = alloc(len);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
975 if (sourcing_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
976 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
977 if (save_sourcing_name != NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
978 && STRNCMP(save_sourcing_name, "function ", 9) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
979 sprintf((char *)sourcing_name, "%s[%d]..",
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
980 save_sourcing_name, (int)save_sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
981 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
982 STRCPY(sourcing_name, "function ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
983 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
984
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
985 if (p_verbose >= 12)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
986 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
987 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
988 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
989
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
990 smsg(_("calling %s"), sourcing_name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
991 if (p_verbose >= 14)
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 char_u buf[MSG_BUF_LEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
994 char_u numbuf2[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
995 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
996 char_u *s;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
997
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
998 msg_puts("(");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
999 for (i = 0; i < argcount; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1000 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1001 if (i > 0)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1002 msg_puts(", ");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1003 if (argvars[i].v_type == VAR_NUMBER)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1004 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
1005 else
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 /* 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
1008 ++emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1009 s = tv2string(&argvars[i], &tofree, numbuf2, 0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1010 --emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1011 if (s != NULL)
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 if (vim_strsize(s) > MSG_BUF_CLEN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1014 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1015 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
1016 s = buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1017 }
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1018 msg_puts((char *)s);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1019 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1020 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1021 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1022 }
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1023 msg_puts(")");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1024 }
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1025 msg_puts("\n"); /* don't overwrite this either */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1026
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1027 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1028 --no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1029 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1030 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1031 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1032 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1033 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1034 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1035 {
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1036 started_profiling = TRUE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1037 func_do_profile(fp);
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1038 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1039 if (fp->uf_profiling
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1040 || (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
1041 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1042 ++fp->uf_tm_count;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1043 profile_start(&call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1044 profile_zero(&fp->uf_tm_children);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1045 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1046 script_prof_save(&wait_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1047 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1048 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1049
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1050 save_current_sctx = current_sctx;
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1051 current_sctx = fp->uf_script_ctx;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1052 save_did_emsg = did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1053 did_emsg = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1054
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1055 if (default_arg_err && (fp->uf_flags & FC_ABORT))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1056 did_emsg = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1057 else
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1058 // call do_cmdline() to execute the lines
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1059 do_cmdline(NULL, get_func_line, (void *)fc,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1060 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1061
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1062 --RedrawingDisabled;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1063
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1064 /* 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
1065 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
1066 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1067 clear_tv(rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1068 rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1069 rettv->vval.v_number = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1070 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1071
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1072 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1073 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
1074 || (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
1075 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1076 profile_end(&call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1077 profile_sub_wait(&wait_start, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1078 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
1079 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
1080 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
1081 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1082 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
1083 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
1084 }
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1085 if (started_profiling)
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1086 // make a ":profdel func" stop profiling the function
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1087 fp->uf_profiling = FALSE;
9562
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 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1090
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1091 /* when being verbose, mention the return value */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1092 if (p_verbose >= 12)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1093 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1094 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1095 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1096
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1097 if (aborting())
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1098 smsg(_("%s aborted"), sourcing_name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1099 else if (fc->rettv->v_type == VAR_NUMBER)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1100 smsg(_("%s returning #%ld"), sourcing_name,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1101 (long)fc->rettv->vval.v_number);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1102 else
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 char_u buf[MSG_BUF_LEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1105 char_u numbuf2[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1106 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1107 char_u *s;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1108
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1109 /* 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
1110 * 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
1111 * 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
1112 ++emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1113 s = tv2string(fc->rettv, &tofree, numbuf2, 0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1114 --emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1115 if (s != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1116 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1117 if (vim_strsize(s) > MSG_BUF_CLEN)
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 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
1120 s = buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1121 }
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1122 smsg(_("%s returning %s"), sourcing_name, s);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1123 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1124 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1125 }
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1126 msg_puts("\n"); /* don't overwrite this either */
9562
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 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1129 --no_wait_return;
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1132 vim_free(sourcing_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1133 sourcing_name = save_sourcing_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1134 sourcing_lnum = save_sourcing_lnum;
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1135 current_sctx = save_current_sctx;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1136 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1137 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1138 script_prof_restore(&wait_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1139 #endif
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1140 if (using_sandbox)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1141 --sandbox;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1142
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1143 if (p_verbose >= 12 && sourcing_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1144 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1145 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1146 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1147
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1148 smsg(_("continuing in %s"), sourcing_name);
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1149 msg_puts("\n"); /* don't overwrite this either */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1150
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1151 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1152 --no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1153 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1154
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1155 did_emsg |= save_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1156 --depth;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1157
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1158 cleanup_function_call(fc);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1159 }
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 /*
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1162 * Unreference "fc": decrement the reference count and free it when it
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1163 * becomes zero. "fp" is detached from "fc".
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
1164 * When "force" is TRUE we are exiting.
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1165 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1166 static void
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
1167 funccal_unref(funccall_T *fc, ufunc_T *fp, int force)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1168 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1169 funccall_T **pfc;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1170 int i;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1171
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1172 if (fc == NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1173 return;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1174
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
1175 if (--fc->fc_refcount <= 0 && (force || (
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
1176 fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1177 && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
1178 && 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
1179 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
1180 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1181 if (fc == *pfc)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1182 {
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1183 *pfc = fc->caller;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1184 free_funccal_contents(fc);
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1185 return;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1186 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1187 }
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1188 for (i = 0; i < fc->fc_funcs.ga_len; ++i)
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1189 if (((ufunc_T **)(fc->fc_funcs.ga_data))[i] == fp)
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1190 ((ufunc_T **)(fc->fc_funcs.ga_data))[i] = NULL;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1191 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1192
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1193 /*
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1194 * 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
1195 * deleted while it still has references this was already done.
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1196 * Return TRUE if the entry was deleted, FALSE if it wasn't found.
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1197 */
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1198 static int
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1199 func_remove(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1200 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1201 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
1202
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1203 if (!HASHITEM_EMPTY(hi))
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1204 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1205 hash_remove(&func_hashtab, hi);
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1206 return TRUE;
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1207 }
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1208 return FALSE;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1209 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1210
14430
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1211 static void
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1212 func_clear_items(ufunc_T *fp)
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1213 {
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1214 ga_clear_strings(&(fp->uf_args));
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1215 ga_clear_strings(&(fp->uf_def_args));
14430
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1216 ga_clear_strings(&(fp->uf_lines));
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1217 #ifdef FEAT_PROFILE
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1218 vim_free(fp->uf_tml_count);
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1219 fp->uf_tml_count = NULL;
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1220 vim_free(fp->uf_tml_total);
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1221 fp->uf_tml_total = NULL;
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1222 vim_free(fp->uf_tml_self);
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1223 fp->uf_tml_self = NULL;
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1224 #endif
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1225 }
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1226
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1227 /*
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1228 * Free all things that a function contains. Does not free the function
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1229 * itself, use func_free() for that.
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
1230 * When "force" is TRUE we are exiting.
9562
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 static void
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1233 func_clear(ufunc_T *fp, int force)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1234 {
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1235 if (fp->uf_cleared)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1236 return;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1237 fp->uf_cleared = TRUE;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1238
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1239 /* clear this function */
14430
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1240 func_clear_items(fp);
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1241 funccal_unref(fp->uf_scoped, fp, force);
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1242 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1243
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1244 /*
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1245 * Free a function and remove it from the list of functions. Does not free
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1246 * what a function contains, call func_clear() first.
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1247 */
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1248 static void
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1249 func_free(ufunc_T *fp)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1250 {
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1251 /* only remove it when not done already, otherwise we would remove a newer
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1252 * version of the function */
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1253 if ((fp->uf_flags & (FC_DELETED | FC_REMOVED)) == 0)
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
1254 func_remove(fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1255
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1256 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1257 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1258
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1259 /*
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1260 * Free all things that a function contains and free the function itself.
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1261 * When "force" is TRUE we are exiting.
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1262 */
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1263 static void
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1264 func_clear_free(ufunc_T *fp, int force)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1265 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1266 func_clear(fp, force);
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1267 func_free(fp);
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1268 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1269
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1270 /*
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1271 * There are two kinds of function names:
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1272 * 1. ordinary names, function defined with :function
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1273 * 2. numbered functions and lambdas
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1274 * For the first we only count the name stored in func_hashtab as a reference,
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1275 * using function() does not count as a reference, because the function is
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1276 * looked up by name.
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1277 */
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1278 static int
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1279 func_name_refcount(char_u *name)
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1280 {
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1281 return isdigit(*name) || *name == '<';
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1282 }
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1283
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1284 static funccal_entry_T *funccal_stack = NULL;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1285
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1286 /*
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1287 * Save the current function call pointer, and set it to NULL.
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1288 * Used when executing autocommands and for ":source".
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1289 */
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1290 void
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1291 save_funccal(funccal_entry_T *entry)
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1292 {
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1293 entry->top_funccal = current_funccal;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1294 entry->next = funccal_stack;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1295 funccal_stack = entry;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1296 current_funccal = NULL;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1297 }
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1298
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1299 void
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1300 restore_funccal(void)
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1301 {
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1302 if (funccal_stack == NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1303 iemsg("INTERNAL: restore_funccal()");
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1304 else
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1305 {
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1306 current_funccal = funccal_stack->top_funccal;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1307 funccal_stack = funccal_stack->next;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1308 }
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1309 }
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1310
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1311 funccall_T *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1312 get_current_funccal(void)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1313 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1314 return current_funccal;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1315 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1316
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1317 #if defined(EXITFREE) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1318 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1319 free_all_functions(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1320 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1321 hashitem_T *hi;
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1322 ufunc_T *fp;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1323 long_u skipped = 0;
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1324 long_u todo = 1;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1325 long_u used;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1326
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1327 /* Clean up the current_funccal chain and the funccal stack. */
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1328 while (current_funccal != NULL)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1329 {
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1330 clear_tv(current_funccal->rettv);
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1331 cleanup_function_call(current_funccal);
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1332 if (current_funccal == NULL && funccal_stack != NULL)
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1333 restore_funccal();
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1334 }
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1335
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1336 /* First clear what the functions contain. Since this may lower the
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1337 * reference count of a function, it may also free a function and change
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1338 * the hash table. Restart if that happens. */
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1339 while (todo > 0)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1340 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1341 todo = func_hashtab.ht_used;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1342 for (hi = func_hashtab.ht_array; todo > 0; ++hi)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1343 if (!HASHITEM_EMPTY(hi))
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1344 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1345 /* Only free functions that are not refcounted, those are
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1346 * supposed to be freed when no longer referenced. */
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1347 fp = HI2UF(hi);
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1348 if (func_name_refcount(fp->uf_name))
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1349 ++skipped;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1350 else
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1351 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1352 used = func_hashtab.ht_used;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1353 func_clear(fp, TRUE);
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1354 if (used != func_hashtab.ht_used)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1355 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1356 skipped = 0;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1357 break;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1358 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1359 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1360 --todo;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1361 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1362 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1363
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1364 /* Now actually free the functions. Need to start all over every time,
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1365 * because func_free() may change the hash table. */
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1366 skipped = 0;
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1367 while (func_hashtab.ht_used > skipped)
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1368 {
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1369 todo = func_hashtab.ht_used;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1370 for (hi = func_hashtab.ht_array; todo > 0; ++hi)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1371 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1372 {
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1373 --todo;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1374 /* Only free functions that are not refcounted, those are
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1375 * supposed to be freed when no longer referenced. */
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1376 fp = HI2UF(hi);
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1377 if (func_name_refcount(fp->uf_name))
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1378 ++skipped;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1379 else
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1380 {
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1381 func_free(fp);
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1382 skipped = 0;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1383 break;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1384 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1385 }
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1386 }
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1387 if (skipped == 0)
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1388 hash_clear(&func_hashtab);
9562
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 #endif
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1393 * 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
1394 * 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
1395 * "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
1396 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1397 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1398 builtin_function(char_u *name, int len)
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 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1401
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1402 if (!ASCII_ISLOWER(name[0]))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1403 return FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1404 p = vim_strchr(name, AUTOLOAD_CHAR);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1405 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
1406 }
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 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1409 func_call(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1410 char_u *name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1411 typval_T *args,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1412 partial_T *partial,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1413 dict_T *selfdict,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1414 typval_T *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1415 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1416 listitem_T *item;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1417 typval_T argv[MAX_FUNC_ARGS + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1418 int argc = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1419 int dummy;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1420 int r = 0;
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 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
1423 item = item->li_next)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1424 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1425 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
1426 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1427 emsg(_("E699: Too many arguments"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1428 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1429 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1430 /* 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
1431 * 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
1432 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1433 copy_tv(&item->li_tv, &argv[argc++]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1434 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1435
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1436 if (item == NULL)
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1437 r = call_func(name, -1, rettv, argc, argv, NULL,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1438 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
1439 &dummy, TRUE, partial, selfdict);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1440
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1441 /* Free the arguments. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1442 while (argc > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1443 clear_tv(&argv[--argc]);
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 return r;
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1448 /*
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1449 * Invoke call_func() with a callback.
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1450 */
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1451 int
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1452 call_callback(
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1453 callback_T *callback,
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1454 int len, // length of "name" or -1 to use strlen()
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1455 typval_T *rettv, // return value goes here
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1456 int argcount, // number of "argvars"
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1457 typval_T *argvars, // vars for arguments, must have "argcount"
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1458 // PLUS ONE elements!
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1459 int (* argv_func)(int, typval_T *, int),
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1460 // function to fill in argvars
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1461 linenr_T firstline, // first line of range
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1462 linenr_T lastline, // last line of range
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1463 int *doesrange, // return: function handled range
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1464 int evaluate,
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1465 dict_T *selfdict) // Dictionary for "self"
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1466 {
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1467 return call_func(callback->cb_name, len, rettv, argcount, argvars,
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1468 argv_func, firstline, lastline, doesrange, evaluate,
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1469 callback->cb_partial, selfdict);
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1470 }
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1471
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1472 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1473 * 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
1474 *
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1475 * "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
1476 * 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
1477 * 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
1478 *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1479 * 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
1480 * 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
1481 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1482 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1483 call_func(
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1484 char_u *funcname, // name of the function
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1485 int len, // length of "name" or -1 to use strlen()
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1486 typval_T *rettv, // return value goes here
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1487 int argcount_in, // number of "argvars"
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1488 typval_T *argvars_in, // vars for arguments, must have "argcount"
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1489 // PLUS ONE elements!
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1490 int (* argv_func)(int, typval_T *, int),
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1491 // function to fill in argvars
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1492 linenr_T firstline, // first line of range
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1493 linenr_T lastline, // last line of range
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1494 int *doesrange, // return: function handled range
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1495 int evaluate,
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1496 partial_T *partial, // optional, can be NULL
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1497 dict_T *selfdict_in) // Dictionary for "self"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1498 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1499 int ret = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1500 int error = ERROR_NONE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1501 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1502 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1503 char_u fname_buf[FLEN_FIXED + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1504 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1505 char_u *fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1506 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1507 int argcount = argcount_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1508 typval_T *argvars = argvars_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1509 dict_T *selfdict = selfdict_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1510 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
1511 int argv_clear = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1512
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1513 // Make a copy of the name, if it comes from a funcref variable it could
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1514 // be changed or deleted in the called function.
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1515 name = len > 0 ? vim_strnsave(funcname, len) : vim_strsave(funcname);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1516 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1517 return ret;
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 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
1520
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1521 *doesrange = FALSE;
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 if (partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1524 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1525 /* 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
1526 * 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
1527 * 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
1528 if (partial->pt_dict != NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1529 && (selfdict_in == NULL || !partial->pt_auto))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1530 selfdict = partial->pt_dict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1531 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
1532 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1533 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
1534 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
1535 for (i = 0; i < argcount_in; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1536 argv[i + argv_clear] = argvars_in[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1537 argvars = argv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1538 argcount = partial->pt_argc + argcount_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1539 }
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
14002
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1542 /*
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1543 * Execute the function if executing and no errors were detected.
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1544 */
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1545 if (!evaluate)
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1546 {
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1547 // Not evaluating, which means the return value is unknown. This
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1548 // matters for giving error messages.
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1549 rettv->v_type = VAR_UNKNOWN;
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1550 }
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
1551 else if (error == ERROR_NONE)
9562
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 char_u *rfname = fname;
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 /* Ignore "g:" before a function name. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1556 if (fname[0] == 'g' && fname[1] == ':')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1557 rfname = fname + 2;
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 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
1560 rettv->vval.v_number = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1561 error = ERROR_UNKNOWN;
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 if (!builtin_function(rfname, -1))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1564 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1565 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1566 * User defined function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1567 */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1568 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
1569 fp = partial->pt_func;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1570 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1571 fp = find_func(rfname);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1572
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1573 /* Trigger FuncUndefined event, may load the function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1574 if (fp == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1575 && apply_autocmds(EVENT_FUNCUNDEFINED,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1576 rfname, rfname, TRUE, NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1577 && !aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1578 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1579 /* 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
1580 fp = find_func(rfname);
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 /* Try loading a package. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1583 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
1584 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1585 /* 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
1586 fp = find_func(rfname);
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
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1589 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
1590 error = ERROR_DELETED;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1591 else if (fp != NULL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1592 {
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1593 if (argv_func != NULL)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1594 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
1595
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1596 if (fp->uf_flags & FC_RANGE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1597 *doesrange = TRUE;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1598 if (argcount < fp->uf_args.ga_len - fp->uf_def_args.ga_len)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1599 error = ERROR_TOOFEW;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1600 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
1601 error = ERROR_TOOMANY;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1602 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
1603 error = ERROR_DICT;
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 int did_save_redo = FALSE;
11325
77f3b7316d8b patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents: 11299
diff changeset
1607 save_redo_T save_redo;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1608
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1609 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1610 * Call the user function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1611 * 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
1612 * redo buffer.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1613 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1614 save_search_patterns();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1615 #ifdef FEAT_INS_EXPAND
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1616 if (!ins_compl_active())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1617 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1618 {
11325
77f3b7316d8b patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents: 11299
diff changeset
1619 saveRedobuff(&save_redo);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1620 did_save_redo = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1621 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1622 ++fp->uf_calls;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1623 call_user_func(fp, argcount, argvars, rettv,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1624 firstline, lastline,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1625 (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
1626 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
1627 /* 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
1628 * now. */
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1629 func_clear_free(fp, FALSE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1630 if (did_save_redo)
11325
77f3b7316d8b patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents: 11299
diff changeset
1631 restoreRedobuff(&save_redo);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1632 restore_search_patterns();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1633 error = ERROR_NONE;
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 }
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1638 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1639 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1640 * 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
1641 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1642 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
1643 }
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 * 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
1646 * 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
1647 * 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
1648 * 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
1649 * 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
1650 * 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
1651 * 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
1652 * 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
1653 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1654 update_force_abort();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1655 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1656 if (error == ERROR_NONE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1657 ret = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1658
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1659 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1660 * 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
1661 * 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
1662 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1663 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1664 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1665 switch (error)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1666 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1667 case ERROR_UNKNOWN:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1668 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
1669 break;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1670 case ERROR_DELETED:
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1671 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
1672 break;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1673 case ERROR_TOOMANY:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1674 emsg_funcname((char *)e_toomanyarg, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1675 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1676 case ERROR_TOOFEW:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1677 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
1678 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1679 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1680 case ERROR_SCRIPT:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1681 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
1682 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1683 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1684 case ERROR_DICT:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1685 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
1686 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1687 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1688 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1689 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1690
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1691 while (argv_clear > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1692 clear_tv(&argv[--argv_clear]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1693 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1694 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1695
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1696 return ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1697 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1698
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1699 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1700 * 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
1701 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1702 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1703 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
1704 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1705 int j;
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 msg_start();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1708 if (indent)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1709 msg_puts(" ");
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1710 msg_puts("function ");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1711 if (fp->uf_name[0] == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1712 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1713 msg_puts_attr("<SNR>", HL_ATTR(HLF_8));
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1714 msg_puts((char *)fp->uf_name + 3);
9562
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 else
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1717 msg_puts((char *)fp->uf_name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1718 msg_putchar('(');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1719 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
1720 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1721 if (j)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1722 msg_puts(", ");
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1723 msg_puts((char *)FUNCARG(fp, j));
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1724 if (j >= fp->uf_args.ga_len - fp->uf_def_args.ga_len)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1725 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1726 msg_puts(" = ");
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1727 msg_puts(((char **)(fp->uf_def_args.ga_data))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1728 [j - fp->uf_args.ga_len + fp->uf_def_args.ga_len]);
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1729 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1730 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1731 if (fp->uf_varargs)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1732 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1733 if (j)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1734 msg_puts(", ");
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1735 msg_puts("...");
9562
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 msg_putchar(')');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1738 if (fp->uf_flags & FC_ABORT)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1739 msg_puts(" abort");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1740 if (fp->uf_flags & FC_RANGE)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1741 msg_puts(" range");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1742 if (fp->uf_flags & FC_DICT)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1743 msg_puts(" dict");
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1744 if (fp->uf_flags & FC_CLOSURE)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1745 msg_puts(" closure");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1746 msg_clr_eos();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1747 if (p_verbose > 0)
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1748 last_set_msg(fp->uf_script_ctx);
9562
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
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 * 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
1753 * 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
1754 * 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
1755 * flags:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1756 * TFN_INT: internal function name OK
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1757 * TFN_QUIET: be quiet
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1758 * 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
1759 * 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
1760 * 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
1761 */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1762 char_u *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1763 trans_function_name(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1764 char_u **pp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1765 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
1766 int flags,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1767 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
1768 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
1769 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1770 char_u *name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1771 char_u *start;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1772 char_u *end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1773 int lead;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1774 char_u sid_buf[20];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1775 int len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1776 lval_T lv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1777
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1778 if (fdp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1779 vim_memset(fdp, 0, sizeof(funcdict_T));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1780 start = *pp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1781
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1782 /* 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
1783 * command). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1784 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
1785 && (*pp)[2] == (int)KE_SNR)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1787 *pp += 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1788 len = get_id_len(pp) + 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1789 return vim_strnsave(start, len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1790 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1791
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1792 /* 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
1793 * 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
1794 lead = eval_fname_script(start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1795 if (lead > 2)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1796 start += lead;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1797
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1798 /* Note that TFN_ flags use the same values as GLV_ flags. */
13002
f7b2ecaeb79c patch 8.0.1377: cannot call a dict function in autoloaded dict
Christian Brabandt <cb@256bit.org>
parents: 11569
diff changeset
1799 end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1800 lead > 2 ? 0 : FNE_CHECK_START);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1801 if (end == start)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1802 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1803 if (!skip)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1804 emsg(_("E129: Function name required"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1805 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1806 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1807 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
1808 {
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 * 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
1811 * 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
1812 * interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1813 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1814 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1815 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1816 if (end != NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1817 semsg(_(e_invarg2), start);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1818 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1819 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1820 *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
1821 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1822 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1823
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1824 if (lv.ll_tv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1825 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1826 if (fdp != 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 fdp->fd_dict = lv.ll_dict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1829 fdp->fd_newkey = lv.ll_newkey;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1830 lv.ll_newkey = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1831 fdp->fd_di = lv.ll_di;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1832 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1833 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
1834 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1835 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
1836 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1837 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1838 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
1839 && lv.ll_tv->vval.v_partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1840 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1841 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
1842 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1843 if (partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1844 *partial = lv.ll_tv->vval.v_partial;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1845 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1846 else
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 if (!skip && !(flags & TFN_QUIET) && (fdp == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1849 || lv.ll_dict == NULL || fdp->fd_newkey == NULL))
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1850 emsg(_(e_funcref));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1851 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1852 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1853 name = NULL;
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 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1856 }
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 if (lv.ll_name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1859 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1860 /* 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
1861 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1862 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1863 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1864
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1865 /* 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
1866 if (lv.ll_exp_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1867 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1868 len = (int)STRLEN(lv.ll_exp_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1869 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
1870 flags & TFN_NO_AUTOLOAD);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1871 if (name == lv.ll_exp_name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1872 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1873 }
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
1874 else if (!(flags & TFN_NO_DEREF))
9562
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 len = (int)(end - *pp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1877 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
1878 if (name == *pp)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1879 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1880 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1881 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1882 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1883 name = vim_strsave(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1884 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1885 if (STRNCMP(name, "<SNR>", 5) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1886 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1887 /* Change "<SNR>" to the byte sequence. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1888 name[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1889 name[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1890 name[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1891 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
1892 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1893 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1894 }
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 if (lv.ll_exp_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1897 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1898 len = (int)STRLEN(lv.ll_exp_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1899 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
1900 && STRNCMP(lv.ll_name, "s:", 2) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1901 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1902 /* 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
1903 * leading "s:" then remove it. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1904 lv.ll_name += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1905 len -= 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1906 lead = 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1907 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1908 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1909 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1910 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1911 /* skip over "s:" and "g:" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1912 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
1913 lv.ll_name += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1914 len = (int)(end - lv.ll_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1915 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1916
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 * Copy the function name to allocated memory.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1919 * 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
1920 * Accept <SNR>123_name() outside a script.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1921 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1922 if (skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1923 lead = 0; /* do nothing */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1924 else if (lead > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1925 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1926 lead = 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1927 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
1928 || eval_fname_sid(*pp))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1929 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1930 /* It's "s:" or "<SID>" */
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1931 if (current_sctx.sc_sid <= 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1932 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1933 emsg(_(e_usingsid));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1934 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1935 }
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1936 sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1937 lead += (int)STRLEN(sid_buf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1938 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1939 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1940 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
1941 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1942 semsg(_("E128: Function name must start with a capital or \"s:\": %s"),
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1943 start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1944 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1945 }
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
1946 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
1947 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1948 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
1949
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1950 if (cp != NULL && cp < end)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1951 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1952 semsg(_("E884: Function name cannot contain a colon: %s"), start);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1953 goto theend;
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1956
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16708
diff changeset
1957 name = alloc(len + lead + 1);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1958 if (name != NULL)
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 if (lead > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1961 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1962 name[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1963 name[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1964 name[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1965 if (lead > 3) /* If it's "<SID>" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1966 STRCPY(name + 3, sid_buf);
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 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
1969 name[lead + len] = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1970 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1971 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1972
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1973 theend:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1974 clear_lval(&lv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1975 return name;
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1978 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1979 * ":function"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1980 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1981 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1982 ex_function(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1983 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1984 char_u *theline;
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
1985 char_u *line_to_free = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1986 int j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1987 int c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1988 int saved_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1989 int saved_wait_return = need_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1990 char_u *name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1991 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1992 char_u *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1993 char_u *line_arg = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1994 garray_T newargs;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1995 garray_T default_args;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1996 garray_T newlines;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1997 int varargs = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1998 int flags = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1999 ufunc_T *fp;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2000 int overwrite = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2001 int indent;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2002 int nesting;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2003 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2004 funcdict_T fudi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2005 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
2006 int paren;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2007 hashtab_T *ht;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2008 int todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2009 hashitem_T *hi;
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2010 int do_concat = TRUE;
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2011 linenr_T sourcing_lnum_off;
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2012 linenr_T sourcing_lnum_top;
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2013 int is_heredoc = FALSE;
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2014 char_u *skip_until = NULL;
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2015 char_u *heredoc_trimmed = NULL;
9562
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2018 * ":function" without argument: list functions.
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 if (ends_excmd(*eap->arg))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2021 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2022 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2023 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2024 todo = (int)func_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2025 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
2026 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2027 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2028 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2029 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2030 fp = HI2UF(hi);
14968
c5ec5ddbe814 patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents: 14927
diff changeset
2031 if (message_filtered(fp->uf_name))
c5ec5ddbe814 patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents: 14927
diff changeset
2032 continue;
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
2033 if (!func_name_refcount(fp->uf_name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2034 list_func_head(fp, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2035 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2036 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2037 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2038 eap->nextcmd = check_nextcmd(eap->arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2039 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2040 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2041
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2042 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2043 * ":function /pat": list functions matching pattern.
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 if (*eap->arg == '/')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2046 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2047 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
2048 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2049 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2050 regmatch_T regmatch;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2051
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2052 c = *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2053 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2054 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
2055 *p = c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2056 if (regmatch.regprog != NULL)
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 regmatch.rm_ic = p_ic;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2059
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2060 todo = (int)func_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2061 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
2062 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2063 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2064 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2065 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2066 fp = HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2067 if (!isdigit(*fp->uf_name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2068 && vim_regexec(&regmatch, fp->uf_name, 0))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2069 list_func_head(fp, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2070 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2071 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2072 vim_regfree(regmatch.regprog);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2073 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2074 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2075 if (*p == '/')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2076 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2077 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2078 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2079 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2080
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2081 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2082 * 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
2083 * func normal function name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2084 * "name" == func, "fudi.fd_dict" == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2085 * dict.func new dictionary entry
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2086 * "name" == NULL, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2087 * "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
2088 * 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
2089 * "name" == func, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2090 * "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
2091 * 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
2092 * "name" == NULL, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2093 * "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
2094 * s:func script-local function name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2095 * 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
2096 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2097 p = eap->arg;
13004
41e46caf1030 patch 8.0.1378: autoload script sources itself when defining function
Christian Brabandt <cb@256bit.org>
parents: 13002
diff changeset
2098 name = trans_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2099 paren = (vim_strchr(p, '(') != NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2100 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
2101 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2102 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2103 * 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
2104 * 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
2105 * interrupt, or an exception.
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 (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2108 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2109 if (!eap->skip && fudi.fd_newkey != NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2110 semsg(_(e_dictkey), fudi.fd_newkey);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2111 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2112 return;
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2115 eap->skip = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2116 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2117
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2118 /* 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
2119 * 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
2120 saved_did_emsg = did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2121 did_emsg = FALSE;
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 * ":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
2125 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2126 if (!paren)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2127 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2128 if (!ends_excmd(*skipwhite(p)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2129 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2130 emsg(_(e_trailing));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2131 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2132 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2133 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2134 if (eap->nextcmd != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2135 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2136 if (!eap->skip && !got_int)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2137 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2138 fp = find_func(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2139 if (fp != NULL)
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 list_func_head(fp, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2142 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
2143 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2144 if (FUNCLINE(fp, j) == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2145 continue;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2146 msg_putchar('\n');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2147 msg_outnum((long)(j + 1));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2148 if (j < 9)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2149 msg_putchar(' ');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2150 if (j < 99)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2151 msg_putchar(' ');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2152 msg_prt_line(FUNCLINE(fp, j), FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2153 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
2154 ui_breakcheck();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2155 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2156 if (!got_int)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2157 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2158 msg_putchar('\n');
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
2159 msg_puts(" endfunction");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2160 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2161 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2162 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2163 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
2164 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2165 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2166 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2167
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2168 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2169 * ":function name(arg1, arg2)" Define function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2170 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2171 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2172 if (*p != '(')
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 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2175 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2176 semsg(_("E124: Missing '(': %s"), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2177 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2178 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2179 /* attempt to continue by skipping some text */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2180 if (vim_strchr(p, '(') != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2181 p = vim_strchr(p, '(');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2182 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2183 p = skipwhite(p + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2184
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2185 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
2186
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2187 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2188 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2189 /* 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
2190 * (that we are overwriting). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2191 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2192 arg = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2193 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2194 arg = fudi.fd_newkey;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2195 if (arg != NULL && (fudi.fd_di == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2196 || (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
2197 && 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
2198 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2199 if (*arg == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2200 j = 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2201 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2202 j = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2203 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
2204 : eval_isnamec(arg[j])))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2205 ++j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2206 if (arg[j] != NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2207 emsg_funcname((char *)e_invarg2, arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2208 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2209 /* Disallow using the g: dict. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2210 if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2211 emsg(_("E862: Cannot use g: here"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2212 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2213
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
2214 if (get_function_args(&p, ')', &newargs, &varargs,
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
2215 &default_args, eap->skip) == FAIL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2216 goto errret_2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2217
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2218 /* 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
2219 for (;;)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2220 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2221 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2222 if (STRNCMP(p, "range", 5) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2223 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2224 flags |= FC_RANGE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2225 p += 5;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2226 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2227 else if (STRNCMP(p, "dict", 4) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2228 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2229 flags |= FC_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2230 p += 4;
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 else if (STRNCMP(p, "abort", 5) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2233 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2234 flags |= FC_ABORT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2235 p += 5;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2236 }
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2237 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
2238 {
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2239 flags |= FC_CLOSURE;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2240 p += 7;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2241 if (current_funccal == NULL)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2242 {
9951
d990a4394c9d commit https://github.com/vim/vim/commit/ba2099034f92a2814494f37bddb0c57d034401b4
Christian Brabandt <cb@256bit.org>
parents: 9844
diff changeset
2243 emsg_funcname(N_("E932: Closure function should not be at top level: %s"),
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2244 name == NULL ? (char_u *)"" : name);
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2245 goto erret;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2246 }
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2247 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2248 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2249 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2250 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2251
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2252 /* 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
2253 * Makes 'exe "func Test()\n...\nendfunc"' work. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2254 if (*p == '\n')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2255 line_arg = p + 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2256 else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2257 emsg(_(e_trailing));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2258
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2259 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2260 * 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
2261 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2262 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2263 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2264 /* 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
2265 * 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
2266 * 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
2267 if (!eap->skip && !eap->forceit)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2268 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2269 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2270 emsg(_(e_funcdict));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2271 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
2272 emsg_funcname(e_funcexts, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2273 }
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 if (!eap->skip && did_emsg)
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2278 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
2279 cmdline_row = msg_row;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2280 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2281
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2282 // Save the starting line number.
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2283 sourcing_lnum_top = sourcing_lnum;
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2284
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2285 indent = 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2286 nesting = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2287 for (;;)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2288 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2289 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2290 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2291 msg_scroll = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2292 saved_wait_return = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2293 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2294 need_wait_return = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2295
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2296 if (line_arg != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2297 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2298 /* 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
2299 theline = line_arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2300 p = vim_strchr(theline, '\n');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2301 if (p == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2302 line_arg += STRLEN(line_arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2303 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2304 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2305 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2306 line_arg = p + 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2307 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2308 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2309 else
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2310 {
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2311 vim_free(line_to_free);
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2312 if (eap->getline == NULL)
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2313 theline = getcmdline(':', 0L, indent, do_concat);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2314 else
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2315 theline = eap->getline(':', eap->cookie, indent, do_concat);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2316 line_to_free = theline;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2317 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2318 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2319 lines_left = Rows - 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2320 if (theline == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2321 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2322 emsg(_("E126: Missing :endfunction"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2323 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2324 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2325
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2326 /* Detect line continuation: sourcing_lnum increased more than one. */
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2327 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie);
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2328 if (sourcing_lnum < sourcing_lnum_off)
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2329 sourcing_lnum_off -= sourcing_lnum;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2330 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2331 sourcing_lnum_off = 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 if (skip_until != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2334 {
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2335 // Don't check for ":endfunc" between
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2336 // * ":append" and "."
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2337 // * ":python <<EOF" and "EOF"
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2338 // * ":let {var-name} =<< [trim] {marker}" and "{marker}"
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2339 if (heredoc_trimmed == NULL
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2340 || (is_heredoc && skipwhite(theline) == theline)
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2341 || STRNCMP(theline, heredoc_trimmed,
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2342 STRLEN(heredoc_trimmed)) == 0)
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2343 {
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2344 if (heredoc_trimmed == NULL)
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2345 p = theline;
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2346 else if (is_heredoc)
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2347 p = skipwhite(theline) == theline
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2348 ? theline : theline + STRLEN(heredoc_trimmed);
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2349 else
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2350 p = theline + STRLEN(heredoc_trimmed);
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2351 if (STRCMP(p, skip_until) == 0)
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2352 {
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2353 VIM_CLEAR(skip_until);
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2354 VIM_CLEAR(heredoc_trimmed);
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2355 do_concat = TRUE;
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2356 is_heredoc = FALSE;
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2357 }
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2358 }
9562
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2361 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2362 /* skip ':' and blanks*/
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10815
diff changeset
2363 for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2364 ;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2365
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2366 /* Check for "endfunction". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2367 if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2368 {
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2369 char_u *nextcmd = NULL;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2370
11543
57c452316da1 patch 8.0.0654: no warning for text after :endfunction
Christian Brabandt <cb@256bit.org>
parents: 11325
diff changeset
2371 if (*p == '|')
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2372 nextcmd = p + 1;
11543
57c452316da1 patch 8.0.0654: no warning for text after :endfunction
Christian Brabandt <cb@256bit.org>
parents: 11325
diff changeset
2373 else if (line_arg != NULL && *skipwhite(line_arg) != NUL)
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2374 nextcmd = line_arg;
11543
57c452316da1 patch 8.0.0654: no warning for text after :endfunction
Christian Brabandt <cb@256bit.org>
parents: 11325
diff changeset
2375 else if (*p != NUL && *p != '"' && p_verbose > 0)
11561
7ad79766365a patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents: 11545
diff changeset
2376 give_warning2(
7ad79766365a patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents: 11545
diff changeset
2377 (char_u *)_("W22: Text found after :endfunction: %s"),
7ad79766365a patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents: 11545
diff changeset
2378 p, TRUE);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2379 if (nextcmd != NULL)
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2380 {
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2381 /* Another command follows. If the line came from "eap" we
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2382 * can simply point into it, otherwise we need to change
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2383 * "eap->cmdlinep". */
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2384 eap->nextcmd = nextcmd;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2385 if (line_to_free != NULL)
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2386 {
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2387 vim_free(*eap->cmdlinep);
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2388 *eap->cmdlinep = line_to_free;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2389 line_to_free = NULL;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2390 }
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2391 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2392 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2393 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2394
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2395 /* 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
2396 * at "end". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2397 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
2398 indent -= 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2399 else if (STRNCMP(p, "if", 2) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2400 || STRNCMP(p, "wh", 2) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2401 || STRNCMP(p, "for", 3) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2402 || STRNCMP(p, "try", 3) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2403 indent += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2404
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2405 /* 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
2406 if (checkforcmd(&p, "function", 2))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2407 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2408 if (*p == '!')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409 p = skipwhite(p + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410 p += eval_fname_script(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411 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
2412 if (*skipwhite(p) == '(')
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 ++nesting;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2415 indent += 2;
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2418
10573
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2419 /* Check for ":append", ":change", ":insert". */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2420 p = skip_range(p, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2421 if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
10573
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2422 || (p[0] == 'c'
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2423 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'h'
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2424 && (!ASCII_ISALPHA(p[2]) || (p[2] == 'a'
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2425 && (STRNCMP(&p[3], "nge", 3) != 0
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2426 || !ASCII_ISALPHA(p[6])))))))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2427 || (p[0] == 'i'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2428 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2429 && (!ASCII_ISALPHA(p[2]) || (p[2] == 's'))))))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2430 skip_until = vim_strsave((char_u *)".");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2431
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2432 /* Check for ":python <<EOF", ":tcl <<EOF", etc. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2433 arg = skipwhite(skiptowhite(p));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2434 if (arg[0] == '<' && arg[1] =='<'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2435 && ((p[0] == 'p' && p[1] == 'y'
10722
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents: 10573
diff changeset
2436 && (!ASCII_ISALNUM(p[2]) || p[2] == 't'
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents: 10573
diff changeset
2437 || ((p[2] == '3' || p[2] == 'x')
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents: 10573
diff changeset
2438 && !ASCII_ISALPHA(p[3]))))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2439 || (p[0] == 'p' && p[1] == 'e'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2440 && (!ASCII_ISALPHA(p[2]) || p[2] == 'r'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2441 || (p[0] == 't' && p[1] == 'c'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2442 && (!ASCII_ISALPHA(p[2]) || p[2] == 'l'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2443 || (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
2444 && !ASCII_ISALPHA(p[3]))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2445 || (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
2446 && (!ASCII_ISALPHA(p[3]) || p[3] == 'y'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2447 || (p[0] == 'm' && p[1] == 'z'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2448 && (!ASCII_ISALPHA(p[2]) || p[2] == 's'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2449 ))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2451 /* ":python <<" continues until a dot, like ":append" */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452 p = skipwhite(arg + 2);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2453 if (*p == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2454 skip_until = vim_strsave((char_u *)".");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2455 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2456 skip_until = vim_strsave(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2457 }
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2458
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2459 // Check for ":let v =<< [trim] EOF"
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2460 arg = skipwhite(skiptowhite(p));
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2461 arg = skipwhite(skiptowhite(arg));
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2462 if (arg[0] == '=' && arg[1] == '<' && arg[2] =='<'
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2463 && ((p[0] == 'l'
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2464 && p[1] == 'e'
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2465 && (!ASCII_ISALNUM(p[2])
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2466 || (p[2] == 't' && !ASCII_ISALNUM(p[3]))))))
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2467 {
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2468 p = skipwhite(arg + 3);
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2469 if (STRNCMP(p, "trim", 4) == 0)
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2470 {
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2471 // Ignore leading white space.
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2472 p = skipwhite(p + 4);
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2473 heredoc_trimmed = vim_strnsave(theline,
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2474 (int)(skipwhite(theline) - theline));
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2475 }
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2476 skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2477 do_concat = FALSE;
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2478 is_heredoc = TRUE;
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2479 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2480 }
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 /* Add the line to the function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2483 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
2484 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2485
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2486 /* 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
2487 * 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
2488 * is an extra alloc/free. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2489 p = vim_strsave(theline);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2490 if (p == NULL)
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2491 goto erret;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2492 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
9562
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 /* 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
2495 * equal to the index in the growarray. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2496 while (sourcing_lnum_off-- > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2497 ((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
2498
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2499 /* Check for end of eap->arg. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2500 if (line_arg != NULL && *line_arg == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2501 line_arg = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2502 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2503
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2504 /* 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
2505 * detected. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2506 if (eap->skip || did_emsg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2507 goto erret;
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 * 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
2511 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2512 if (fudi.fd_dict == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2513 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2514 v = find_var(name, &ht, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2515 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
2516 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2517 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
2518 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2519 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2520 }
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 fp = find_func(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2523 if (fp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2524 {
15008
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2525 // Function can be replaced with "function!" and when sourcing the
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2526 // same script again, but only once.
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2527 if (!eap->forceit
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2528 && (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2529 || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2530 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2531 emsg_funcname(e_funcexts, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2532 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2533 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2534 if (fp->uf_calls > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2535 {
15008
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2536 emsg_funcname(
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2537 N_("E127: Cannot redefine function %s: It is in use"),
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2538 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2539 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2540 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2541 if (fp->uf_refcount > 1)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2542 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2543 /* 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
2544 * create a new one. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2545 --fp->uf_refcount;
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2546 fp->uf_flags |= FC_REMOVED;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2547 fp = NULL;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2548 overwrite = TRUE;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2549 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2550 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2551 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2552 /* redefine existing function */
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13096
diff changeset
2553 VIM_CLEAR(name);
14430
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2554 func_clear_items(fp);
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2555 #ifdef FEAT_PROFILE
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2556 fp->uf_profiling = FALSE;
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2557 fp->uf_prof_initialized = FALSE;
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2558 #endif
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2559 }
9562
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2562 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2563 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2564 char numbuf[20];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2565
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2566 fp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2567 if (fudi.fd_newkey == NULL && !eap->forceit)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2568 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2569 emsg(_(e_funcdict));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2570 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2571 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2572 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2573 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2574 /* Can't add a function to a locked dictionary */
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
2575 if (var_check_lock(fudi.fd_dict->dv_lock, eap->arg, FALSE))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2576 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2577 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2578 /* Can't change an existing function if it is locked */
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
2579 else if (var_check_lock(fudi.fd_di->di_tv.v_lock, eap->arg, FALSE))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2580 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2581
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2582 /* 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
2583 * Funcref! */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2584 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2585 sprintf(numbuf, "%d", ++func_nr);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2586 name = vim_strsave((char_u *)numbuf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2587 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2588 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2589 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2590
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2591 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2592 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2593 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
2594 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2595 int slen, plen;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2596 char_u *scriptname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2597
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2598 /* 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
2599 j = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2600 if (sourcing_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2601 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2602 scriptname = autoload_name(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2603 if (scriptname != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2604 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2605 p = vim_strchr(scriptname, '/');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2606 plen = (int)STRLEN(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2607 slen = (int)STRLEN(sourcing_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2608 if (slen > plen && fnamecmp(p,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2609 sourcing_name + slen - plen) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2610 j = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2611 vim_free(scriptname);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2612 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2613 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2614 if (j == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2615 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2616 semsg(_("E746: Function name does not match script file name: %s"), name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2617 goto erret;
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2620
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
2621 fp = alloc_clear(sizeof(ufunc_T) + STRLEN(name));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2622 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2623 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2624
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2625 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2626 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2627 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2628 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2629 /* add new dict entry */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2630 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
2631 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2632 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2633 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2634 goto erret;
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 (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
2637 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2638 vim_free(fudi.fd_di);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2639 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2640 goto erret;
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2643 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2644 /* overwrite existing dict entry */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2645 clear_tv(&fudi.fd_di->di_tv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2646 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
2647 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
2648
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2649 /* behave like "dict" was used */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2650 flags |= FC_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2651 }
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 /* 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
2654 STRCPY(fp->uf_name, name);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2655 if (overwrite)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2656 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2657 hi = hash_find(&func_hashtab, name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2658 hi->hi_key = UF2HIKEY(fp);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2659 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2660 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
2661 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2662 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2663 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2664 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2665 fp->uf_refcount = 1;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2666 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2667 fp->uf_args = newargs;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
2668 fp->uf_def_args = default_args;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2669 fp->uf_lines = newlines;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2670 if ((flags & FC_CLOSURE) != 0)
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2671 {
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2672 if (register_closure(fp) == FAIL)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2673 goto erret;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2674 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2675 else
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2676 fp->uf_scoped = NULL;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2677
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2678 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2679 if (prof_def_func())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2680 func_do_profile(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2681 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2682 fp->uf_varargs = varargs;
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
2683 if (sandbox)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
2684 flags |= FC_SANDBOX;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2685 fp->uf_flags = flags;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2686 fp->uf_calls = 0;
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
2687 fp->uf_script_ctx = current_sctx;
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2688 fp->uf_script_ctx.sc_lnum += sourcing_lnum_top;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2689 goto ret_free;
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 erret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2692 ga_clear_strings(&newargs);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
2693 ga_clear_strings(&default_args);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2694 errret_2:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2695 ga_clear_strings(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2696 ret_free:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2697 vim_free(skip_until);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2698 vim_free(line_to_free);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2699 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2700 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2701 did_emsg |= saved_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2702 need_wait_return |= saved_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2703 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2704
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 * 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
2707 * Return 2 if "p" starts with "s:".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2708 * Return 0 otherwise.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2709 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2710 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2711 eval_fname_script(char_u *p)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2712 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2713 /* 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
2714 * the standard library function. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2715 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
2716 || MB_STRNICMP(p + 1, "SNR>", 4) == 0))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2717 return 5;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2718 if (p[0] == 's' && p[1] == ':')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2719 return 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2720 return 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2721 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2722
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2723 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2724 translated_function_exists(char_u *name)
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 if (builtin_function(name, -1))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2727 return find_internal_func(name) >= 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2728 return find_func(name) != NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2729 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2730
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 * 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
2733 * 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
2734 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2735 int
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2736 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
2737 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2738 char_u *nm = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2739 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2740 int n = FALSE;
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2741 int flag;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2742
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2743 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
2744 if (no_deref)
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2745 flag |= TFN_NO_DEREF;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2746 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
2747 nm = skipwhite(nm);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2748
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2749 /* Only accept "funcname", "funcname ", "funcname (..." and
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2750 * "funcname(...", not "funcname!...". */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2751 if (p != NULL && (*nm == NUL || *nm == '('))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2752 n = translated_function_exists(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2753 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2754 return n;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2755 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2756
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
2757 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2758 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2759 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
2760 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2761 char_u *nm = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2762 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2763
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2764 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
2765
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2766 if (p != NULL && *nm == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2767 if (!check || translated_function_exists(p))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2768 return p;
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 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2771 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2772 }
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
2773 #endif
9562
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 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2776
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 * 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
2779 * function names.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2780 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2781 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2782 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
2783 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2784 static long_u done;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2785 static hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2786 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2787
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2788 if (idx == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2789 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2790 done = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2791 hi = func_hashtab.ht_array;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2792 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2793 if (done < func_hashtab.ht_used)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2794 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2795 if (done++ > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2796 ++hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2797 while (HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2798 ++hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2799 fp = HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2800
9638
af0d98d8836e commit https://github.com/vim/vim/commit/b49edc11a1872fa99befa9a4a8ea6c8537868038
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
2801 if ((fp->uf_flags & FC_DICT)
af0d98d8836e commit https://github.com/vim/vim/commit/b49edc11a1872fa99befa9a4a8ea6c8537868038
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
2802 || 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
2803 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
2804
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2805 if (STRLEN(fp->uf_name) + 4 >= IOSIZE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2806 return fp->uf_name; /* prevents overflow */
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 cat_func_name(IObuff, fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2809 if (xp->xp_context != EXPAND_USER_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2810 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2811 STRCAT(IObuff, "(");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2812 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
2813 STRCAT(IObuff, ")");
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 IObuff;
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 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2818 }
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 #endif /* FEAT_CMDL_COMPL */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2821
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2822 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2823 * ":delfunction {name}"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2824 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2825 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2826 ex_delfunction(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2827 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2828 ufunc_T *fp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2829 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2830 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2831 funcdict_T fudi;
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 p = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2834 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
2835 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2836 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2837 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2838 if (fudi.fd_dict != NULL && !eap->skip)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2839 emsg(_(e_funcref));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2840 return;
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 if (!ends_excmd(*skipwhite(p)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2843 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2844 vim_free(name);
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2845 emsg(_(e_trailing));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2846 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2847 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2848 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2849 if (eap->nextcmd != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2850 *p = NUL;
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 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2853 fp = find_func(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2854 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2855
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2856 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2857 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2858 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2859 {
11545
1780e6fecb30 patch 8.0.0655: not easy to make sure a function does not exist
Christian Brabandt <cb@256bit.org>
parents: 11543
diff changeset
2860 if (!eap->forceit)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2861 semsg(_(e_nofunc), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2862 return;
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 if (fp->uf_calls > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2865 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2866 semsg(_("E131: Cannot delete function %s: It is in use"), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2867 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2868 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2869
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2870 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2871 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2872 /* 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
2873 * 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
2874 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
2875 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2876 else
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2877 {
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2878 /* A normal function (not a numbered function or lambda) has a
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2879 * refcount of 1 for the entry in the hashtable. When deleting
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2880 * it and the refcount is more than one, it should be kept.
9951
d990a4394c9d commit https://github.com/vim/vim/commit/ba2099034f92a2814494f37bddb0c57d034401b4
Christian Brabandt <cb@256bit.org>
parents: 9844
diff changeset
2881 * A numbered function and lambda should be kept if the refcount is
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2882 * one or more. */
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2883 if (fp->uf_refcount > (func_name_refcount(fp->uf_name) ? 0 : 1))
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2884 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2885 /* 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
2886 * do remove it from the hashtable. */
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2887 if (func_remove(fp))
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2888 fp->uf_refcount--;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2889 fp->uf_flags |= FC_DELETED;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2890 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2891 else
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
2892 func_clear_free(fp, FALSE);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2893 }
9562
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2896
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 * 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
2899 * becomes zero.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2900 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2901 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2902 func_unref(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2903 {
9655
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2904 ufunc_T *fp = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2905
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2906 if (name == NULL || !func_name_refcount(name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2907 return;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2908 fp = find_func(name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2909 if (fp == NULL && isdigit(*name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2910 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2911 #ifdef EXITFREE
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2912 if (!entered_free_all_mem)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2913 #endif
10359
66f1b5bf3fa6 commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2914 internal_error("func_unref()");
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2915 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2916 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
2917 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2918 /* 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
2919 * when "uf_calls" becomes zero. */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2920 if (fp->uf_calls == 0)
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
2921 func_clear_free(fp, FALSE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2922 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2923 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2924
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2925 /*
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2926 * 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
2927 * becomes zero.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2928 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2929 void
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2930 func_ptr_unref(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2931 {
9655
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2932 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
2933 {
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2934 /* 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
2935 * when "uf_calls" becomes zero. */
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
2936 if (fp->uf_calls == 0)
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
2937 func_clear_free(fp, FALSE);
9562
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2940
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2941 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2942 * Count a reference to a Function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2943 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2944 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2945 func_ref(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2946 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2947 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2948
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2949 if (name == NULL || !func_name_refcount(name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2950 return;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2951 fp = find_func(name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2952 if (fp != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2953 ++fp->uf_refcount;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2954 else if (isdigit(*name))
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2955 /* 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
2956 * Fail silently, when named or lambda function isn't found. */
10359
66f1b5bf3fa6 commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2957 internal_error("func_ref()");
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2958 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2959
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2960 /*
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2961 * Count a reference to a Function.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2962 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2963 void
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2964 func_ptr_ref(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2965 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2966 if (fp != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2967 ++fp->uf_refcount;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2968 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2969
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 * 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
2972 * referenced from anywhere that is in use.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2973 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2974 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2975 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
2976 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2977 return (fc->l_varlist.lv_copyID != copyID
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2978 && 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
2979 && fc->l_avars.dv_copyID != copyID
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
2980 && fc->fc_copyID != copyID);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2981 }
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2984 * ":return [expr]"
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 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2987 ex_return(exarg_T *eap)
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 char_u *arg = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2990 typval_T rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2991 int returning = FALSE;
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 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2994 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2995 emsg(_("E133: :return not inside a function"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2996 return;
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 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3000 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3001
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3002 eap->nextcmd = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3003 if ((*arg != NUL && *arg != '|' && *arg != '\n')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3004 && 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
3005 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3006 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3007 returning = do_return(eap, FALSE, TRUE, &rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3008 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3009 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3010 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3011 /* 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
3012 else if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3013 {
13096
30f9a62f5f51 patch 8.0.1423: error in return not caught by try/catch
Christian Brabandt <cb@256bit.org>
parents: 13004
diff changeset
3014 /* In return statement, cause_abort should be force_abort. */
30f9a62f5f51 patch 8.0.1423: error in return not caught by try/catch
Christian Brabandt <cb@256bit.org>
parents: 13004
diff changeset
3015 update_force_abort();
30f9a62f5f51 patch 8.0.1423: error in return not caught by try/catch
Christian Brabandt <cb@256bit.org>
parents: 13004
diff changeset
3016
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3017 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3018 * 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
3019 * aborting error, an interrupt, or an exception.
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 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3022 returning = do_return(eap, FALSE, TRUE, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3023 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3024
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3025 /* 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
3026 * 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
3027 * 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
3028 if (returning)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3029 eap->nextcmd = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3030 else if (eap->nextcmd == NULL) /* no argument */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3031 eap->nextcmd = check_nextcmd(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3032
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3033 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3034 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3035 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3036
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 * ":1,25call func(arg1, arg2)" function call.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3039 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3040 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3041 ex_call(exarg_T *eap)
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 char_u *arg = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3044 char_u *startarg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3045 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3046 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3047 int len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3048 typval_T rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3049 linenr_T lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3050 int doesrange;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3051 int failed = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3052 funcdict_T fudi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3053 partial_T *partial = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3054
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3055 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3056 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3057 /* 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
3058 * 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
3059 * :if 0 | call dict.foo().bar() | endif */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3060 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3061 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
3062 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3063 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3064 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3065 }
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 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
3068 if (fudi.fd_newkey != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3069 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3070 /* Still need to give an error message for missing key. */
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3071 semsg(_(e_dictkey), fudi.fd_newkey);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3072 vim_free(fudi.fd_newkey);
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 if (tofree == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3075 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3076
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3077 /* 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
3078 * the arguments. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3079 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3080 ++fudi.fd_dict->dv_refcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3081
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3082 /* 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
3083 * 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
3084 * from trans_function_name(). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3085 len = (int)STRLEN(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3086 name = deref_func_name(tofree, &len,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3087 partial != NULL ? NULL : &partial, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3088
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3089 /* 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
3090 * backward compatibility. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3091 startarg = skipwhite(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3092 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
3093
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3094 if (*startarg != '(')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3095 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3096 semsg(_("E107: Missing parentheses: %s"), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3097 goto end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3098 }
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3101 * 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
3102 * arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3103 * 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
3104 * call, and the loop is broken.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3105 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3106 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3107 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3108 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3109 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
3110 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3111 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3112 lnum = eap->line1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3113 for ( ; lnum <= eap->line2; ++lnum)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3114 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3115 if (!eap->skip && eap->addr_count > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3116 {
15000
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3117 if (lnum > curbuf->b_ml.ml_line_count)
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3118 {
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3119 // If the function deleted lines or switched to another buffer
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3120 // the line number may become invalid.
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3121 emsg(_(e_invrange));
15000
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3122 break;
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3123 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3124 curwin->w_cursor.lnum = lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3125 curwin->w_cursor.col = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3126 curwin->w_cursor.coladd = 0;
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 arg = startarg;
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
3129 if (get_func_tv(name, -1, &rettv, &arg,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3130 eap->line1, eap->line2, &doesrange,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3131 !eap->skip, partial, fudi.fd_dict) == FAIL)
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 failed = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3134 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3135 }
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3136 if (has_watchexpr())
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3137 dbg_check_breakpoint(eap);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3138
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3139 /* 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
3140 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
3141 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3142 failed = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3143 break;
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3146 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3147 if (doesrange || eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3148 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3149
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3150 /* 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
3151 * 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
3152 * 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
3153 * characters below is executed. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3154 if (aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3155 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3156 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3157 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3158 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3159
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3160 if (!failed)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3161 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3162 /* 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
3163 if (!ends_excmd(*arg))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3164 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3165 emsg_severe = TRUE;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3166 emsg(_(e_trailing));
9562
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3169 eap->nextcmd = check_nextcmd(arg);
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3172 end:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3173 dict_unref(fudi.fd_dict);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3174 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3175 }
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 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
3179 * 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
3180 * 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
3181 * 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
3182 * 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
3183 * FALSE when the return gets pending.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3184 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3185 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3186 do_return(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3187 exarg_T *eap,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3188 int reanimate,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3189 int is_cmd,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3190 void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3191 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3192 int idx;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3193 struct condstack *cstack = eap->cstack;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3194
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3195 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3196 /* Undo the return. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3197 current_funccal->returned = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3198
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3199 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3200 * 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
3201 * 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
3202 * 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
3203 * Otherwise, return normally.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3204 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3205 idx = cleanup_conditionals(eap->cstack, 0, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3206 if (idx >= 0)
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 cstack->cs_pending[idx] = CSTP_RETURN;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3209
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3210 if (!is_cmd && !reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3211 /* 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
3212 * 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
3213 * argument if present or is NULL else. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3214 cstack->cs_rettv[idx] = rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3215 else
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 /* 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
3218 * return rettv. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3219 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3220 rettv = current_funccal->rettv;
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 if (rettv != NULL)
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 /* Store the value of the pending return. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3225 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
3226 *(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
3227 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3228 emsg(_(e_outofmem));
9562
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 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3231 cstack->cs_rettv[idx] = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3232
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3233 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3234 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3235 /* 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
3236 * 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
3237 * return value. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3238 current_funccal->rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3239 current_funccal->rettv->vval.v_number = 0;
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 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3242 report_make_pending(CSTP_RETURN, rettv);
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 else
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 current_funccal->returned = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3247
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3248 /* 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
3249 * 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
3250 * there. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3251 if (!reanimate && rettv != NULL)
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 clear_tv(current_funccal->rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3254 *current_funccal->rettv = *(typval_T *)rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3255 if (!is_cmd)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3256 vim_free(rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3257 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3258 }
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 return idx < 0;
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
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 * 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
3265 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3266 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3267 discard_pending_return(void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3268 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3269 free_tv((typval_T *)rettv);
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 * 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
3274 * 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
3275 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3276 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3277 get_return_cmd(void *rettv)
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 char_u *s = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3280 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3281 char_u numbuf[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3282
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3283 if (rettv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3284 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
3285 if (s == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3286 s = (char_u *)"";
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3287
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3288 STRCPY(IObuff, ":return ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3289 STRNCPY(IObuff + 8, s, IOSIZE - 8);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3290 if (STRLEN(s) + 8 >= IOSIZE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3291 STRCPY(IObuff + IOSIZE - 4, "...");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3292 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3293 return vim_strsave(IObuff);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3294 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3295
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3296 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3297 * Get next function line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3298 * 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
3299 * 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
3300 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3301 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3302 get_func_line(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3303 int c UNUSED,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3304 void *cookie,
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
3305 int indent UNUSED,
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
3306 int do_concat UNUSED)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3307 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3308 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3309 ufunc_T *fp = fcp->func;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3310 char_u *retval;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3311 garray_T *gap; /* growarray with function lines */
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 /* 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
3314 if (fcp->dbg_tick != debug_tick)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3315 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3316 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
3317 sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3318 fcp->dbg_tick = debug_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3319 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3320 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3321 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3322 func_line_end(cookie);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3323 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3324
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3325 gap = &fp->uf_lines;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3326 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
3327 || fcp->returned)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3328 retval = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3329 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3330 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3331 /* Skip NULL lines (continuation lines). */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3332 while (fcp->linenr < gap->ga_len
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3333 && ((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
3334 ++fcp->linenr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3335 if (fcp->linenr >= gap->ga_len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3336 retval = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3337 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3338 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3339 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
3340 sourcing_lnum = fcp->linenr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3341 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3342 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3343 func_line_start(cookie);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3344 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3345 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3346 }
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 /* Did we encounter a breakpoint? */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3349 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
3350 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3351 dbg_breakpoint(fp->uf_name, sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3352 /* Find next breakpoint. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3353 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
3354 sourcing_lnum);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3355 fcp->dbg_tick = debug_tick;
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 return retval;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3359 }
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 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3362 * 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
3363 * 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
3364 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3365 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3366 func_has_ended(void *cookie)
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 funccall_T *fcp = (funccall_T *)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 /* 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
3371 * an error inside a try conditional. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3372 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
3373 || fcp->returned);
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 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
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_has_abort(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3381 void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3382 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3383 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
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
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 * 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
3389 * 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
3390 * explicitly (pt_auto is FALSE).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3391 * Changes "rettv" in-place.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3392 * Returns the updated "selfdict_in".
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 dict_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3395 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
3396 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3397 char_u *fname;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3398 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3399 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3400 char_u fname_buf[FLEN_FIXED + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3401 int error;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3402 dict_T *selfdict = selfdict_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3403
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3404 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
3405 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
3406 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3407 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3408 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
3409 : rettv->vval.v_partial->pt_name;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3410 /* 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
3411 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
3412 fp = find_func(fname);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3413 vim_free(tofree);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3414 }
9562
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 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
3417 {
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3418 partial_T *pt = ALLOC_CLEAR_ONE(partial_T);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3419
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3420 if (pt != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3421 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3422 pt->pt_refcount = 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3423 pt->pt_dict = selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3424 pt->pt_auto = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3425 selfdict = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3426 if (rettv->v_type == VAR_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3427 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3428 /* 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
3429 * selfdict. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3430 pt->pt_name = rettv->vval.v_string;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3431 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3432 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3433 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3434 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
3435 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3436
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3437 /* 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
3438 * 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
3439 * be referenced elsewhere. */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3440 if (ret_pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3441 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3442 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
3443 func_ref(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3444 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3445 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3446 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3447 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
3448 func_ptr_ref(pt->pt_func);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3449 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3450 if (ret_pt->pt_argc > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3451 {
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3452 pt->pt_argv = ALLOC_MULT(typval_T, ret_pt->pt_argc);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3453 if (pt->pt_argv == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3454 /* out of memory: drop the arguments */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3455 pt->pt_argc = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3456 else
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 pt->pt_argc = ret_pt->pt_argc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3459 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
3460 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
3461 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3462 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3463 partial_unref(ret_pt);
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 rettv->v_type = VAR_PARTIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3466 rettv->vval.v_partial = pt;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3467 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3468 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3469 return selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3470 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3471
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3472 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3473 * Return the name of the executed function.
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 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3476 func_name(void *cookie)
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 return ((funccall_T *)cookie)->func->uf_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3479 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3480
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 * 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
3483 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3484 linenr_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3485 func_breakpoint(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3486 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3487 return &((funccall_T *)cookie)->breakpoint;
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 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
3492 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3493 int *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3494 func_dbg_tick(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3495 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3496 return &((funccall_T *)cookie)->dbg_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3497 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3498
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3499 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3500 * 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
3501 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3502 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3503 func_level(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3504 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3505 return ((funccall_T *)cookie)->level;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3506 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3507
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 * 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
3510 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3511 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3512 current_func_returned(void)
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 return current_funccal->returned;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3515 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3516
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3517 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3518 free_unref_funccal(int copyID, int testing)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3519 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3520 int did_free = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3521 int did_free_funccal = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3522 funccall_T *fc, **pfc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3523
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3524 for (pfc = &previous_funccal; *pfc != NULL; )
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 if (can_free_funccal(*pfc, copyID))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3527 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3528 fc = *pfc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3529 *pfc = fc->caller;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
3530 free_funccal_contents(fc);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3531 did_free = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3532 did_free_funccal = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3533 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3534 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3535 pfc = &(*pfc)->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3536 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3537 if (did_free_funccal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3538 /* 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
3539 * collected, so run again. */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3540 (void)garbage_collect(testing);
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 return did_free;
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 /*
9951
d990a4394c9d commit https://github.com/vim/vim/commit/ba2099034f92a2814494f37bddb0c57d034401b4
Christian Brabandt <cb@256bit.org>
parents: 9844
diff changeset
3546 * Get function call environment based on backtrace debug level
9562
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 static funccall_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3549 get_funccal(void)
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 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3552 funccall_T *funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3553 funccall_T *temp_funccal;
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 funccal = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3556 if (debug_backtrace_level > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3557 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3558 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
3559 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3560 temp_funccal = funccal->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3561 if (temp_funccal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3562 funccal = temp_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3563 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3564 /* backtrace level overflow. reset to max */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3565 debug_backtrace_level = i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3566 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3567 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3568 return funccal;
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
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3571 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3572 * 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
3573 * 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
3574 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3575 hashtab_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3576 get_funccal_local_ht()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3577 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3578 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3579 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3580 return &get_funccal()->l_vars.dv_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3581 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3582
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3583 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3584 * Return the l: scope variable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3585 * 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
3586 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3587 dictitem_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3588 get_funccal_local_var()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3589 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3590 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3591 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3592 return &get_funccal()->l_vars_var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3593 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3594
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3595 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3596 * 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
3597 * 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
3598 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3599 hashtab_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3600 get_funccal_args_ht()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3601 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3602 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3603 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3604 return &get_funccal()->l_avars.dv_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3605 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3606
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3607 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3608 * Return the a: scope variable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3609 * 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
3610 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3611 dictitem_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3612 get_funccal_args_var()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3613 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3614 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3615 return NULL;
10795
8afee415119d patch 8.0.0287: debug mode: cannot access function arguments
Christian Brabandt <cb@256bit.org>
parents: 10722
diff changeset
3616 return &get_funccal()->l_avars_var;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3617 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3618
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3619 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3620 * 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
3621 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3622 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3623 list_func_vars(int *first)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3624 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3625 if (current_funccal != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3626 list_hashtable_vars(&current_funccal->l_vars.dv_hashtab,
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3627 "l:", FALSE, first);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3628 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3629
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3630 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3631 * 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
3632 * the dict that contains it.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3633 * Otherwise return NULL.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3634 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3635 dict_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3636 get_current_funccal_dict(hashtab_T *ht)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3637 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3638 if (current_funccal != NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3639 && ht == &current_funccal->l_vars.dv_hashtab)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3640 return &current_funccal->l_vars;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3641 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3642 }
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 /*
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3645 * Search hashitem in parent scope.
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3646 */
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3647 hashitem_T *
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3648 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
3649 {
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3650 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
3651 hashtab_T *ht;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3652 hashitem_T *hi = NULL;
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3653 char_u *varname;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3654
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3655 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
3656 return NULL;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3657
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3658 /* 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
3659 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
3660 while (current_funccal != NULL)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3661 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3662 ht = find_var_ht(name, &varname);
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3663 if (ht != NULL && *varname != NUL)
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3664 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3665 hi = hash_find(ht, varname);
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3666 if (!HASHITEM_EMPTY(hi))
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3667 {
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3668 *pht = ht;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3669 break;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3670 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3671 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3672 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
3673 break;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3674 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
3675 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3676 current_funccal = old_current_funccal;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3677
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3678 return hi;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3679 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3680
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3681 /*
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3682 * Search variable in parent scope.
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3683 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3684 dictitem_T *
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3685 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
3686 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3687 dictitem_T *v = NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3688 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
3689 hashtab_T *ht;
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3690 char_u *varname;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3691
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3692 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
3693 return NULL;
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 /* 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
3696 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
3697 while (current_funccal)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3698 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3699 ht = find_var_ht(name, &varname);
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3700 if (ht != NULL && *varname != NUL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3701 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
3702 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
3703 if (v != NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3704 break;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3705 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3706 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
3707 break;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3708 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
3709 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3710 current_funccal = old_current_funccal;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3711
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3712 return v;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3713 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3714
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3715 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3716 * 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
3717 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3718 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3719 set_ref_in_previous_funccal(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3720 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3721 int abort = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3722 funccall_T *fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3723
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3724 for (fc = previous_funccal; !abort && fc != NULL; fc = fc->caller)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3725 {
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3726 fc->fc_copyID = copyID + 1;
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3727 abort = abort
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3728 || set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID + 1, NULL)
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3729 || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID + 1, NULL)
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3730 || set_ref_in_list_items(&fc->l_varlist, copyID + 1, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3731 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3732 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3733 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3734
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3735 static int
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3736 set_ref_in_funccal(funccall_T *fc, int copyID)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3737 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3738 int abort = FALSE;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3739
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3740 if (fc->fc_copyID != copyID)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3741 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3742 fc->fc_copyID = copyID;
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3743 abort = abort
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3744 || set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID, NULL)
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3745 || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID, NULL)
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3746 || set_ref_in_list_items(&fc->l_varlist, copyID, NULL)
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
3747 || set_ref_in_func(NULL, fc->func, copyID);
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3748 }
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3749 return abort;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3750 }
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3751
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3752 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3753 * 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
3754 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3755 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3756 set_ref_in_call_stack(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3757 {
16969
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
3758 int abort = FALSE;
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
3759 funccall_T *fc;
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
3760 funccal_entry_T *entry;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3761
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17127
diff changeset
3762 for (fc = current_funccal; !abort && fc != NULL; fc = fc->caller)
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3763 abort = abort || set_ref_in_funccal(fc, copyID);
16969
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
3764
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
3765 // Also go through the funccal_stack.
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17127
diff changeset
3766 for (entry = funccal_stack; !abort && entry != NULL; entry = entry->next)
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17127
diff changeset
3767 for (fc = entry->top_funccal; !abort && fc != NULL; fc = fc->caller)
16969
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
3768 abort = abort || set_ref_in_funccal(fc, copyID);
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
3769
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3770 return abort;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3771 }
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3772
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3773 /*
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3774 * Set "copyID" in all functions available by name.
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3775 */
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3776 int
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3777 set_ref_in_functions(int copyID)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3778 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3779 int todo;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3780 hashitem_T *hi = NULL;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3781 int abort = FALSE;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3782 ufunc_T *fp;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3783
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3784 todo = (int)func_hashtab.ht_used;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3785 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3786 {
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3787 if (!HASHITEM_EMPTY(hi))
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3788 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3789 --todo;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3790 fp = HI2UF(hi);
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3791 if (!func_name_refcount(fp->uf_name))
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3792 abort = abort || set_ref_in_func(NULL, fp, copyID);
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3793 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3794 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3795 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3796 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3797
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3798 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3799 * Set "copyID" in all function arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3800 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3801 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3802 set_ref_in_func_args(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3803 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3804 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3805 int abort = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3806
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3807 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
3808 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
3809 copyID, NULL, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3810 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3811 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3812
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3813 /*
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3814 * 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
3815 * 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
3816 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3817 int
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3818 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
3819 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3820 ufunc_T *fp = fp_in;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3821 funccall_T *fc;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3822 int error = ERROR_NONE;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3823 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
3824 char_u *tofree = NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3825 char_u *fname;
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3826 int abort = FALSE;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3827
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3828 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
3829 return FALSE;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3830
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3831 if (fp_in == NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3832 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3833 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
3834 fp = find_func(fname);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3835 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3836 if (fp != NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3837 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3838 for (fc = fp->uf_scoped; fc != NULL; fc = fc->func->uf_scoped)
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3839 abort = abort || set_ref_in_funccal(fc, copyID);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3840 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3841 vim_free(tofree);
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
3842 return abort;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3843 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3844
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3845 #endif /* FEAT_EVAL */