Mercurial > vim
annotate src/vim9compile.c @ 35462:24fbfda19203
Added tag v9.1.0500 for changeset 5301104f466a2379d132dd8029b8a6d6eabd7df4
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 18 Jun 2024 21:15:04 +0200 |
parents | 2e492a1539e0 |
children | 0e8dbbe586c3 |
rev | line source |
---|---|
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
8 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
9 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
10 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
11 * vim9compile.c: compiling a :def function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
12 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
13 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
14 #define USING_FLOAT_STUFF |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
15 #include "vim.h" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
16 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
17 #if defined(FEAT_EVAL) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
18 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
19 // When not generating protos this is included in proto.h |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
20 #ifdef PROTO |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
21 # include "vim9.h" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
22 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
23 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
24 // Functions defined with :def are stored in this growarray. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
25 // They are never removed, so that they can be found by index. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
26 // Deleted functions have the df_deleted flag set. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
27 garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL}; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
28 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
29 static void delete_def_function_contents(dfunc_T *dfunc, int mark_deleted); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
30 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
31 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
32 * Lookup variable "name" in the local scope and return it in "lvar". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
33 * "lvar->lv_from_outer" is incremented accordingly. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
34 * If "lvar" is NULL only check if the variable can be found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
35 * Return FAIL if not found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
36 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
37 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
38 lookup_local(char_u *name, size_t len, lvar_T *lvar, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
39 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
40 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
41 lvar_T *lvp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
42 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
43 if (len == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
44 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
45 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
46 if (((len == 4 && STRNCMP(name, "this", 4) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
47 || (len == 5 && STRNCMP(name, "super", 5) == 0)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
48 && cctx->ctx_ufunc != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
49 && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
50 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
51 int is_super = *name == 's'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
52 if (is_super) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
53 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
54 if (name[5] != '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
55 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
56 emsg(_(e_super_must_be_followed_by_dot)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
57 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
58 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
59 if (cctx->ctx_ufunc->uf_class != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
60 && cctx->ctx_ufunc->uf_class->class_extends == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
61 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
62 emsg(_(e_using_super_not_in_child_class)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
63 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
64 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
65 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
66 if (lvar != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
67 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
68 CLEAR_POINTER(lvar); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
69 lvar->lv_loop_depth = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
70 lvar->lv_name = (char_u *)(is_super ? "super" : "this"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
71 if (cctx->ctx_ufunc->uf_class != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
72 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
73 lvar->lv_type = &cctx->ctx_ufunc->uf_class->class_object_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
74 if (is_super) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
75 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
76 type_T *type = get_type_ptr(cctx->ctx_type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
77 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
78 if (type != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
79 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
80 *type = *lvar->lv_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
81 lvar->lv_type = type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
82 type->tt_flags |= TTFLAG_SUPER; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
83 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
84 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
85 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
86 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
87 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
88 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
89 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
90 // Find local in current function scope. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
91 for (idx = 0; idx < cctx->ctx_locals.ga_len; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
92 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
93 lvp = ((lvar_T *)cctx->ctx_locals.ga_data) + idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
94 if (lvp->lv_name != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
95 && STRNCMP(name, lvp->lv_name, len) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
96 && STRLEN(lvp->lv_name) == len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
97 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
98 if (lvar != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
99 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
100 *lvar = *lvp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
101 lvar->lv_from_outer = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
102 // If the variable was declared inside a loop set |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
103 // lvar->lv_loop_idx and lvar->lv_loop_depth. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
104 get_loop_var_idx(cctx, idx, lvar); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
105 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
106 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
107 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
108 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
109 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
110 // Find local in outer function scope. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
111 if (cctx->ctx_outer != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
112 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
113 if (lookup_local(name, len, lvar, cctx->ctx_outer) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
114 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
115 if (lvar != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
116 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
117 cctx->ctx_outer_used = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
118 ++lvar->lv_from_outer; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
119 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
120 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
121 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
122 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
123 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
124 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
125 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
126 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
127 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
128 * Lookup an argument in the current function and an enclosing function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
129 * Returns the argument index in "idxp" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
130 * Returns the argument type in "type" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
131 * Sets "gen_load_outer" to TRUE if found in outer scope. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
132 * Returns OK when found, FAIL otherwise. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
133 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
134 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
135 arg_exists( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
136 char_u *name, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
137 size_t len, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
138 int *idxp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
139 type_T **type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
140 int *gen_load_outer, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
141 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
142 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
143 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
144 char_u *va_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
145 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
146 if (len == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
147 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
148 for (idx = 0; idx < cctx->ctx_ufunc->uf_args_visible; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
149 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
150 char_u *arg = FUNCARG(cctx->ctx_ufunc, idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
151 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
152 if (STRNCMP(name, arg, len) == 0 && arg[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
153 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
154 if (idxp != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
155 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
156 // Arguments are located above the frame pointer. One further |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
157 // if there is a vararg argument |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
158 *idxp = idx - (cctx->ctx_ufunc->uf_args.ga_len |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
159 + STACK_FRAME_SIZE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
160 + (cctx->ctx_ufunc->uf_va_name != NULL ? -1 : 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
161 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
162 if (cctx->ctx_ufunc->uf_arg_types != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
163 *type = cctx->ctx_ufunc->uf_arg_types[idx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
164 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
165 *type = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
166 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
167 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
168 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
169 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
170 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
171 va_name = cctx->ctx_ufunc->uf_va_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
172 if (va_name != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
173 && STRNCMP(name, va_name, len) == 0 && va_name[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
174 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
175 if (idxp != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
176 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
177 // varargs is always the last argument |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
178 *idxp = -STACK_FRAME_SIZE - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
179 *type = cctx->ctx_ufunc->uf_va_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
180 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
181 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
182 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
183 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
184 if (cctx->ctx_outer != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
185 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
186 // Lookup the name for an argument of the outer function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
187 if (arg_exists(name, len, idxp, type, gen_load_outer, cctx->ctx_outer) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
188 == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
189 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
190 if (gen_load_outer != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
191 ++*gen_load_outer; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
192 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
193 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
194 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
195 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
196 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
197 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
198 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
199 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
200 * Lookup a script-local variable in the current script, possibly defined in a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
201 * block that contains the function "cctx->ctx_ufunc". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
202 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
203 * If "len" is <= 0 "name" must be NUL terminated. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
204 * Return NULL when not found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
205 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
206 static sallvar_T * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
207 find_script_var(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
208 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
209 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
210 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
211 int cc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
212 sallvar_T *sav; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
213 ufunc_T *ufunc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
214 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
215 // Find the list of all script variables with the right name. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
216 if (len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
217 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
218 cc = name[len]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
219 name[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
220 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
221 hi = hash_find(&si->sn_all_vars.dv_hashtab, name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
222 if (len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
223 name[len] = cc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
224 if (HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
225 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
226 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
227 sav = HI2SAV(hi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
228 if (sav->sav_block_id == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
229 // variable defined in the top script scope is always visible |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
230 return sav; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
231 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
232 if (cctx == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
233 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
234 if (cstack == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
235 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
236 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
237 // Not in a function scope, find variable with block ID equal to or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
238 // smaller than the current block id. Use "cstack" to go up the block |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
239 // scopes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
240 while (sav != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
241 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
242 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
243 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
244 for (idx = cstack->cs_idx; idx >= 0; --idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
245 if (cstack->cs_block_id[idx] == sav->sav_block_id) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
246 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
247 if (idx >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
248 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
249 sav = sav->sav_next; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
250 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
251 return sav; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
252 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
253 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
254 // Go over the variables with this name and find one that was visible |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
255 // from the function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
256 ufunc = cctx->ctx_ufunc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
257 while (sav != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
258 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
259 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
260 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
261 // Go over the blocks that this function was defined in. If the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
262 // variable block ID matches it was visible to the function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
263 for (idx = 0; idx < ufunc->uf_block_depth; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
264 if (ufunc->uf_block_ids[idx] == sav->sav_block_id) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
265 return sav; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
266 sav = sav->sav_next; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
267 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
268 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
269 // Not found, variable was not visible. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
270 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
271 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
272 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
273 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
274 * If "name" can be found in the current script set it's "block_id". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
275 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
276 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
277 update_script_var_block_id(char_u *name, int block_id) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
278 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
279 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
280 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
281 sallvar_T *sav; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
282 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
283 hi = hash_find(&si->sn_all_vars.dv_hashtab, name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
284 if (HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
285 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
286 sav = HI2SAV(hi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
287 sav->sav_block_id = block_id; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
288 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
289 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
290 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
291 * Return TRUE if the script context is Vim9 script. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
292 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
293 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
294 script_is_vim9(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
295 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
296 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
297 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
298 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
299 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
300 * Lookup a variable (without s: prefix) in the current script. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
301 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
302 * Returns OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
303 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
304 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
305 script_var_exists(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
306 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
307 if (current_sctx.sc_sid <= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
308 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
309 if (script_is_vim9()) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
310 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
311 // Check script variables that were visible where the function was |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
312 // defined. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
313 if (find_script_var(name, len, cctx, cstack) != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
314 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
315 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
316 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
317 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
318 hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
319 dictitem_T *di; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
320 int cc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
321 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
322 // Check script variables that are currently visible |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
323 cc = name[len]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
324 name[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
325 di = find_var_in_ht(ht, 0, name, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
326 name[len] = cc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
327 if (di != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
328 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
329 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
330 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
331 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
332 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
333 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
334 /* |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
335 * Returns the index of a class method or class variable with name "name" |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
336 * accessible in the currently compiled function. |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
337 * If "cl_ret" is not NULL set it to the class. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
338 * Otherwise return -1. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
339 */ |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
340 static int |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
341 cctx_class_midx( |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
342 cctx_T *cctx, |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
343 int is_method, |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
344 char_u *name, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
345 size_t len, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
346 class_T **cl_ret) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
347 { |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
348 if (cctx == NULL || cctx->ctx_ufunc == NULL |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
349 || cctx->ctx_ufunc->uf_class == NULL |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
350 || cctx->ctx_ufunc->uf_defclass == NULL) |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
351 return -1; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
352 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
353 // Search for the class method or variable in the class where the calling |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
354 // function is defined. |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
355 class_T *cl = cctx->ctx_ufunc->uf_defclass; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
356 int m_idx = is_method ? class_method_idx(cl, name, len) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
357 : class_member_idx(cl, name, len); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
358 if (m_idx < 0) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
359 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
360 cl = cl->class_extends; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
361 while (cl != NULL) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
362 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
363 m_idx = is_method ? class_method_idx(cl, name, len) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
364 : class_member_idx(cl, name, len); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
365 if (m_idx >= 0) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
366 break; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
367 cl = cl->class_extends; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
368 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
369 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
370 |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
371 if (m_idx >= 0) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
372 { |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
373 if (cl_ret != NULL) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
374 *cl_ret = cl; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
375 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
376 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
377 return m_idx; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
378 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
379 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
380 /* |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
381 * Returns the index of a class method with name "name" accessible in the |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
382 * currently compiled function. Returns -1 if not found. The class where the |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
383 * method is defined is returned in "cl_ret". |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
384 */ |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
385 int |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
386 cctx_class_method_idx( |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
387 cctx_T *cctx, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
388 char_u *name, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
389 size_t len, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
390 class_T **cl_ret) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
391 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
392 return cctx_class_midx(cctx, TRUE, name, len, cl_ret); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
393 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
394 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
395 /* |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
396 * Returns the index of a class variable with name "name" accessible in the |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
397 * currently compiled function. Returns -1 if not found. The class where the |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
398 * variable is defined is returned in "cl_ret". |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
399 */ |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
400 int |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
401 cctx_class_member_idx( |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
402 cctx_T *cctx, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
403 char_u *name, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
404 size_t len, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
405 class_T **cl_ret) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
406 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
407 return cctx_class_midx(cctx, FALSE, name, len, cl_ret); |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
408 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
409 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
410 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
411 * Return TRUE if "name" is a local variable, argument, script variable or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
412 * imported. Also if "name" is "this" and in a class method. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
413 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
414 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
415 variable_exists(char_u *name, size_t len, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
416 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
417 return (cctx != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
418 && (lookup_local(name, len, NULL, cctx) == OK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
419 || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
420 || (len == 4 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
421 && cctx->ctx_ufunc != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
422 && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
423 && STRNCMP(name, "this", 4) == 0))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
424 || script_var_exists(name, len, cctx, NULL) == OK |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
425 || cctx_class_member_idx(cctx, name, len, NULL) >= 0 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
426 || find_imported(name, len, FALSE) != NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
427 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
428 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
429 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
430 * Return TRUE if "name" is a local variable, argument, script variable, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
431 * imported or function. Or commands are being skipped, a declaration may have |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
432 * been skipped then. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
433 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
434 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
435 item_exists(char_u *name, size_t len, int cmd UNUSED, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
436 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
437 return variable_exists(name, len, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
438 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
439 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
440 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
441 * Check if "p[len]" is already defined, either in script "import_sid" or in |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
442 * compilation context "cctx". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
443 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
444 * Does not check the global namespace. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
445 * If "is_arg" is TRUE the error message is for an argument name. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
446 * Return FAIL and give an error if it defined. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
447 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
448 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
449 check_defined( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
450 char_u *p, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
451 size_t len, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
452 cctx_T *cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
453 cstack_T *cstack, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
454 int is_arg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
455 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
456 int c = p[len]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
457 ufunc_T *ufunc = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
458 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
459 // underscore argument is OK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
460 if (len == 1 && *p == '_') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
461 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
462 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
463 if (script_var_exists(p, len, cctx, cstack) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
464 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
465 if (is_arg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
466 semsg(_(e_argument_already_declared_in_script_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
467 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
468 semsg(_(e_variable_already_declared_in_script_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
469 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
470 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
471 |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
472 if (cctx_class_member_idx(cctx, p, len, NULL) >= 0) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
473 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
474 if (is_arg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
475 semsg(_(e_argument_already_declared_in_class_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
476 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
477 semsg(_(e_variable_already_declared_in_class_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
478 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
479 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
480 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
481 p[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
482 if ((cctx != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
483 && (lookup_local(p, len, NULL, cctx) == OK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
484 || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
485 || find_imported(p, len, FALSE) != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
486 || (ufunc = find_func_even_dead(p, 0)) != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
487 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
488 // A local or script-local function can shadow a global function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
489 if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
490 && (!func_is_global(ufunc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
491 || (p[0] == 'g' && p[1] == ':')))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
492 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
493 if (is_arg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
494 semsg(_(e_argument_name_shadows_existing_variable_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
495 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
496 semsg(_(e_name_already_defined_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
497 p[len] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
498 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
499 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
500 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
501 p[len] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
502 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
503 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
504 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
505 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
506 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
507 * Return TRUE if "actual" could be "expected" and a runtime typecheck is to be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
508 * used. Return FALSE if the types will never match. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
509 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
510 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
511 use_typecheck(type_T *actual, type_T *expected) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
512 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
513 if (actual->tt_type == VAR_ANY |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
514 || actual->tt_type == VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
515 || (actual->tt_type == VAR_FUNC |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
516 && (expected->tt_type == VAR_FUNC |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
517 || expected->tt_type == VAR_PARTIAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
518 && (actual->tt_member == &t_any |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
519 || actual->tt_member == &t_unknown |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
520 || actual->tt_argcount < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
521 && (actual->tt_member == &t_unknown || |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
522 (actual->tt_member == &t_void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
523 == (expected->tt_member == &t_void)))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
524 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
525 if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
526 && actual->tt_type == expected->tt_type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
527 // This takes care of a nested list or dict. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
528 return use_typecheck(actual->tt_member, expected->tt_member); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
529 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
530 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
531 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
532 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
533 * Check that |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
534 * - "actual" matches "expected" type or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
535 * - "actual" is a type that can be "expected" type: add a runtime check; or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
536 * - return FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
537 * If "actual_is_const" is TRUE then the type won't change at runtime, do not |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
538 * generate a TYPECHECK. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
539 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
540 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
541 need_type_where( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
542 type_T *actual, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
543 type_T *expected, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
544 int number_ok, // expect VAR_FLOAT but VAR_NUMBER is OK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
545 int offset, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
546 where_T where, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
547 cctx_T *cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
548 int silent, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
549 int actual_is_const) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
550 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
551 int ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
552 |
34006
ab6a70fad5b5
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
553 if (expected->tt_type != VAR_CLASS && expected->tt_type != VAR_TYPEALIAS) |
ab6a70fad5b5
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
554 { |
ab6a70fad5b5
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
555 if (check_type_is_value(actual) == FAIL) |
ab6a70fad5b5
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
556 return FAIL; |
ab6a70fad5b5
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
557 } |
ab6a70fad5b5
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
558 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
559 if (expected == &t_bool && actual != &t_bool |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
560 && (actual->tt_flags & TTFLAG_BOOL_OK)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
561 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
562 // Using "0", "1" or the result of an expression with "&&" or "||" as a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
563 // boolean is OK but requires a conversion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
564 generate_2BOOL(cctx, FALSE, offset); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
565 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
566 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
567 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
568 ret = check_type_maybe(expected, actual, FALSE, where); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
569 if (ret == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
570 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
571 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
572 // If actual a constant a runtime check makes no sense. If it's |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
573 // null_function it is OK. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
574 if (actual_is_const && ret == MAYBE && actual == &t_func_unknown) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
575 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
576 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
577 // If the actual type can be the expected type add a runtime check. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
578 if (!actual_is_const && ret == MAYBE && use_typecheck(actual, expected)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
579 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
580 generate_TYPECHECK(cctx, expected, number_ok, offset, |
32863
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
581 where.wt_kind == WT_VARIABLE, where.wt_index); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
582 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
583 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
584 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
585 if (!silent) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
586 type_mismatch_where(expected, actual, where); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
587 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
588 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
589 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
590 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
591 need_type( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
592 type_T *actual, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
593 type_T *expected, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
594 int number_ok, // when expected is float number is also OK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
595 int offset, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
596 int arg_idx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
597 cctx_T *cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
598 int silent, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
599 int actual_is_const) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
600 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
601 where_T where = WHERE_INIT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
602 |
32863
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
603 if (arg_idx > 0) |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
604 { |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
605 where.wt_index = arg_idx; |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
606 where.wt_kind = WT_ARGUMENT; |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
607 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
608 return need_type_where(actual, expected, number_ok, offset, where, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
609 cctx, silent, actual_is_const); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
610 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
611 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
612 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
613 * Set type of variable "lvar" to "type". If the variable is a constant then |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
614 * the type gets TTFLAG_CONST. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
615 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
616 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
617 set_var_type(lvar_T *lvar, type_T *type_arg, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
618 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
619 type_T *type = type_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
620 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
621 if (lvar->lv_const == ASSIGN_CONST && (type->tt_flags & TTFLAG_CONST) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
622 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
623 if (type->tt_flags & TTFLAG_STATIC) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
624 // entry in static_types[] is followed by const type |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
625 type = type + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
626 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
627 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
628 type = copy_type(type, cctx->ctx_type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
629 type->tt_flags |= TTFLAG_CONST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
630 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
631 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
632 lvar->lv_type = type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
633 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
634 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
635 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
636 * Reserve space for a local variable. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
637 * "assign" can be ASSIGN_VAR for :var, ASSIGN_CONST for :const and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
638 * ASSIGN_FINAL for :final. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
639 * Return the variable or NULL if it failed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
640 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
641 lvar_T * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
642 reserve_local( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
643 cctx_T *cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
644 char_u *name, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
645 size_t len, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
646 int assign, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
647 type_T *type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
648 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
649 lvar_T *lvar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
650 dfunc_T *dfunc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
651 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
652 if (arg_exists(name, len, NULL, NULL, NULL, cctx) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
653 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
654 emsg_namelen(_(e_str_is_used_as_argument), name, (int)len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
655 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
656 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
657 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
658 if (GA_GROW_FAILS(&cctx->ctx_locals, 1)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
659 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
660 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
661 CLEAR_POINTER(lvar); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
662 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
663 // Every local variable uses the next entry on the stack. We could re-use |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
664 // the last ones when leaving a scope, but then variables used in a closure |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
665 // might get overwritten. To keep things simple do not re-use stack |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
666 // entries. This is less efficient, but memory is cheap these days. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
667 dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
668 lvar->lv_idx = dfunc->df_var_names.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
669 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
670 lvar->lv_name = vim_strnsave(name, len == 0 ? STRLEN(name) : len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
671 lvar->lv_const = assign; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
672 if (type == &t_unknown || type == &t_any) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
673 // type not known yet, may be inferred from RHS |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
674 lvar->lv_type = type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
675 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
676 // may use TTFLAG_CONST |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
677 set_var_type(lvar, type, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
678 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
679 // Remember the name for debugging. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
680 if (GA_GROW_FAILS(&dfunc->df_var_names, 1)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
681 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
682 ((char_u **)dfunc->df_var_names.ga_data)[lvar->lv_idx] = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
683 vim_strsave(lvar->lv_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
684 ++dfunc->df_var_names.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
685 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
686 return lvar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
687 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
688 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
689 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
690 * If "check_writable" is ASSIGN_CONST give an error if the variable was |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
691 * defined with :final or :const, if "check_writable" is ASSIGN_FINAL give an |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
692 * error if the variable was defined with :const. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
693 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
694 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
695 check_item_writable(svar_T *sv, int check_writable, char_u *name) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
696 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
697 if ((check_writable == ASSIGN_CONST && sv->sv_const != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
698 || (check_writable == ASSIGN_FINAL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
699 && sv->sv_const == ASSIGN_CONST)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
700 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
701 semsg(_(e_cannot_change_readonly_variable_str), name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
702 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
703 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
704 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
705 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
706 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
707 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
708 * Find "name" in script-local items of script "sid". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
709 * Pass "check_writable" to check_item_writable(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
710 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
711 * Returns the index in "sn_var_vals" if found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
712 * If found but not in "sn_var_vals" returns -1. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
713 * If not found or the variable is not writable returns -2. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
714 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
715 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
716 get_script_item_idx( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
717 int sid, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
718 char_u *name, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
719 int check_writable, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
720 cctx_T *cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
721 cstack_T *cstack) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
722 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
723 hashtab_T *ht; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
724 dictitem_T *di; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
725 scriptitem_T *si = SCRIPT_ITEM(sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
726 svar_T *sv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
727 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
728 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
729 if (!SCRIPT_ID_VALID(sid)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
730 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
731 if (sid == current_sctx.sc_sid) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
732 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
733 sallvar_T *sav = find_script_var(name, 0, cctx, cstack); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
734 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
735 if (sav == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
736 return -2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
737 idx = sav->sav_var_vals_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
738 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
739 if (check_item_writable(sv, check_writable, name) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
740 return -2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
741 return idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
742 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
743 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
744 // First look the name up in the hashtable. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
745 ht = &SCRIPT_VARS(sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
746 di = find_var_in_ht(ht, 0, name, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
747 if (di == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
748 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
749 if (si->sn_autoload_prefix != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
750 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
751 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
752 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
753 // A variable exported from an autoload script is in the global |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
754 // variables, we can find it in the all_vars table. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
755 hi = hash_find(&si->sn_all_vars.dv_hashtab, name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
756 if (!HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
757 return HI2SAV(hi)->sav_var_vals_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
758 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
759 return -2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
760 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
761 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
762 // Now find the svar_T index in sn_var_vals. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
763 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
764 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
765 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
766 if (sv->sv_tv == &di->di_tv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
767 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
768 if (check_item_writable(sv, check_writable, name) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
769 return -2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
770 return idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
771 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
772 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
773 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
774 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
775 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
776 static imported_T * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
777 find_imported_in_script(char_u *name, size_t len, int sid) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
778 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
779 scriptitem_T *si; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
780 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
781 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
782 if (!SCRIPT_ID_VALID(sid)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
783 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
784 si = SCRIPT_ITEM(sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
785 for (idx = 0; idx < si->sn_imports.ga_len; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
786 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
787 imported_T *import = ((imported_T *)si->sn_imports.ga_data) + idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
788 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
789 if (len == 0 ? STRCMP(name, import->imp_name) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
790 : STRLEN(import->imp_name) == len |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
791 && STRNCMP(name, import->imp_name, len) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
792 return import; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
793 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
794 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
795 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
796 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
797 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
798 * Find "name" in imported items of the current script. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
799 * If "len" is 0 use any length that works. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
800 * If "load" is TRUE and the script was not loaded yet, load it now. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
801 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
802 imported_T * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
803 find_imported(char_u *name, size_t len, int load) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
804 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
805 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
806 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
807 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
808 // Skip over "s:" before "s:something" to find the import name. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
809 int off = name[0] == 's' && name[1] == ':' ? 2 : 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
810 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
811 imported_T *ret = find_imported_in_script(name + off, len - off, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
812 current_sctx.sc_sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
813 if (ret != NULL && load && (ret->imp_flags & IMP_FLAGS_AUTOLOAD)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
814 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
815 scid_T actual_sid = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
816 int save_emsg_off = emsg_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
817 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
818 // "emsg_off" will be set when evaluating an expression silently, but |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
819 // we do want to know about errors in a script. Also because it then |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
820 // aborts when an error is encountered. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
821 emsg_off = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
822 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
823 // script found before but not loaded yet |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
824 ret->imp_flags &= ~IMP_FLAGS_AUTOLOAD; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
825 (void)do_source(SCRIPT_ITEM(ret->imp_sid)->sn_name, FALSE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
826 DOSO_NONE, &actual_sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
827 // If the script is a symlink it may be sourced with another name, may |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
828 // need to adjust the script ID for that. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
829 if (actual_sid != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
830 ret->imp_sid = actual_sid; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
831 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
832 emsg_off = save_emsg_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
833 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
834 return ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
835 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
836 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
837 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
838 * Called when checking for a following operator at "arg". When the rest of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
839 * the line is empty or only a comment, peek the next line. If there is a next |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
840 * line return a pointer to it and set "nextp". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
841 * Otherwise skip over white space. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
842 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
843 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
844 may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
845 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
846 char_u *p = skipwhite(arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
847 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
848 *nextp = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
849 if (*p == NUL || (VIM_ISWHITE(*arg) && vim9_comment_start(p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
850 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
851 *nextp = peek_next_line_from_context(cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
852 if (*nextp != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
853 return *nextp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
854 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
855 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
856 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
857 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
858 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
859 * Return a pointer to the next line that isn't empty or only contains a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
860 * comment. Skips over white space. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
861 * Returns NULL if there is none. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
862 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
863 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
864 peek_next_line_from_context(cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
865 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
866 int lnum = cctx->ctx_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
867 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
868 while (++lnum < cctx->ctx_ufunc->uf_lines.ga_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
869 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
870 char_u *line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[lnum]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
871 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
872 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
873 // ignore NULLs inserted for continuation lines |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
874 if (line != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
875 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
876 p = skipwhite(line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
877 if (vim9_bad_comment(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
878 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
879 if (*p != NUL && !vim9_comment_start(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
880 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
881 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
882 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
883 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
884 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
885 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
886 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
887 * Get the next line of the function from "cctx". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
888 * Skips over empty lines. Skips over comment lines if "skip_comment" is TRUE. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
889 * Returns NULL when at the end. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
890 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
891 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
892 next_line_from_context(cctx_T *cctx, int skip_comment) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
893 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
894 char_u *line; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
895 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
896 do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
897 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
898 ++cctx->ctx_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
899 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
900 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
901 line = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
902 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
903 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
904 line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
905 cctx->ctx_line_start = line; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
906 SOURCING_LNUM = cctx->ctx_lnum + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
907 } while (line == NULL || *skipwhite(line) == NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
908 || (skip_comment && vim9_comment_start(skipwhite(line)))); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
909 return line; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
910 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
911 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
912 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
913 * Skip over white space at "whitep" and assign to "*arg". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
914 * If "*arg" is at the end of the line, advance to the next line. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
915 * Also when "whitep" points to white space and "*arg" is on a "#". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
916 * Return FAIL if beyond the last line, "*arg" is unmodified then. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
917 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
918 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
919 may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
920 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
921 *arg = skipwhite(whitep); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
922 if (vim9_bad_comment(*arg)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
923 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
924 if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
925 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
926 char_u *next = next_line_from_context(cctx, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
927 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
928 if (next == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
929 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
930 *arg = skipwhite(next); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
931 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
932 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
933 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
934 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
935 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
936 * Idem, and give an error when failed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
937 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
938 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
939 may_get_next_line_error(char_u *whitep, char_u **arg, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
940 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
941 if (may_get_next_line(whitep, arg, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
942 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
943 SOURCING_LNUM = cctx->ctx_lnum + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
944 emsg(_(e_line_incomplete)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
945 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
946 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
947 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
948 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
949 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
950 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
951 * Get a line from the compilation context, compatible with exarg_T getline(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
952 * Return a pointer to the line in allocated memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
953 * Return NULL for end-of-file or some error. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
954 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
955 static char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
956 exarg_getline( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
957 int c UNUSED, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
958 void *cookie, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
959 int indent UNUSED, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
960 getline_opt_T options UNUSED) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
961 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
962 cctx_T *cctx = (cctx_T *)cookie; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
963 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
964 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
965 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
966 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
967 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len - 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
968 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
969 ++cctx->ctx_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
970 p = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
971 // Comment lines result in NULL pointers, skip them. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
972 if (p != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
973 return vim_strsave(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
974 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
975 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
976 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
977 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
978 fill_exarg_from_cctx(exarg_T *eap, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
979 { |
33988
7c30841c60a0
patch 9.0.2180: POSIX function name in exarg causes issues
Christian Brabandt <cb@256bit.org>
parents:
33951
diff
changeset
|
980 eap->ea_getline = exarg_getline; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
981 eap->cookie = cctx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
982 eap->skip = cctx->ctx_skip == SKIP_YES; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
983 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
984 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
985 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
986 * Return TRUE if "ufunc" should be compiled, taking into account whether |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
987 * "profile" indicates profiling is to be done. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
988 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
989 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
990 func_needs_compiling(ufunc_T *ufunc, compiletype_T compile_type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
991 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
992 switch (ufunc->uf_def_status) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
993 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
994 case UF_TO_BE_COMPILED: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
995 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
996 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
997 case UF_COMPILED: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
998 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
999 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1000 + ufunc->uf_dfunc_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1001 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1002 switch (compile_type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1003 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1004 case CT_PROFILE: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1005 #ifdef FEAT_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1006 return dfunc->df_instr_prof == NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1007 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1008 case CT_NONE: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1009 return dfunc->df_instr == NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1010 case CT_DEBUG: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1011 return dfunc->df_instr_debug == NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1012 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1013 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1014 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1015 case UF_NOT_COMPILED: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1016 case UF_COMPILE_ERROR: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1017 case UF_COMPILING: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1018 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1019 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1020 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1021 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1022 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1023 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1024 * Compile a nested :def command. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1025 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1026 static char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1027 compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1028 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1029 int is_global = *eap->arg == 'g' && eap->arg[1] == ':'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1030 char_u *name_start = eap->arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1031 char_u *name_end = to_name_end(eap->arg, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1032 int off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1033 char_u *func_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1034 char_u *lambda_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1035 ufunc_T *ufunc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1036 int r = FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1037 compiletype_T compile_type; |
33366
88fa56e88cd7
patch 9.0.1944: Vim9: function instruction pointer invalidated
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1038 int funcref_isn_idx = -1; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1039 lvar_T *lvar = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1040 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1041 if (eap->forceit) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1042 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1043 emsg(_(e_cannot_use_bang_with_nested_def)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1044 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1045 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1046 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1047 if (*name_start == '/') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1048 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1049 name_end = skip_regexp(name_start + 1, '/', TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1050 if (*name_end == '/') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1051 ++name_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1052 set_nextcmd(eap, name_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1053 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1054 if (name_end == name_start || *skipwhite(name_end) != '(') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1055 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1056 if (!ends_excmd2(name_start, name_end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1057 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1058 if (*skipwhite(name_end) == '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1059 semsg(_(e_cannot_define_dict_func_in_vim9_script_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1060 eap->cmd); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1061 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1062 semsg(_(e_invalid_command_str), eap->cmd); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1063 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1064 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1065 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1066 // "def" or "def Name": list functions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1067 if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1068 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1069 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1070 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1071 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1072 // Only g:Func() can use a namespace. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1073 if (name_start[1] == ':' && !is_global) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1074 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1075 semsg(_(e_namespace_not_supported_str), name_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1076 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1077 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1078 if (cctx->ctx_skip != SKIP_YES |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1079 && check_defined(name_start, name_end - name_start, cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1080 NULL, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1081 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1082 if (!ASCII_ISUPPER(is_global ? name_start[2] : name_start[0])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1083 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1084 semsg(_(e_function_name_must_start_with_capital_str), name_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1085 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1086 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1087 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1088 eap->arg = name_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1089 fill_exarg_from_cctx(eap, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1090 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1091 eap->forceit = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1092 // We use the special <Lamba>99 name, but it's not really a lambda. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1093 lambda_name = vim_strsave(get_lambda_name()); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1094 if (lambda_name == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1095 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1096 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1097 // This may free the current line, make a copy of the name. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1098 off = is_global ? 2 : 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1099 func_name = vim_strnsave(name_start + off, name_end - name_start - off); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1100 if (func_name == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1101 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1102 r = FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1103 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1104 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1105 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1106 // Make sure "KeyTyped" is not set, it may cause indent to be written. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1107 int save_KeyTyped = KeyTyped; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1108 KeyTyped = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1109 |
33326
4e531adb3fac
patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents:
33322
diff
changeset
|
1110 ufunc = define_function(eap, lambda_name, lines_to_free, 0, NULL, 0); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1111 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1112 KeyTyped = save_KeyTyped; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1113 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1114 if (ufunc == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1115 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1116 r = eap->skip ? OK : FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1117 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1118 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1119 if (eap->nextcmd != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1120 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1121 semsg(_(e_text_found_after_str_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1122 eap->cmdidx == CMD_def ? "enddef" : "endfunction", eap->nextcmd); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1123 r = FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1124 func_ptr_unref(ufunc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1125 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1126 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1127 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1128 // copy over the block scope IDs before compiling |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1129 if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1130 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1131 int block_depth = cctx->ctx_ufunc->uf_block_depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1132 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1133 ufunc->uf_block_ids = ALLOC_MULT(int, block_depth); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1134 if (ufunc->uf_block_ids != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1135 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1136 mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1137 sizeof(int) * block_depth); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1138 ufunc->uf_block_depth = block_depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1139 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1140 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1141 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1142 // Define the funcref before compiling, so that it is found by any |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1143 // recursive call. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1144 if (is_global) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1145 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1146 r = generate_NEWFUNC(cctx, lambda_name, func_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1147 func_name = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1148 lambda_name = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1149 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1150 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1151 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1152 // Define a local variable for the function reference. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1153 lvar = reserve_local(cctx, func_name, name_end - name_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1154 ASSIGN_CONST, ufunc->uf_func_type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1155 if (lvar == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1156 goto theend; |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
1157 if (generate_FUNCREF(cctx, ufunc, NULL, FALSE, 0, &funcref_isn_idx) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1158 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1159 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1160 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1161 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1162 compile_type = get_compile_type(ufunc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1163 #ifdef FEAT_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1164 // If the outer function is profiled, also compile the nested function for |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1165 // profiling. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1166 if (cctx->ctx_compile_type == CT_PROFILE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1167 compile_type = CT_PROFILE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1168 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1169 if (func_needs_compiling(ufunc, compile_type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1170 && compile_def_function(ufunc, TRUE, compile_type, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1171 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1172 func_ptr_unref(ufunc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1173 if (lvar != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1174 // Now the local variable can't be used. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1175 *lvar->lv_name = '/'; // impossible value |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1176 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1177 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1178 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1179 #ifdef FEAT_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1180 // When the outer function is compiled for profiling, the nested function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1181 // may be called without profiling. Compile it here in the right context. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1182 if (compile_type == CT_PROFILE && func_needs_compiling(ufunc, CT_NONE)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1183 compile_def_function(ufunc, FALSE, CT_NONE, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1184 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1185 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1186 // If a FUNCREF instruction was generated, set the index after compiling. |
33366
88fa56e88cd7
patch 9.0.1944: Vim9: function instruction pointer invalidated
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1187 if (funcref_isn_idx != -1 && ufunc->uf_def_status == UF_COMPILED) |
88fa56e88cd7
patch 9.0.1944: Vim9: function instruction pointer invalidated
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1188 { |
88fa56e88cd7
patch 9.0.1944: Vim9: function instruction pointer invalidated
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1189 isn_T *funcref_isn = ((isn_T *)cctx->ctx_instr.ga_data) + |
88fa56e88cd7
patch 9.0.1944: Vim9: function instruction pointer invalidated
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1190 funcref_isn_idx; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1191 funcref_isn->isn_arg.funcref.fr_dfunc_idx = ufunc->uf_dfunc_idx; |
33366
88fa56e88cd7
patch 9.0.1944: Vim9: function instruction pointer invalidated
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1192 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1193 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1194 theend: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1195 vim_free(lambda_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1196 vim_free(func_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1197 return r == FAIL ? NULL : (char_u *)""; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1198 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1199 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1200 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1201 * Compile one Vim expression {expr} in string "p". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1202 * "p" points to the opening "{". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1203 * Return a pointer to the character after "}", NULL for an error. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1204 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1205 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1206 compile_one_expr_in_str(char_u *p, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1207 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1208 char_u *block_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1209 char_u *block_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1210 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1211 // Skip the opening {. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1212 block_start = skipwhite(p + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1213 block_end = block_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1214 if (*block_start != NUL && skip_expr(&block_end, NULL) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1215 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1216 block_end = skipwhite(block_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1217 // The block must be closed by a }. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1218 if (*block_end != '}') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1219 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1220 semsg(_(e_missing_close_curly_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1221 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1222 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1223 if (compile_expr0(&block_start, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1224 return NULL; |
34957
3cacfb652766
patch 9.1.0335: String interpolation fails for List type
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
1225 may_generate_2STRING(-1, TOSTRING_INTERPOLATE, cctx); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1226 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1227 return block_end + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1228 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1229 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1230 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1231 * Compile a string "str" (either containing a literal string or a mix of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1232 * literal strings and Vim expressions of the form `{expr}`). This is used |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1233 * when compiling a heredoc assignment to a variable or an interpolated string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1234 * in a Vim9 def function. Vim9 instructions are generated to push strings, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1235 * evaluate expressions, concatenate them and create a list of lines. When |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1236 * "evalstr" is TRUE, Vim expressions in "str" are evaluated. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1237 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1238 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1239 compile_all_expr_in_str(char_u *str, int evalstr, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1240 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1241 char_u *p = str; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1242 char_u *val; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1243 int count = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1244 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1245 if (cctx->ctx_skip == SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1246 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1247 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1248 if (!evalstr || *str == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1249 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1250 // Literal string, possibly empty. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1251 val = *str != NUL ? vim_strsave(str) : NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1252 return generate_PUSHS(cctx, &val); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1253 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1254 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1255 // Push all the string pieces to the stack, followed by a ISN_CONCAT. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1256 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1257 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1258 char_u *lit_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1259 int escaped_brace = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1260 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1261 // Look for a block start. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1262 lit_start = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1263 while (*p != '{' && *p != '}' && *p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1264 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1265 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1266 if (*p != NUL && *p == p[1]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1267 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1268 // Escaped brace, unescape and continue. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1269 // Include the brace in the literal string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1270 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1271 escaped_brace = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1272 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1273 else if (*p == '}') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1274 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1275 semsg(_(e_stray_closing_curly_str), str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1276 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1277 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1278 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1279 // Append the literal part. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1280 if (p != lit_start) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1281 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1282 val = vim_strnsave(lit_start, (size_t)(p - lit_start)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1283 if (generate_PUSHS(cctx, &val) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1284 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1285 ++count; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1286 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1287 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1288 if (*p == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1289 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1290 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1291 if (escaped_brace) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1292 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1293 // Skip the second brace. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1294 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1295 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1296 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1297 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1298 p = compile_one_expr_in_str(p, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1299 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1300 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1301 ++count; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1302 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1303 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1304 // Small optimization, if there's only a single piece skip the ISN_CONCAT. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1305 if (count > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1306 return generate_CONCAT(cctx, count); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1307 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1308 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1309 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1310 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1311 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1312 * Return the length of an assignment operator, or zero if there isn't one. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1313 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1314 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1315 assignment_len(char_u *p, int *heredoc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1316 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1317 if (*p == '=') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1318 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1319 if (p[1] == '<' && p[2] == '<') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1320 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1321 *heredoc = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1322 return 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1323 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1324 return 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1325 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1326 if (vim_strchr((char_u *)"+-*/%", *p) != NULL && p[1] == '=') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1327 return 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1328 if (STRNCMP(p, "..=", 3) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1329 return 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1330 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1331 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1332 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1333 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1334 * Generate the load instruction for "name". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1335 */ |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
1336 static int |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1337 generate_loadvar(cctx_T *cctx, lhs_T *lhs) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1338 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1339 char_u *name = lhs->lhs_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1340 type_T *type = lhs->lhs_type; |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
1341 int res = OK; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1342 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1343 switch (lhs->lhs_dest) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1344 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1345 case dest_option: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1346 case dest_func_option: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1347 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1348 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1349 case dest_global: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1350 if (vim_strchr(name, AUTOLOAD_CHAR) == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1351 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1352 if (name[2] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1353 generate_instr_type(cctx, ISN_LOADGDICT, &t_dict_any); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1354 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1355 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1356 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1357 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1358 generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1359 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1360 case dest_buffer: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1361 generate_LOAD(cctx, ISN_LOADB, 0, name + 2, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1362 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1363 case dest_window: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1364 generate_LOAD(cctx, ISN_LOADW, 0, name + 2, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1365 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1366 case dest_tab: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1367 generate_LOAD(cctx, ISN_LOADT, 0, name + 2, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1368 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1369 case dest_script: |
35037
5df4ad0a5200
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Christian Brabandt <cb@256bit.org>
parents:
35032
diff
changeset
|
1370 case dest_script_v9: |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
1371 res = compile_load_scriptvar(cctx, |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1372 name + (name[1] == ':' ? 2 : 0), NULL, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1373 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1374 case dest_env: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1375 // Include $ in the name here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1376 generate_LOAD(cctx, ISN_LOADENV, 0, name, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1377 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1378 case dest_reg: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1379 generate_LOAD(cctx, ISN_LOADREG, name[1], NULL, &t_string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1380 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1381 case dest_vimvar: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1382 generate_LOADV(cctx, name + 2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1383 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1384 case dest_local: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1385 if (cctx->ctx_skip != SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1386 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1387 lvar_T *lvar = lhs->lhs_lvar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1388 if (lvar->lv_from_outer > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1389 generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1390 lvar->lv_loop_depth, lvar->lv_loop_idx, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1391 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1392 generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1393 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1394 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1395 case dest_class_member: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1396 generate_CLASSMEMBER(cctx, TRUE, lhs->lhs_class, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1397 lhs->lhs_classmember_idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1398 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1399 case dest_expr: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1400 // list or dict value should already be on the stack. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1401 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1402 } |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
1403 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
1404 return res; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1405 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1406 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1407 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1408 * Skip over "[expr]" or ".member". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1409 * Does not check for any errors. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1410 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1411 static char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1412 skip_index(char_u *start) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1413 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1414 char_u *p = start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1415 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1416 if (*p == '[') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1417 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1418 p = skipwhite(p + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1419 (void)skip_expr(&p, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1420 p = skipwhite(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1421 if (*p == ']') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1422 return p + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1423 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1424 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1425 // if (*p == '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1426 return to_name_end(p + 1, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1427 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1428 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1429 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1430 vim9_declare_error(char_u *name) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1431 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1432 char *scope = ""; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1433 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1434 switch (*name) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1435 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1436 case 'g': scope = _("global"); break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1437 case 'b': scope = _("buffer"); break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1438 case 'w': scope = _("window"); break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1439 case 't': scope = _("tab"); break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1440 case 'v': scope = "v:"; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1441 case '$': semsg(_(e_cannot_declare_an_environment_variable_str), name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1442 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1443 case '&': semsg(_(e_cannot_declare_an_option_str), name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1444 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1445 case '@': semsg(_(e_cannot_declare_a_register_str), name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1446 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1447 default: return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1448 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1449 semsg(_(e_cannot_declare_a_scope_variable_str), scope, name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1450 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1451 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1452 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1453 * Return TRUE if "name" is a valid register to use. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1454 * Return FALSE and give an error message if not. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1455 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1456 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1457 valid_dest_reg(int name) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1458 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1459 if ((name == '@' || valid_yank_reg(name, FALSE)) && name != '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1460 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1461 emsg_invreg(name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1462 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1463 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1464 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1465 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1466 * For one assignment figure out the type of destination. Return it in "dest". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1467 * When not recognized "dest" is not set. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1468 * For an option "option_scope" is set. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1469 * For a v:var "vimvaridx" is set. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1470 * "type" is set to the destination type if known, unchanted otherwise. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1471 * Return FAIL if an error message was given. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1472 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1473 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1474 get_var_dest( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1475 char_u *name, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1476 assign_dest_T *dest, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1477 cmdidx_T cmdidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1478 int *option_scope, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1479 int *vimvaridx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1480 type_T **type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1481 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1482 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1483 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1484 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1485 if (*name == '&') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1486 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1487 int cc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1488 long numval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1489 getoption_T opt_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1490 int opt_p_flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1491 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1492 *dest = dest_option; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1493 if (cmdidx == CMD_final || cmdidx == CMD_const) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1494 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1495 emsg(_(e_cannot_lock_option)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1496 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1497 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1498 p = name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1499 p = find_option_end(&p, option_scope); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1500 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1501 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1502 // cannot happen? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1503 emsg(_(e_unexpected_characters_in_assignment)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1504 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1505 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1506 cc = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1507 *p = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1508 opt_type = get_option_value(skip_option_env_lead(name), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1509 &numval, NULL, &opt_p_flags, *option_scope); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1510 *p = cc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1511 switch (opt_type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1512 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1513 case gov_unknown: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1514 semsg(_(e_unknown_option_str), name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1515 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1516 case gov_string: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1517 case gov_hidden_string: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1518 if (opt_p_flags & P_FUNC) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1519 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1520 // might be a Funcref, check the type later |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1521 *type = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1522 *dest = dest_func_option; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1523 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1524 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1525 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1526 *type = &t_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1527 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1528 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1529 case gov_bool: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1530 case gov_hidden_bool: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1531 *type = &t_bool; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1532 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1533 case gov_number: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1534 case gov_hidden_number: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1535 *type = &t_number; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1536 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1537 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1538 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1539 else if (*name == '$') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1540 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1541 *dest = dest_env; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1542 *type = &t_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1543 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1544 else if (*name == '@') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1545 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1546 if (!valid_dest_reg(name[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1547 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1548 *dest = dest_reg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1549 *type = name[1] == '#' ? &t_number_or_string : &t_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1550 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1551 else if (STRNCMP(name, "g:", 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1552 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1553 *dest = dest_global; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1554 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1555 else if (STRNCMP(name, "b:", 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1556 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1557 *dest = dest_buffer; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1558 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1559 else if (STRNCMP(name, "w:", 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1560 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1561 *dest = dest_window; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1562 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1563 else if (STRNCMP(name, "t:", 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1564 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1565 *dest = dest_tab; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1566 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1567 else if (STRNCMP(name, "v:", 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1568 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1569 typval_T *vtv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1570 int di_flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1571 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1572 *vimvaridx = find_vim_var(name + 2, &di_flags); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1573 if (*vimvaridx < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1574 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1575 semsg(_(e_variable_not_found_str), name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1576 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1577 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1578 // We use the current value of "sandbox" here, is that OK? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1579 if (var_check_ro(di_flags, name, FALSE)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1580 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1581 *dest = dest_vimvar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1582 vtv = get_vim_var_tv(*vimvaridx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1583 *type = typval2type_vimvar(vtv, cctx->ctx_type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1584 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1585 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1586 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1587 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1588 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1589 is_decl_command(cmdidx_T cmdidx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1590 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1591 return cmdidx == CMD_let || cmdidx == CMD_var |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1592 || cmdidx == CMD_final || cmdidx == CMD_const; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1593 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1594 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1595 /* |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1596 * Returns TRUE if the class or object variable in "lhs" is modifiable. |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1597 * "var_start" points to the start of the variable name and "lhs->lhs_varlen" |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1598 * has the total length. Note that the "lhs" can be nested an object reference |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1599 * (e.g. a.b.c.d.var). |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1600 */ |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1601 static int |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1602 lhs_class_member_modifiable(lhs_T *lhs, char_u *var_start, cctx_T *cctx) |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1603 { |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1604 size_t varlen = lhs->lhs_varlen; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1605 class_T *cl = lhs->lhs_type->tt_class; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1606 int is_object = lhs->lhs_type->tt_type == VAR_OBJECT; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1607 char_u *name = var_start + varlen + 1; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1608 size_t namelen = lhs->lhs_end - var_start - varlen - 1; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1609 ocmember_T *m; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1610 |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1611 m = member_lookup(cl, lhs->lhs_type->tt_type, name, namelen, NULL); |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1612 if (m == NULL) |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1613 { |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1614 member_not_found_msg(cl, lhs->lhs_type->tt_type, name, namelen); |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1615 return FALSE; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1616 } |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1617 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
1618 if (IS_ENUM(cl)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
1619 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
1620 semsg(_(e_enumvalue_str_cannot_be_modified), cl->class_name, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
1621 m->ocm_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
1622 return FALSE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
1623 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
1624 |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1625 // If it is private member variable, then accessing it outside the |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1626 // class is not allowed. |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1627 // If it is a read only class variable, then it can be modified |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1628 // only inside the class where it is defined. |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1629 if ((m->ocm_access != VIM_ACCESS_ALL) && |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1630 ((is_object && !inside_class(cctx, cl)) |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1631 || (!is_object && cctx->ctx_ufunc->uf_class != cl))) |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1632 { |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1633 char *msg = (m->ocm_access == VIM_ACCESS_PRIVATE) |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33718
diff
changeset
|
1634 ? e_cannot_access_protected_variable_str |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
1635 : e_variable_is_not_writable_str; |
33498
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33466
diff
changeset
|
1636 emsg_var_cl_define(msg, m->ocm_name, 0, cl); |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1637 return FALSE; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1638 } |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1639 |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1640 return TRUE; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1641 } |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1642 |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1643 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1644 * Figure out the LHS type and other properties for an assignment or one item |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1645 * of ":unlet" with an index. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1646 * Returns OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1647 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1648 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1649 compile_lhs( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1650 char_u *var_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1651 lhs_T *lhs, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1652 cmdidx_T cmdidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1653 int heredoc, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1654 int has_cmd, // "var" before "var_start" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1655 int oplen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1656 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1657 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1658 char_u *var_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1659 int is_decl = is_decl_command(cmdidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1660 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1661 CLEAR_POINTER(lhs); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1662 lhs->lhs_dest = dest_local; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1663 lhs->lhs_vimvaridx = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1664 lhs->lhs_scriptvar_idx = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1665 lhs->lhs_member_idx = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1666 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1667 // "dest_end" is the end of the destination, including "[expr]" or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1668 // ".name". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1669 // "var_end" is the end of the variable/option/etc. name. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1670 lhs->lhs_dest_end = skip_var_one(var_start, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1671 if (*var_start == '@') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1672 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1673 if (!valid_dest_reg(var_start[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1674 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1675 var_end = var_start + 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1676 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1677 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1678 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1679 // skip over the leading "&", "&l:", "&g:" and "$" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1680 var_end = skip_option_env_lead(var_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1681 var_end = to_name_end(var_end, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1682 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1683 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1684 // "a: type" is declaring variable "a" with a type, not dict "a:". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1685 if (is_decl && lhs->lhs_dest_end == var_start + 2 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1686 && lhs->lhs_dest_end[-1] == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1687 --lhs->lhs_dest_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1688 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1689 --var_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1690 lhs->lhs_end = lhs->lhs_dest_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1691 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1692 // compute the length of the destination without "[expr]" or ".name" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1693 lhs->lhs_varlen = var_end - var_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1694 lhs->lhs_varlen_total = lhs->lhs_varlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1695 lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1696 if (lhs->lhs_name == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1697 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1698 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1699 if (lhs->lhs_dest_end > var_start + lhs->lhs_varlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1700 // Something follows after the variable: "var[idx]" or "var.key". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1701 lhs->lhs_has_index = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1702 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1703 if (heredoc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1704 lhs->lhs_type = &t_list_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1705 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1706 lhs->lhs_type = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1707 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1708 if (cctx->ctx_skip != SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1709 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1710 int declare_error = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1711 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1712 if (get_var_dest(lhs->lhs_name, &lhs->lhs_dest, cmdidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1713 &lhs->lhs_opt_flags, &lhs->lhs_vimvaridx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1714 &lhs->lhs_type, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1715 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1716 if (lhs->lhs_dest != dest_local |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1717 && cmdidx != CMD_const && cmdidx != CMD_final) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1718 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1719 // Specific kind of variable recognized. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1720 declare_error = is_decl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1721 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1722 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1723 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1724 class_T *defcl; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1725 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1726 // No specific kind of variable recognized, just a name. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1727 if (check_reserved_name(lhs->lhs_name, lhs->lhs_has_index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1728 && *var_end == '.') == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1729 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1730 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1731 if (lookup_local(var_start, lhs->lhs_varlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1732 &lhs->lhs_local_lvar, cctx) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1733 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1734 lhs->lhs_lvar = &lhs->lhs_local_lvar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1735 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1736 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1737 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1738 CLEAR_FIELD(lhs->lhs_arg_lvar); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1739 if (arg_exists(var_start, lhs->lhs_varlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1740 &lhs->lhs_arg_lvar.lv_idx, &lhs->lhs_arg_lvar.lv_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1741 &lhs->lhs_arg_lvar.lv_from_outer, cctx) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1742 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1743 if (is_decl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1744 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1745 semsg(_(e_str_is_used_as_argument), lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1746 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1747 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1748 lhs->lhs_lvar = &lhs->lhs_arg_lvar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1749 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1750 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1751 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1752 if (lhs->lhs_lvar != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1753 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1754 if (is_decl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1755 { |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1756 // if we come here with what looks like an assignment like |
33466
3de472480e91
patch 9.0.1986: Vim9: accepting type-annotations
Christian Brabandt <cb@256bit.org>
parents:
33446
diff
changeset
|
1757 // .= but which has been rejected by assignment_len() from |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1758 // may_compile_assignment give a better error message |
33250
575dd775b7fb
patch 9.0.1897: Vim9: confusing error with .= in compiled functions
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
1759 char_u *p = skipwhite(lhs->lhs_end); |
575dd775b7fb
patch 9.0.1897: Vim9: confusing error with .= in compiled functions
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
1760 if (p[0] == '.' && p[1] == '=') |
575dd775b7fb
patch 9.0.1897: Vim9: confusing error with .= in compiled functions
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
1761 emsg(_(e_dot_equal_not_supported_with_script_version_two)); |
33466
3de472480e91
patch 9.0.1986: Vim9: accepting type-annotations
Christian Brabandt <cb@256bit.org>
parents:
33446
diff
changeset
|
1762 else if (p[0] == ':') |
3de472480e91
patch 9.0.1986: Vim9: accepting type-annotations
Christian Brabandt <cb@256bit.org>
parents:
33446
diff
changeset
|
1763 // type specified in a non-var assignment |
3de472480e91
patch 9.0.1986: Vim9: accepting type-annotations
Christian Brabandt <cb@256bit.org>
parents:
33446
diff
changeset
|
1764 semsg(_(e_trailing_characters_str), p); |
33250
575dd775b7fb
patch 9.0.1897: Vim9: confusing error with .= in compiled functions
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
1765 else |
575dd775b7fb
patch 9.0.1897: Vim9: confusing error with .= in compiled functions
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
1766 semsg(_(e_variable_already_declared_str), lhs->lhs_name); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1767 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1768 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1769 } |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1770 else if ((lhs->lhs_classmember_idx = cctx_class_member_idx( |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1771 cctx, var_start, lhs->lhs_varlen, &defcl)) >= 0) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1772 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1773 if (cctx->ctx_ufunc->uf_defclass != defcl) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1774 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1775 // A class variable can be accessed without the class name |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1776 // only inside a class. |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
1777 semsg(_(e_class_variable_str_accessible_only_inside_class_str), |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1778 lhs->lhs_name, defcl->class_name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1779 return FAIL; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
1780 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1781 if (is_decl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1782 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1783 semsg(_(e_variable_already_declared_in_class_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1784 lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1785 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1786 } |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
1787 |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
1788 ocmember_T *m = |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
1789 &defcl->class_class_members[lhs->lhs_classmember_idx]; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
1790 if (oc_var_check_ro(defcl, m)) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
1791 return FAIL; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
1792 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1793 lhs->lhs_dest = dest_class_member; |
34748
529709e74c11
patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents:
34676
diff
changeset
|
1794 // The class variable is defined either in the current class or |
529709e74c11
patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents:
34676
diff
changeset
|
1795 // in one of the parent class in the hierarchy. |
529709e74c11
patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents:
34676
diff
changeset
|
1796 lhs->lhs_class = defcl; |
529709e74c11
patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents:
34676
diff
changeset
|
1797 lhs->lhs_type = oc_member_type_by_idx(defcl, FALSE, |
529709e74c11
patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents:
34676
diff
changeset
|
1798 lhs->lhs_classmember_idx); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1799 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1800 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1801 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1802 int script_namespace = lhs->lhs_varlen > 1 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1803 && STRNCMP(var_start, "s:", 2) == 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1804 int script_var = (script_namespace |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1805 ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1806 cctx, NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1807 : script_var_exists(var_start, lhs->lhs_varlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1808 cctx, NULL)) == OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1809 imported_T *import = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1810 find_imported(var_start, lhs->lhs_varlen, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1811 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1812 if (script_namespace || script_var || import != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1813 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1814 char_u *rawname = lhs->lhs_name |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1815 + (lhs->lhs_name[1] == ':' ? 2 : 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1816 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1817 if (script_namespace && current_script_is_vim9()) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1818 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1819 semsg(_(e_cannot_use_s_colon_in_vim9_script_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1820 var_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1821 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1822 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1823 if (is_decl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1824 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1825 if (script_namespace) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1826 semsg(_(e_cannot_declare_script_variable_in_function_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1827 lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1828 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1829 semsg(_(e_variable_already_declared_in_script_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1830 lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1831 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1832 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1833 else if (cctx->ctx_ufunc->uf_script_ctx_version |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1834 == SCRIPT_VERSION_VIM9 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1835 && script_namespace |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1836 && !script_var && import == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1837 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1838 semsg(_(e_unknown_variable_str), lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1839 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1840 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1841 |
35037
5df4ad0a5200
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Christian Brabandt <cb@256bit.org>
parents:
35032
diff
changeset
|
1842 lhs->lhs_dest = current_script_is_vim9() |
5df4ad0a5200
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Christian Brabandt <cb@256bit.org>
parents:
35032
diff
changeset
|
1843 ? dest_script_v9 : dest_script; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1844 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1845 // existing script-local variables should have a type |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1846 lhs->lhs_scriptvar_sid = current_sctx.sc_sid; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1847 if (import != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1848 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1849 char_u *dot = vim_strchr(var_start, '.'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1850 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1851 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1852 // for an import the name is what comes after the dot |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1853 if (dot == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1854 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1855 semsg(_(e_no_dot_after_imported_name_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1856 var_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1857 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1858 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1859 p = skipwhite(dot + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1860 var_end = to_name_end(p, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1861 if (var_end == p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1862 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1863 semsg(_(e_missing_name_after_imported_name_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1864 var_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1865 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1866 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1867 vim_free(lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1868 lhs->lhs_varlen = var_end - p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1869 lhs->lhs_name = vim_strnsave(p, lhs->lhs_varlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1870 if (lhs->lhs_name == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1871 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1872 rawname = lhs->lhs_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1873 lhs->lhs_scriptvar_sid = import->imp_sid; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1874 // TODO: where do we check this name is exported? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1875 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1876 // Check if something follows: "exp.var[idx]" or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1877 // "exp.var.key". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1878 lhs->lhs_has_index = lhs->lhs_dest_end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1879 > skipwhite(var_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1880 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1881 if (SCRIPT_ID_VALID(lhs->lhs_scriptvar_sid)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1882 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1883 // Check writable only when no index follows. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1884 lhs->lhs_scriptvar_idx = get_script_item_idx( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1885 lhs->lhs_scriptvar_sid, rawname, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1886 lhs->lhs_has_index ? ASSIGN_FINAL : ASSIGN_CONST, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1887 cctx, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1888 if (lhs->lhs_scriptvar_idx >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1889 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1890 scriptitem_T *si = SCRIPT_ITEM( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1891 lhs->lhs_scriptvar_sid); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1892 svar_T *sv = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1893 ((svar_T *)si->sn_var_vals.ga_data) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1894 + lhs->lhs_scriptvar_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1895 lhs->lhs_type = sv->sv_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1896 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1897 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1898 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1899 else if (check_defined(var_start, lhs->lhs_varlen, cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1900 NULL, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1901 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1902 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1903 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1904 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1905 if (declare_error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1906 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1907 vim9_declare_error(lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1908 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1909 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1910 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1911 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1912 // handle "a:name" as a name, not index "name" in "a" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1913 if (lhs->lhs_varlen > 1 || var_start[lhs->lhs_varlen] != ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1914 var_end = lhs->lhs_dest_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1915 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1916 if (lhs->lhs_dest != dest_option && lhs->lhs_dest != dest_func_option) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1917 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1918 if (is_decl && *skipwhite(var_end) == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1919 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1920 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1921 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1922 // parse optional type: "let var: type = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1923 if (VIM_ISWHITE(*var_end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1924 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1925 semsg(_(e_no_white_space_allowed_before_colon_str), var_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1926 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1927 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1928 if (!VIM_ISWHITE(var_end[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1929 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1930 semsg(_(e_white_space_required_after_str_str), ":", var_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1931 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1932 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1933 p = skipwhite(var_end + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1934 lhs->lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1935 if (lhs->lhs_type == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1936 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1937 lhs->lhs_has_type = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1938 lhs->lhs_end = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1939 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1940 else if (lhs->lhs_lvar != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1941 lhs->lhs_type = lhs->lhs_lvar->lv_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1942 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1943 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1944 if (oplen == 3 && !heredoc |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1945 && lhs->lhs_dest != dest_global |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1946 && !lhs->lhs_has_index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1947 && lhs->lhs_type->tt_type != VAR_STRING |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1948 && lhs->lhs_type->tt_type != VAR_ANY) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1949 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1950 emsg(_(e_can_only_concatenate_to_string)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1951 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1952 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1953 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1954 if (lhs->lhs_lvar == NULL && lhs->lhs_dest == dest_local |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1955 && cctx->ctx_skip != SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1956 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1957 if (oplen > 1 && !heredoc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1958 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1959 // +=, /=, etc. require an existing variable |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1960 semsg(_(e_cannot_use_operator_on_new_variable_str), lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1961 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1962 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1963 if (!is_decl || (lhs->lhs_has_index && !has_cmd |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1964 && cctx->ctx_skip != SKIP_YES)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1965 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1966 semsg(_(e_unknown_variable_str), lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1967 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1968 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1969 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1970 // Check the name is valid for a funcref. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1971 if ((lhs->lhs_type->tt_type == VAR_FUNC |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1972 || lhs->lhs_type->tt_type == VAR_PARTIAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1973 && var_wrong_func_name(lhs->lhs_name, TRUE)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1974 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1975 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1976 // New local variable. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1977 int assign = cmdidx == CMD_final ? ASSIGN_FINAL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1978 : cmdidx == CMD_const ? ASSIGN_CONST : ASSIGN_VAR; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1979 lhs->lhs_lvar = reserve_local(cctx, var_start, lhs->lhs_varlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1980 assign, lhs->lhs_type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1981 if (lhs->lhs_lvar == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1982 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1983 lhs->lhs_new_local = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1984 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1985 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1986 lhs->lhs_member_type = lhs->lhs_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1987 if (lhs->lhs_has_index) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1988 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1989 char_u *after = var_start + lhs->lhs_varlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1990 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1991 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1992 // Something follows after the variable: "var[idx]" or "var.key". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1993 if (is_decl && cctx->ctx_skip != SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1994 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1995 if (has_cmd) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1996 emsg(_(e_cannot_use_index_when_declaring_variable)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1997 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1998 semsg(_(e_unknown_variable_str), lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1999 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2000 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2001 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2002 // Now: var_start[lhs->lhs_varlen] is '[' or '.' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2003 // Only the last index is used below, if there are others |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2004 // before it generate code for the expression. Thus for |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2005 // "ll[1][2]" the expression is "ll[1]" and "[2]" is the index. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2006 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2007 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2008 p = skip_index(after); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2009 if (*p != '[' && *p != '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2010 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2011 lhs->lhs_varlen_total = p - var_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2012 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2013 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2014 after = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2015 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2016 if (after > var_start + lhs->lhs_varlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2017 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2018 lhs->lhs_varlen = after - var_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2019 lhs->lhs_dest = dest_expr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2020 // We don't know the type before evaluating the expression, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2021 // use "any" until then. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2022 lhs->lhs_type = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2023 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2024 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2025 int use_class = lhs->lhs_type != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2026 && (lhs->lhs_type->tt_type == VAR_CLASS |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
2027 || lhs->lhs_type->tt_type == VAR_OBJECT); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2028 if (lhs->lhs_type == NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2029 || (use_class ? lhs->lhs_type->tt_class == NULL |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
2030 : lhs->lhs_type->tt_member == NULL)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2031 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2032 lhs->lhs_member_type = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2033 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2034 else if (use_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2035 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2036 // for an object or class member get the type of the member |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33075
diff
changeset
|
2037 class_T *cl = lhs->lhs_type->tt_class; |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33250
diff
changeset
|
2038 int is_object = lhs->lhs_type->tt_type == VAR_OBJECT; |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2039 char_u *name = var_start + lhs->lhs_varlen + 1; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2040 size_t namelen = lhs->lhs_end - var_start - lhs->lhs_varlen - 1; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2041 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2042 ocmember_T *m = member_lookup(cl, lhs->lhs_type->tt_type, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2043 name, namelen, &lhs->lhs_member_idx); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2044 if (m == NULL) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2045 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2046 member_not_found_msg(cl, lhs->lhs_type->tt_type, name, namelen); |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2047 return FAIL; |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2048 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2049 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2050 if (IS_ENUM(cl)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2051 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2052 if (!inside_class(cctx, cl)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2053 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2054 semsg(_(e_enumvalue_str_cannot_be_modified), |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2055 cl->class_name, m->ocm_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2056 return FALSE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2057 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2058 if (lhs->lhs_type->tt_type == VAR_OBJECT && |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2059 lhs->lhs_member_idx < 2) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2060 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2061 char *msg = lhs->lhs_member_idx == 0 ? |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2062 e_enum_str_name_cannot_be_modified : |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2063 e_enum_str_ordinal_cannot_be_modified; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2064 semsg(_(msg), cl->class_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2065 return FALSE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2066 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2067 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2068 |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2069 // If it is private member variable, then accessing it outside the |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2070 // class is not allowed. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2071 // If it is a read only class variable, then it can be modified |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2072 // only inside the class where it is defined. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2073 if ((m->ocm_access != VIM_ACCESS_ALL) && |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2074 ((is_object && !inside_class(cctx, cl)) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2075 || (!is_object && cctx->ctx_ufunc->uf_class != cl))) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2076 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2077 char *msg = (m->ocm_access == VIM_ACCESS_PRIVATE) |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33718
diff
changeset
|
2078 ? e_cannot_access_protected_variable_str |
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33718
diff
changeset
|
2079 : e_variable_is_not_writable_str; |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2080 emsg_var_cl_define(msg, m->ocm_name, 0, cl); |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33075
diff
changeset
|
2081 return FAIL; |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2082 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2083 |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
2084 if (!IS_CONSTRUCTOR_METHOD(cctx->ctx_ufunc) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
2085 && oc_var_check_ro(cl, m)) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
2086 return FAIL; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
2087 |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2088 lhs->lhs_member_type = m->ocm_type; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2089 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2090 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2091 lhs->lhs_member_type = lhs->lhs_type->tt_member; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2092 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2093 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2094 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2095 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2096 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2097 * Figure out the LHS and check a few errors. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2098 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2099 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2100 compile_assign_lhs( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2101 char_u *var_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2102 lhs_T *lhs, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2103 cmdidx_T cmdidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2104 int is_decl, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2105 int heredoc, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2106 int has_cmd, // "var" before "var_start" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2107 int oplen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2108 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2109 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2110 if (compile_lhs(var_start, lhs, cmdidx, heredoc, has_cmd, oplen, cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2111 == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2112 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2113 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2114 if (!lhs->lhs_has_index && lhs->lhs_lvar == &lhs->lhs_arg_lvar) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2115 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2116 semsg(_(e_cannot_assign_to_argument_str), lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2117 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2118 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2119 if (!is_decl && lhs->lhs_lvar != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2120 && lhs->lhs_lvar->lv_const != ASSIGN_VAR |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2121 && !lhs->lhs_has_index) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2122 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2123 semsg(_(e_cannot_assign_to_constant_str), lhs->lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2124 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2125 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2126 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2127 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2128 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2129 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2130 * Return TRUE if "lhs" has a range index: "[expr : expr]". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2131 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2132 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2133 has_list_index(char_u *idx_start, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2134 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2135 char_u *p = idx_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2136 int save_skip; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2137 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2138 if (*p != '[') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2139 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2140 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2141 p = skipwhite(p + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2142 if (*p == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2143 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2144 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2145 save_skip = cctx->ctx_skip; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2146 cctx->ctx_skip = SKIP_YES; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2147 (void)compile_expr0(&p, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2148 cctx->ctx_skip = save_skip; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2149 return *skipwhite(p) == ':'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2150 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2151 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2152 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2153 * For an assignment with an index, compile the "idx" in "var[idx]" or "key" in |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2154 * "var.key". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2155 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2156 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2157 compile_assign_index( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2158 char_u *var_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2159 lhs_T *lhs, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2160 int *range, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2161 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2162 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2163 size_t varlen = lhs->lhs_varlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2164 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2165 int r = OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2166 int need_white_before = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2167 int empty_second; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2168 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2169 p = var_start + varlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2170 if (*p == '[') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2171 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2172 p = skipwhite(p + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2173 if (*p == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2174 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2175 // empty first index, push zero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2176 r = generate_PUSHNR(cctx, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2177 need_white_before = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2178 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2179 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2180 r = compile_expr0(&p, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2181 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2182 if (r == OK && *skipwhite(p) == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2183 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2184 // unlet var[idx : idx] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2185 // blob[idx : idx] = value |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2186 *range = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2187 p = skipwhite(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2188 empty_second = *skipwhite(p + 1) == ']'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2189 if ((need_white_before && !IS_WHITE_OR_NUL(p[-1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2190 || (!empty_second && !IS_WHITE_OR_NUL(p[1]))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2191 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2192 semsg(_(e_white_space_required_before_and_after_str_at_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2193 ":", p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2194 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2195 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2196 p = skipwhite(p + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2197 if (*p == ']') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2198 // empty second index, push "none" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2199 r = generate_PUSHSPEC(cctx, VVAL_NONE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2200 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2201 r = compile_expr0(&p, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2202 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2203 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2204 if (r == OK && *skipwhite(p) != ']') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2205 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2206 // this should not happen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2207 emsg(_(e_missing_closing_square_brace)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2208 r = FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2209 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2210 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2211 else if (lhs->lhs_member_idx >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2212 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2213 // object member index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2214 r = generate_PUSHNR(cctx, lhs->lhs_member_idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2215 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2216 else // if (*p == '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2217 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2218 char_u *key_end = to_name_end(p + 1, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2219 char_u *key = vim_strnsave(p + 1, key_end - p - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2220 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2221 r = generate_PUSHS(cctx, &key); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2222 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2223 return r; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2224 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2225 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2226 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2227 * For a LHS with an index, load the variable to be indexed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2228 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2229 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2230 compile_load_lhs( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2231 lhs_T *lhs, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2232 char_u *var_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2233 type_T *rhs_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2234 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2235 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2236 if (lhs->lhs_dest == dest_expr) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2237 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2238 size_t varlen = lhs->lhs_varlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2239 int c = var_start[varlen]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2240 int lines_len = cctx->ctx_ufunc->uf_lines.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2241 int res; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2242 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2243 // Evaluate "ll[expr]" of "ll[expr][idx]". End the line with a NUL and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2244 // limit the lines array length to avoid skipping to a following line. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2245 var_start[varlen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2246 cctx->ctx_ufunc->uf_lines.ga_len = cctx->ctx_lnum + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2247 char_u *p = var_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2248 res = compile_expr0(&p, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2249 var_start[varlen] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2250 cctx->ctx_ufunc->uf_lines.ga_len = lines_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2251 if (res == FAIL || p != var_start + varlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2252 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2253 // this should not happen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2254 if (res != FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2255 emsg(_(e_missing_closing_square_brace)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2256 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2257 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2258 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2259 lhs->lhs_type = cctx->ctx_type_stack.ga_len == 0 ? &t_void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2260 : get_type_on_stack(cctx, 0); |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2261 |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2262 if (lhs->lhs_type->tt_type == VAR_OBJECT) |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2263 { |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2264 // Check whether the object variable is modifiable |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2265 if (!lhs_class_member_modifiable(lhs, var_start, cctx)) |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2266 return FAIL; |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2267 } |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2268 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2269 // Now we can properly check the type. The variable is indexed, thus |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2270 // we need the member type. For a class or object we don't know the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2271 // type yet, it depends on what member is used. |
33668
fcc8296f36eb
patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents:
33540
diff
changeset
|
2272 // The top item in the stack is the Dict, followed by the key and then |
fcc8296f36eb
patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents:
33540
diff
changeset
|
2273 // the type of the value. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2274 vartype_T vartype = lhs->lhs_type->tt_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2275 type_T *member_type = lhs->lhs_type->tt_member; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2276 if (rhs_type != NULL && member_type != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2277 && vartype != VAR_OBJECT && vartype != VAR_CLASS |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2278 && rhs_type != &t_void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2279 && need_type(rhs_type, member_type, FALSE, |
33668
fcc8296f36eb
patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents:
33540
diff
changeset
|
2280 -3, 0, cctx, FALSE, FALSE) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2281 return FAIL; |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
2282 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
2283 return OK; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2284 } |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
2285 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
2286 return generate_loadvar(cctx, lhs); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2287 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2288 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2289 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2290 * Produce code for loading "lhs" and also take care of an index. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2291 * Return OK/FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2292 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2293 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2294 compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2295 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2296 if (lhs->lhs_type->tt_type == VAR_OBJECT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2297 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2298 // "this.value": load "this" object and get the value at index for an |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2299 // object or class member get the type of the member. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2300 // Also for "obj.value". |
33996
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2301 char_u *dot = vim_strchr(var_start, '.'); |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2302 if (dot == NULL) |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2303 { |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2304 semsg(_(e_missing_dot_after_object_str), lhs->lhs_name); |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2305 return FAIL; |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2306 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2307 |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33075
diff
changeset
|
2308 class_T *cl = lhs->lhs_type->tt_class; |
33534
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2309 type_T *type = oc_member_type(cl, TRUE, dot + 1, |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
2310 lhs->lhs_end, &lhs->lhs_member_idx); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2311 if (lhs->lhs_member_idx < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2312 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2313 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2314 if (dot - var_start == 4 && STRNCMP(var_start, "this", 4) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2315 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2316 // load "this" |
34618
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2317 lvar_T *lvar = lhs->lhs_lvar; |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2318 int rc; |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2319 |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2320 if (lvar->lv_from_outer > 0) |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2321 rc = generate_LOADOUTER(cctx, lvar->lv_idx, |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2322 lvar->lv_from_outer, lvar->lv_loop_depth, |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2323 lvar->lv_loop_idx, type); |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2324 else |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2325 rc = generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type); |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2326 |
7ff3c277377f
patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents:
34074
diff
changeset
|
2327 if (rc == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2328 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2329 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2330 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2331 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2332 // load object variable or argument |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2333 if (compile_load_lhs(lhs, var_start, lhs->lhs_type, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2334 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2335 } |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2336 if (IS_INTERFACE(cl)) |
33387
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33366
diff
changeset
|
2337 return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type); |
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33366
diff
changeset
|
2338 return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2339 } |
33534
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2340 else if (lhs->lhs_type->tt_type == VAR_CLASS) |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2341 { |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2342 // "<classname>.value": load class variable "classname.value" |
33996
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2343 char_u *dot = vim_strchr(var_start, '.'); |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2344 if (dot == NULL) |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2345 { |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2346 check_type_is_value(lhs->lhs_type); |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2347 return FAIL; |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33993
diff
changeset
|
2348 } |
33534
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2349 |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2350 class_T *cl = lhs->lhs_type->tt_class; |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2351 ocmember_T *m = class_member_lookup(cl, dot + 1, |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2352 lhs->lhs_end - dot - 1, |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2353 &lhs->lhs_member_idx); |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2354 if (m == NULL) |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2355 return FAIL; |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2356 |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2357 return generate_CLASSMEMBER(cctx, TRUE, cl, lhs->lhs_member_idx); |
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2358 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2359 |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
2360 if (compile_load_lhs(lhs, var_start, NULL, cctx) == FAIL) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
2361 return FAIL; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2362 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2363 if (lhs->lhs_has_index) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2364 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2365 int range = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2366 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2367 // Get member from list or dict. First compile the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2368 // index value. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2369 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2370 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2371 if (range) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2372 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2373 semsg(_(e_cannot_use_range_with_assignment_operator_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2374 var_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2375 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2376 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2377 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2378 // Get the member. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2379 if (compile_member(FALSE, NULL, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2380 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2381 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2382 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2383 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2384 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2385 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2386 * Assignment to a list or dict member, or ":unlet" for the item, using the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2387 * information in "lhs". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2388 * Returns OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2389 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2390 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2391 compile_assign_unlet( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2392 char_u *var_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2393 lhs_T *lhs, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2394 int is_assign, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2395 type_T *rhs_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2396 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2397 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2398 vartype_T dest_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2399 int range = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2400 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2401 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2402 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2403 if (is_assign && range |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2404 && lhs->lhs_type->tt_type != VAR_LIST |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2405 && lhs->lhs_type != &t_blob |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2406 && lhs->lhs_type != &t_any) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2407 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2408 semsg(_(e_cannot_use_range_with_assignment_str), var_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2409 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2410 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2411 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2412 if (lhs->lhs_type == NULL || lhs->lhs_type == &t_any) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2413 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2414 // Index on variable of unknown type: check at runtime. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2415 dest_type = VAR_ANY; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2416 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2417 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2418 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2419 dest_type = lhs->lhs_type->tt_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2420 if (dest_type == VAR_DICT && range) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2421 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2422 emsg(_(e_cannot_use_range_with_dictionary)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2423 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2424 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2425 if (dest_type == VAR_DICT |
34957
3cacfb652766
patch 9.1.0335: String interpolation fails for List type
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
2426 && may_generate_2STRING(-1, TOSTRING_NONE, cctx) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2427 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2428 if (dest_type == VAR_LIST || dest_type == VAR_BLOB) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2429 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2430 type_T *type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2431 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2432 if (range) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2433 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2434 type = get_type_on_stack(cctx, 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2435 if (need_type(type, &t_number, FALSE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2436 -2, 0, cctx, FALSE, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2437 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2438 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2439 type = get_type_on_stack(cctx, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2440 if ((dest_type != VAR_BLOB && type->tt_type != VAR_SPECIAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2441 && need_type(type, &t_number, FALSE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2442 -1, 0, cctx, FALSE, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2443 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2444 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2445 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2446 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2447 if (cctx->ctx_skip == SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2448 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2449 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2450 // Load the dict, list or object. On the stack we then have: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2451 // - value (for assignment, not for :unlet) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2452 // - index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2453 // - for [a : b] second index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2454 // - variable |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2455 if (compile_load_lhs(lhs, var_start, rhs_type, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2456 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2457 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2458 if (dest_type == VAR_LIST |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2459 || dest_type == VAR_DICT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2460 || dest_type == VAR_BLOB |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2461 || dest_type == VAR_CLASS |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2462 || dest_type == VAR_OBJECT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2463 || dest_type == VAR_ANY) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2464 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2465 if (is_assign) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2466 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2467 if (range) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2468 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2469 if (generate_instr_drop(cctx, ISN_STORERANGE, 4) == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2470 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2471 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2472 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2473 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2474 isn_T *isn = generate_instr_drop(cctx, ISN_STOREINDEX, 3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2475 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2476 if (isn == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2477 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2478 isn->isn_arg.storeindex.si_vartype = dest_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2479 isn->isn_arg.storeindex.si_class = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2480 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2481 if (dest_type == VAR_OBJECT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2482 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2483 class_T *cl = lhs->lhs_type->tt_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2484 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
2485 if (IS_INTERFACE(cl)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2486 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2487 // "this.value": load "this" object and get the value |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2488 // at index for an object or class member get the type |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2489 // of the member |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2490 isn->isn_arg.storeindex.si_class = cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2491 ++cl->class_refcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2492 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2493 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2494 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2495 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2496 else if (range) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2497 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2498 if (generate_instr_drop(cctx, ISN_UNLETRANGE, 3) == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2499 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2500 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2501 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2502 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2503 if (generate_instr_drop(cctx, ISN_UNLETINDEX, 2) == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2504 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2505 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2506 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2507 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2508 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2509 emsg(_(e_indexable_type_required)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2510 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2511 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2512 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2513 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2514 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2515 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2516 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2517 * Generate an instruction to push the default value for "vartype". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2518 * if "dest_local" is TRUE then for some types no instruction is generated. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2519 * "skip_store" is set to TRUE if no PUSH instruction is generated. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2520 * Returns OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2521 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2522 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2523 push_default_value( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2524 cctx_T *cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2525 vartype_T vartype, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2526 int dest_is_local, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2527 int *skip_store) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2528 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2529 int r = OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2530 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2531 switch (vartype) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2532 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2533 case VAR_BOOL: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2534 r = generate_PUSHBOOL(cctx, VVAL_FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2535 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2536 case VAR_FLOAT: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2537 r = generate_PUSHF(cctx, 0.0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2538 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2539 case VAR_STRING: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2540 r = generate_PUSHS(cctx, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2541 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2542 case VAR_BLOB: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2543 r = generate_PUSHBLOB(cctx, blob_alloc()); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2544 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2545 case VAR_FUNC: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2546 r = generate_PUSHFUNC(cctx, NULL, &t_func_void, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2547 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2548 case VAR_LIST: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2549 r = generate_NEWLIST(cctx, 0, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2550 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2551 case VAR_DICT: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2552 r = generate_NEWDICT(cctx, 0, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2553 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2554 case VAR_JOB: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2555 r = generate_PUSHJOB(cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2556 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2557 case VAR_CHANNEL: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2558 r = generate_PUSHCHANNEL(cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2559 break; |
33008
ba1b40b520e8
patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
2560 case VAR_OBJECT: |
ba1b40b520e8
patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
2561 r = generate_PUSHOBJ(cctx); |
ba1b40b520e8
patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
2562 break; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2563 case VAR_NUMBER: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2564 case VAR_UNKNOWN: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2565 case VAR_ANY: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2566 case VAR_PARTIAL: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2567 case VAR_VOID: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2568 case VAR_INSTR: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2569 case VAR_CLASS: |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33668
diff
changeset
|
2570 case VAR_TYPEALIAS: |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2571 case VAR_SPECIAL: // cannot happen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2572 // This is skipped for local variables, they are always |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2573 // initialized to zero. But in a "for" or "while" loop |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2574 // the value may have been changed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2575 if (dest_is_local && !inside_loop_scope(cctx)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2576 *skip_store = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2577 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2578 r = generate_PUSHNR(cctx, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2579 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2580 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2581 return r; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2582 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2583 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2584 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2585 * Compile declaration and assignment: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2586 * "let name" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2587 * "var name = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2588 * "final name = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2589 * "const name = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2590 * "name = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2591 * "arg" points to "name". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2592 * "++arg" and "--arg" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2593 * Return NULL for an error. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2594 * Return "arg" if it does not look like a variable list. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2595 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2596 static char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2597 compile_assignment( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2598 char_u *arg_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2599 exarg_T *eap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2600 cmdidx_T cmdidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2601 cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2602 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2603 char_u *arg = arg_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2604 char_u *var_start; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2605 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2606 char_u *end = arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2607 char_u *ret = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2608 int var_count = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2609 int var_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2610 int semicolon = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2611 int did_generate_slice = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2612 garray_T *instr = &cctx->ctx_instr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2613 int jump_instr_idx = instr->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2614 char_u *op; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2615 int oplen = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2616 int heredoc = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2617 int incdec = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2618 type_T *rhs_type = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2619 char_u *sp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2620 int is_decl = is_decl_command(cmdidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2621 lhs_T lhs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2622 CLEAR_FIELD(lhs); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2623 long start_lnum = SOURCING_LNUM; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2624 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2625 int has_arg_is_set_prefix = STRNCMP(arg, "ifargisset ", 11) == 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2626 if (has_arg_is_set_prefix) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2627 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2628 arg += 11; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2629 int def_idx = getdigits(&arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2630 arg = skipwhite(arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2631 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2632 // Use a JUMP_IF_ARG_NOT_SET instruction to skip if the value was not |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2633 // given and the default value is "v:none". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2634 int off = STACK_FRAME_SIZE + (cctx->ctx_ufunc->uf_va_name != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2635 ? 1 : 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2636 int count = cctx->ctx_ufunc->uf_def_args.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2637 if (generate_JUMP_IF_ARG(cctx, ISN_JUMP_IF_ARG_NOT_SET, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2638 def_idx - count - off) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2639 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2640 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2641 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2642 // Skip over the "varname" or "[varname, varname]" to get to any "=". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2643 p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2644 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2645 return *arg == '[' ? arg : NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2646 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2647 if (eap->cmdidx == CMD_increment || eap->cmdidx == CMD_decrement) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2648 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2649 if (VIM_ISWHITE(eap->cmd[2])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2650 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2651 semsg(_(e_no_white_space_allowed_after_str_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2652 eap->cmdidx == CMD_increment ? "++" : "--", eap->cmd); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2653 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2654 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2655 op = (char_u *)(eap->cmdidx == CMD_increment ? "+=" : "-="); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2656 oplen = 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2657 incdec = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2658 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2659 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2660 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2661 sp = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2662 p = skipwhite(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2663 op = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2664 oplen = assignment_len(p, &heredoc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2665 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2666 if (var_count > 0 && oplen == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2667 // can be something like "[1, 2]->func()" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2668 return arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2669 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2670 if (oplen > 0 && (!VIM_ISWHITE(*sp) || !IS_WHITE_OR_NUL(op[oplen]))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2671 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2672 error_white_both(op, oplen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2673 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2674 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2675 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2676 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2677 if (heredoc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2678 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2679 list_T *l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2680 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2681 // [let] varname =<< [trim] {end} |
33988
7c30841c60a0
patch 9.0.2180: POSIX function name in exarg causes issues
Christian Brabandt <cb@256bit.org>
parents:
33951
diff
changeset
|
2682 eap->ea_getline = exarg_getline; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2683 eap->cookie = cctx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2684 l = heredoc_get(eap, op + 3, FALSE, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2685 if (l == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2686 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2687 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2688 list_free(l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2689 p += STRLEN(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2690 end = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2691 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2692 else if (var_count > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2693 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2694 char_u *wp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2695 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2696 // for "[var, var] = expr" evaluate the expression here, loop over the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2697 // list of variables below. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2698 // A line break may follow the "=". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2699 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2700 wp = op + oplen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2701 if (may_get_next_line_error(wp, &p, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2702 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2703 if (compile_expr0(&p, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2704 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2705 end = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2706 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2707 if (cctx->ctx_skip != SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2708 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2709 type_T *stacktype; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2710 int needed_list_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2711 int did_check = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2712 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2713 stacktype = cctx->ctx_type_stack.ga_len == 0 ? &t_void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2714 : get_type_on_stack(cctx, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2715 if (stacktype->tt_type == VAR_VOID) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2716 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2717 emsg(_(e_cannot_use_void_value)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2718 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2719 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2720 if (need_type(stacktype, &t_list_any, FALSE, -1, 0, cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2721 FALSE, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2722 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2723 // If a constant list was used we can check the length right here. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2724 needed_list_len = semicolon ? var_count - 1 : var_count; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2725 if (instr->ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2726 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2727 isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2728 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2729 if (isn->isn_type == ISN_NEWLIST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2730 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2731 did_check = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2732 if (semicolon ? isn->isn_arg.number < needed_list_len |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2733 : isn->isn_arg.number != needed_list_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2734 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2735 semsg(_(e_expected_nr_items_but_got_nr), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2736 needed_list_len, (int)isn->isn_arg.number); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2737 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2738 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2739 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2740 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2741 if (!did_check) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2742 generate_CHECKLEN(cctx, needed_list_len, semicolon); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2743 if (stacktype->tt_member != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2744 rhs_type = stacktype->tt_member; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2745 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2746 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2747 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2748 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2749 * Loop over variables in "[var, var] = expr". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2750 * For "var = expr" and "let var: type" this is done only once. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2751 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2752 if (var_count > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2753 var_start = skipwhite(arg + 1); // skip over the "[" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2754 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2755 var_start = arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2756 for (var_idx = 0; var_idx == 0 || var_idx < var_count; var_idx++) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2757 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2758 int instr_count = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2759 int save_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2760 int skip_store = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2761 type_T *inferred_type = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2762 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2763 if (var_start[0] == '_' && !eval_isnamec(var_start[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2764 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2765 // Ignore underscore in "[a, _, b] = list". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2766 if (var_count > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2767 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2768 var_start = skipwhite(var_start + 2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2769 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2770 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2771 emsg(_(e_cannot_use_underscore_here)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2772 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2773 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2774 vim_free(lhs.lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2775 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2776 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2777 * Figure out the LHS type and other properties. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2778 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2779 if (compile_assign_lhs(var_start, &lhs, cmdidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2780 is_decl, heredoc, var_start > eap->cmd, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2781 oplen, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2782 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2783 if (heredoc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2784 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2785 SOURCING_LNUM = start_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2786 if (lhs.lhs_has_type |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2787 && need_type(&t_list_string, lhs.lhs_type, FALSE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2788 -1, 0, cctx, FALSE, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2789 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2790 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2791 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2792 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2793 if (cctx->ctx_skip == SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2794 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2795 if (oplen > 0 && var_count == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2796 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2797 // skip over the "=" and the expression |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2798 p = skipwhite(op + oplen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2799 (void)compile_expr0(&p, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2800 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2801 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2802 else if (oplen > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2803 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2804 int is_const = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2805 char_u *wp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2806 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2807 // for "+=", "*=", "..=" etc. first load the current value |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2808 if (*op != '=' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2809 && compile_load_lhs_with_index(&lhs, var_start, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2810 cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2811 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2812 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2813 // For "var = expr" evaluate the expression. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2814 if (var_count == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2815 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2816 int r; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2817 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2818 // Compile the expression. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2819 instr_count = instr->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2820 if (incdec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2821 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2822 r = generate_PUSHNR(cctx, 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2823 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2824 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2825 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2826 // Temporarily hide the new local variable here, it is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2827 // not available to this expression. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2828 if (lhs.lhs_new_local) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2829 --cctx->ctx_locals.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2830 wp = op + oplen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2831 if (may_get_next_line_error(wp, &p, cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2832 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2833 if (lhs.lhs_new_local) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2834 ++cctx->ctx_locals.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2835 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2836 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2837 r = compile_expr0_ext(&p, cctx, &is_const); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2838 if (lhs.lhs_new_local) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2839 ++cctx->ctx_locals.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2840 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2841 if (r == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2842 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2843 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2844 else if (semicolon && var_idx == var_count - 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2845 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2846 // For "[var; var] = expr" get the rest of the list |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2847 did_generate_slice = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2848 if (generate_SLICE(cctx, var_count - 1) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2849 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2850 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2851 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2852 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2853 // For "[var, var] = expr" get the "var_idx" item from the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2854 // list. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2855 if (generate_GETITEM(cctx, var_idx, *op != '=') == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2856 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2857 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2858 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2859 rhs_type = cctx->ctx_type_stack.ga_len == 0 ? &t_void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2860 : get_type_on_stack(cctx, 0); |
33913
a259471e74fe
patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents:
33738
diff
changeset
|
2861 if (check_type_is_value(rhs_type) == FAIL) |
a259471e74fe
patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents:
33738
diff
changeset
|
2862 goto theend; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2863 if (lhs.lhs_lvar != NULL && (is_decl || !lhs.lhs_has_type)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2864 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2865 if ((rhs_type->tt_type == VAR_FUNC |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2866 || rhs_type->tt_type == VAR_PARTIAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2867 && !lhs.lhs_has_index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2868 && var_wrong_func_name(lhs.lhs_name, TRUE)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2869 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2870 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2871 if (lhs.lhs_new_local && !lhs.lhs_has_type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2872 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2873 if (rhs_type->tt_type == VAR_VOID) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2874 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2875 emsg(_(e_cannot_use_void_value)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2876 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2877 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2878 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2879 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2880 type_T *type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2881 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2882 // An empty list or dict has a &t_unknown member, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2883 // for a variable that implies &t_any. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2884 if (rhs_type == &t_list_empty) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2885 type = &t_list_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2886 else if (rhs_type == &t_dict_empty) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2887 type = &t_dict_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2888 else if (rhs_type == &t_unknown) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2889 type = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2890 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2891 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2892 type = rhs_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2893 inferred_type = rhs_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2894 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2895 set_var_type(lhs.lhs_lvar, type, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2896 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2897 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2898 else if (*op == '=') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2899 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2900 type_T *use_type = lhs.lhs_lvar->lv_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2901 where_T where = WHERE_INIT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2902 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2903 // Without operator check type here, otherwise below. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2904 // Use the line number of the assignment. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2905 SOURCING_LNUM = start_lnum; |
32863
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2906 if (var_count > 0) |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2907 { |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2908 where.wt_index = var_idx + 1; |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2909 where.wt_kind = WT_VARIABLE; |
a39314fa9495
patch 9.0.1741: No type checking in interfaces
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2910 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2911 // If assigning to a list or dict member, use the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2912 // member type. Not for "list[:] =". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2913 if (lhs.lhs_has_index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2914 && !has_list_index(var_start + lhs.lhs_varlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2915 cctx)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2916 use_type = lhs.lhs_member_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2917 if (need_type_where(rhs_type, use_type, FALSE, -1, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2918 where, cctx, FALSE, is_const) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2919 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2920 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2921 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2922 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2923 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2924 type_T *lhs_type = lhs.lhs_member_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2925 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2926 // Special case: assigning to @# can use a number or a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2927 // string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2928 // Also: can assign a number to a float. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2929 if ((lhs_type == &t_number_or_string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2930 || lhs_type == &t_float) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2931 && rhs_type->tt_type == VAR_NUMBER) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2932 lhs_type = &t_number; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2933 if (*p != '=' && need_type(rhs_type, lhs_type, FALSE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2934 -1, 0, cctx, FALSE, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2935 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2936 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2937 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2938 else if (cmdidx == CMD_final) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2939 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2940 emsg(_(e_final_requires_a_value)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2941 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2942 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2943 else if (cmdidx == CMD_const) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2944 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2945 emsg(_(e_const_requires_a_value)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2946 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2947 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2948 else if (!lhs.lhs_has_type || lhs.lhs_dest == dest_option |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2949 || lhs.lhs_dest == dest_func_option) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2950 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2951 emsg(_(e_type_or_initialization_required)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2952 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2953 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2954 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2955 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2956 // variables are always initialized |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2957 if (GA_GROW_FAILS(instr, 1)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2958 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2959 instr_count = instr->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2960 int r = push_default_value(cctx, lhs.lhs_member_type->tt_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2961 lhs.lhs_dest == dest_local, &skip_store); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2962 if (r == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2963 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2964 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2965 if (var_count == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2966 end = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2967 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2968 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2969 // no need to parse more when skipping |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2970 if (cctx->ctx_skip == SKIP_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2971 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2972 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2973 if (oplen > 0 && *op != '=') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2974 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2975 type_T *expected; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2976 type_T *stacktype = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2977 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2978 if (*op == '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2979 { |
34957
3cacfb652766
patch 9.1.0335: String interpolation fails for List type
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
2980 if (may_generate_2STRING(-1, TOSTRING_NONE, cctx) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2981 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2982 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2983 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2984 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2985 expected = lhs.lhs_member_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2986 stacktype = get_type_on_stack(cctx, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2987 if ( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2988 // If variable is float operation with number is OK. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2989 !(expected == &t_float && (stacktype == &t_number |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2990 || stacktype == &t_number_bool)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2991 && need_type(stacktype, expected, TRUE, -1, 0, cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2992 FALSE, FALSE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2993 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2994 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2995 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2996 if (*op == '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2997 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2998 if (generate_CONCAT(cctx, 2) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2999 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3000 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3001 else if (*op == '+') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3002 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3003 if (generate_add_instr(cctx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3004 operator_type(lhs.lhs_member_type, stacktype), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3005 lhs.lhs_member_type, stacktype, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3006 EXPR_APPEND) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3007 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3008 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3009 else if (generate_two_op(cctx, op) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3010 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3011 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3012 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3013 // Use the line number of the assignment for store instruction. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3014 save_lnum = cctx->ctx_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3015 cctx->ctx_lnum = start_lnum - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3016 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3017 if (lhs.lhs_has_index) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3018 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3019 // Use the info in "lhs" to store the value at the index in the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3020 // list, dict or object. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3021 if (compile_assign_unlet(var_start, &lhs, TRUE, rhs_type, cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3022 == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3023 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3024 cctx->ctx_lnum = save_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3025 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3026 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3027 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3028 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3029 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3030 if (is_decl && cmdidx == CMD_const && (lhs.lhs_dest == dest_script |
35037
5df4ad0a5200
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Christian Brabandt <cb@256bit.org>
parents:
35032
diff
changeset
|
3031 || lhs.lhs_dest == dest_script_v9 |
5df4ad0a5200
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Christian Brabandt <cb@256bit.org>
parents:
35032
diff
changeset
|
3032 || lhs.lhs_dest == dest_global |
5df4ad0a5200
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Christian Brabandt <cb@256bit.org>
parents:
35032
diff
changeset
|
3033 || lhs.lhs_dest == dest_local)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3034 // ":const var": lock the value, but not referenced variables |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3035 generate_LOCKCONST(cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3036 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3037 if ((lhs.lhs_type->tt_type == VAR_DICT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3038 || lhs.lhs_type->tt_type == VAR_LIST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3039 && lhs.lhs_type->tt_member != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3040 && lhs.lhs_type->tt_member != &t_any |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3041 && lhs.lhs_type->tt_member != &t_unknown) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3042 // Set the type in the list or dict, so that it can be checked, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3043 // also in legacy script. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3044 generate_SETTYPE(cctx, lhs.lhs_type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3045 else if (inferred_type != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3046 && (inferred_type->tt_type == VAR_DICT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3047 || inferred_type->tt_type == VAR_LIST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3048 && inferred_type->tt_member != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3049 && inferred_type->tt_member != &t_unknown |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3050 && inferred_type->tt_member != &t_any) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3051 // Set the type in the list or dict, so that it can be checked, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3052 // also in legacy script. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3053 generate_SETTYPE(cctx, inferred_type); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3054 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3055 if (!skip_store && generate_store_lhs(cctx, &lhs, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3056 instr_count, is_decl) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3057 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3058 cctx->ctx_lnum = save_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3059 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3060 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3061 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3062 cctx->ctx_lnum = save_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3063 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3064 if (var_idx + 1 < var_count) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3065 var_start = skipwhite(lhs.lhs_end + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3066 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3067 if (has_arg_is_set_prefix) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3068 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3069 // set instruction index in JUMP_IF_ARG_SET to here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3070 isn_T *isn = ((isn_T *)instr->ga_data) + jump_instr_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3071 isn->isn_arg.jumparg.jump_where = instr->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3072 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3073 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3074 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3075 // For "[var, var] = expr" drop the "expr" value. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3076 // Also for "[var, var; _] = expr". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3077 if (var_count > 0 && (!semicolon || !did_generate_slice)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3078 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3079 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3080 goto theend; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3081 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3082 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3083 ret = skipwhite(end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3084 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3085 theend: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3086 vim_free(lhs.lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3087 return ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3088 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3089 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3090 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3091 * Check for an assignment at "eap->cmd", compile it if found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3092 * Return NOTDONE if there is none, FAIL for failure, OK if done. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3093 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3094 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3095 may_compile_assignment(exarg_T *eap, char_u **line, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3096 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3097 char_u *pskip; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3098 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3099 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3100 // Assuming the command starts with a variable or function name, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3101 // find what follows. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3102 // Skip over "var.member", "var[idx]" and the like. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3103 // Also "&opt = val", "$ENV = val" and "@r = val". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3104 pskip = (*eap->cmd == '&' || *eap->cmd == '$' || *eap->cmd == '@') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3105 ? eap->cmd + 1 : eap->cmd; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3106 p = to_name_end(pskip, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3107 if (p > eap->cmd && *p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3108 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3109 char_u *var_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3110 int oplen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3111 int heredoc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3112 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3113 if (eap->cmd[0] == '@') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3114 var_end = eap->cmd + 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3115 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3116 var_end = find_name_end(pskip, NULL, NULL, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3117 FNE_CHECK_START | FNE_INCL_BR); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3118 oplen = assignment_len(skipwhite(var_end), &heredoc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3119 if (oplen > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3120 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3121 size_t len = p - eap->cmd; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3122 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3123 // Recognize an assignment if we recognize the variable |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3124 // name: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3125 // "&opt = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3126 // "$ENV = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3127 // "@r = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3128 // "g:var = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3129 // "g:[key] = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3130 // "local = expr" where "local" is a local var. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3131 // "script = expr" where "script" is a script-local var. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3132 // "import = expr" where "import" is an imported var |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3133 if (*eap->cmd == '&' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3134 || *eap->cmd == '$' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3135 || *eap->cmd == '@' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3136 || ((len) > 2 && eap->cmd[1] == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3137 || STRNCMP(eap->cmd, "g:[", 3) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3138 || variable_exists(eap->cmd, len, cctx)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3139 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3140 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3141 if (*line == NULL || *line == eap->cmd) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3142 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3143 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3144 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3145 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3146 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3147 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3148 // might be "[var, var] = expr" or "ifargisset this.member = expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3149 if (*eap->cmd == '[' || STRNCMP(eap->cmd, "ifargisset ", 11) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3150 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3151 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3152 if (*line == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3153 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3154 if (*line != eap->cmd) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3155 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3156 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3157 return NOTDONE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3158 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3159 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3160 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3161 * Check if arguments of "ufunc" shadow variables in "cctx". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3162 * Return OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3163 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3164 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3165 check_args_shadowing(ufunc_T *ufunc, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3166 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3167 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3168 char_u *arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3169 int r = OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3170 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3171 // Make sure arguments are not found when compiling a second time. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3172 ufunc->uf_args_visible = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3173 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3174 // Check for arguments shadowing variables from the context. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3175 for (i = 0; i < ufunc->uf_args.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3176 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3177 arg = ((char_u **)(ufunc->uf_args.ga_data))[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3178 if (check_defined(arg, STRLEN(arg), cctx, NULL, TRUE) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3179 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3180 r = FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3181 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3182 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3183 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3184 ufunc->uf_args_visible = ufunc->uf_args.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3185 return r; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3186 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3187 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3188 #ifdef HAS_MESSAGE_WINDOW |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3189 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3190 * Get a count before a command. Can only be a number. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3191 * Returns zero if there is no count. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3192 * Returns -1 if there is something wrong. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3193 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3194 static long |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3195 get_cmd_count(char_u *line, exarg_T *eap) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3196 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3197 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3198 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3199 // skip over colons and white space |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3200 for (p = line; *p == ':' || VIM_ISWHITE(*p); ++p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3201 ; |
34074
1629cc65d78d
patch 9.1.0006: is*() and to*() function may be unsafe
Christian Brabandt <cb@256bit.org>
parents:
34006
diff
changeset
|
3202 if (!SAFE_isdigit(*p)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3203 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3204 // The command or modifiers must be following. Assume a lower case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3205 // character means there is a modifier. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3206 if (p < eap->cmd && !vim_islower(*p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3207 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3208 emsg(_(e_invalid_range)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3209 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3210 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3211 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3212 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3213 return atol((char *)p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3214 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3215 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3216 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3217 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3218 * Get the compilation type that should be used for "ufunc". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3219 * Keep in sync with INSTRUCTIONS(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3220 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3221 compiletype_T |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3222 get_compile_type(ufunc_T *ufunc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3223 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3224 // Update uf_has_breakpoint if needed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3225 update_has_breakpoint(ufunc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3226 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3227 if (debug_break_level > 0 || may_break_in_function(ufunc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3228 return CT_DEBUG; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3229 #ifdef FEAT_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3230 if (do_profiling == PROF_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3231 { |
33119
bede81965821
patch 9.0.1842: Need more accurate profiling
Christian Brabandt <cb@256bit.org>
parents:
33109
diff
changeset
|
3232 if (!ufunc->uf_profiling && has_profiling(FALSE, ufunc->uf_name, NULL, |
bede81965821
patch 9.0.1842: Need more accurate profiling
Christian Brabandt <cb@256bit.org>
parents:
33109
diff
changeset
|
3233 &ufunc->uf_hash)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3234 func_do_profile(ufunc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3235 if (ufunc->uf_profiling) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3236 return CT_PROFILE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3237 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3238 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3239 return CT_NONE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3240 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3241 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3242 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3243 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3244 * Add a function to the list of :def functions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3245 * This sets "ufunc->uf_dfunc_idx" but the function isn't compiled yet. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3246 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3247 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3248 add_def_function(ufunc_T *ufunc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3249 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3250 dfunc_T *dfunc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3251 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3252 if (def_functions.ga_len == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3253 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3254 // The first position is not used, so that a zero uf_dfunc_idx means it |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3255 // wasn't set. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3256 if (GA_GROW_FAILS(&def_functions, 1)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3257 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3258 ++def_functions.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3259 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3260 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3261 // Add the function to "def_functions". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3262 if (GA_GROW_FAILS(&def_functions, 1)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3263 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3264 dfunc = ((dfunc_T *)def_functions.ga_data) + def_functions.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3265 CLEAR_POINTER(dfunc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3266 dfunc->df_idx = def_functions.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3267 ufunc->uf_dfunc_idx = dfunc->df_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3268 dfunc->df_ufunc = ufunc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3269 dfunc->df_name = vim_strsave(ufunc->uf_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3270 ga_init2(&dfunc->df_var_names, sizeof(char_u *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3271 ++dfunc->df_refcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3272 ++def_functions.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3273 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3274 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3275 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3276 /* |
35044
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3277 * For an object constructor, generate instruction to setup "this" (the first |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3278 * local variable) and to initialize the object variables. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3279 */ |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3280 static int |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3281 obj_constructor_prologue(ufunc_T *ufunc, cctx_T *cctx) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3282 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3283 generate_CONSTRUCT(cctx, ufunc->uf_class); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3284 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3285 for (int i = 0; i < ufunc->uf_class->class_obj_member_count; ++i) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3286 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3287 ocmember_T *m = &ufunc->uf_class->class_obj_members[i]; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3288 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3289 if (i < 2 && IS_ENUM(ufunc->uf_class)) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3290 // The first two object variables in an enum are the name |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3291 // and the ordinal. These are set by the ISN_CONSTRUCT |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3292 // instruction. So don't generate instructions to set |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3293 // these variables. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3294 continue; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3295 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3296 if (m->ocm_init != NULL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3297 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3298 char_u *expr = m->ocm_init; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3299 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3300 if (compile_expr0(&expr, cctx) == FAIL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3301 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3302 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3303 if (!ends_excmd2(m->ocm_init, expr)) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3304 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3305 semsg(_(e_trailing_characters_str), expr); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3306 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3307 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3308 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3309 type_T *type = get_type_on_stack(cctx, 0); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3310 if (m->ocm_type->tt_type == VAR_ANY |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3311 && !(m->ocm_flags & OCMFLAG_HAS_TYPE) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3312 && type->tt_type != VAR_SPECIAL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3313 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3314 // If the member variable type is not yet set, then use |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3315 // the initialization expression type. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3316 m->ocm_type = type; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3317 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3318 else if (m->ocm_type->tt_type != type->tt_type) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3319 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3320 // The type of the member initialization expression is |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3321 // determined at run time. Add a runtime type check. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3322 where_T where = WHERE_INIT; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3323 where.wt_kind = WT_MEMBER; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3324 where.wt_func_name = (char *)m->ocm_name; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3325 if (need_type_where(type, m->ocm_type, FALSE, -1, |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3326 where, cctx, FALSE, FALSE) == FAIL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3327 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3328 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3329 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3330 else |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3331 push_default_value(cctx, m->ocm_type->tt_type, FALSE, NULL); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3332 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3333 generate_STORE_THIS(cctx, i); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3334 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3335 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3336 return OK; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3337 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3338 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3339 /* |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3340 * For an object method and an constructor, generate instruction to setup |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3341 * "this" (the first local variable). For a constructor, generate instructions |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3342 * to initialize the object variables. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3343 */ |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3344 static int |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3345 obj_method_prologue(ufunc_T *ufunc, cctx_T *cctx) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3346 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3347 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + ufunc->uf_dfunc_idx; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3348 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3349 if (GA_GROW_FAILS(&dfunc->df_var_names, 1)) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3350 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3351 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3352 ((char_u **)dfunc->df_var_names.ga_data)[0] = |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3353 vim_strsave((char_u *)"this"); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3354 ++dfunc->df_var_names.ga_len; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3355 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3356 // In the constructor allocate memory for the object and initialize the |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3357 // object members. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3358 if (IS_CONSTRUCTOR_METHOD(ufunc)) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3359 return obj_constructor_prologue(ufunc, cctx); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3360 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3361 return OK; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3362 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3363 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3364 /* |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3365 * Produce instructions for the default values of optional arguments. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3366 */ |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3367 static int |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3368 compile_def_function_default_args( |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3369 ufunc_T *ufunc, |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3370 cctx_T *cctx, |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3371 garray_T *instr) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3372 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3373 int count = ufunc->uf_def_args.ga_len; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3374 int first_def_arg = ufunc->uf_args.ga_len - count; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3375 int i; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3376 int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3377 int did_set_arg_type = FALSE; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3378 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3379 // Produce instructions for the default values of optional arguments. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3380 SOURCING_LNUM = 0; // line number unknown |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3381 for (i = 0; i < count; ++i) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3382 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3383 char_u *arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i]; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3384 if (STRCMP(arg, "v:none") == 0) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3385 // "arg = v:none" means the argument is optional without |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3386 // setting a value when the argument is missing. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3387 continue; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3388 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3389 type_T *val_type; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3390 int arg_idx = first_def_arg + i; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3391 where_T where = WHERE_INIT; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3392 int jump_instr_idx = instr->ga_len; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3393 isn_T *isn; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3394 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3395 // Use a JUMP_IF_ARG_SET instruction to skip if the value was given. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3396 if (generate_JUMP_IF_ARG(cctx, ISN_JUMP_IF_ARG_SET, |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3397 i - count - off) == FAIL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3398 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3399 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3400 // Make sure later arguments are not found. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3401 ufunc->uf_args_visible = arg_idx; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3402 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3403 int r = compile_expr0(&arg, cctx); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3404 if (r == FAIL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3405 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3406 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3407 // If no type specified use the type of the default value. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3408 // Otherwise check that the default value type matches the |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3409 // specified type. |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3410 val_type = get_type_on_stack(cctx, 0); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3411 where.wt_index = arg_idx + 1; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3412 where.wt_kind = WT_ARGUMENT; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3413 if (ufunc->uf_arg_types[arg_idx] == &t_unknown) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3414 { |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3415 did_set_arg_type = TRUE; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3416 ufunc->uf_arg_types[arg_idx] = val_type; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3417 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3418 else if (need_type_where(val_type, ufunc->uf_arg_types[arg_idx], |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3419 FALSE, -1, where, cctx, FALSE, FALSE) == FAIL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3420 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3421 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3422 if (generate_STORE(cctx, ISN_STORE, i - count - off, NULL) == FAIL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3423 return FAIL; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3424 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3425 // set instruction index in JUMP_IF_ARG_SET to here |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3426 isn = ((isn_T *)instr->ga_data) + jump_instr_idx; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3427 isn->isn_arg.jumparg.jump_where = instr->ga_len; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3428 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3429 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3430 if (did_set_arg_type) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3431 set_function_type(ufunc); |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3432 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3433 return OK; |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3434 } |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3435 |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
3436 /* |
35032
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3437 * Compile def function body. Loop over all the lines in the function and |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3438 * generate instructions. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3439 */ |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3440 static int |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3441 compile_def_function_body( |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3442 cctx_T *cctx, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3443 int last_func_lnum, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3444 int check_return_type, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3445 garray_T *lines_to_free, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3446 char **errormsg) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3447 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3448 char_u *line = NULL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3449 char_u *p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3450 int did_emsg_before = did_emsg; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3451 #ifdef FEAT_PROFILE |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3452 int prof_lnum = -1; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3453 #endif |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3454 int debug_lnum = -1; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3455 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3456 for (;;) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3457 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3458 exarg_T ea; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3459 int starts_with_colon = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3460 char_u *cmd; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3461 cmdmod_T local_cmdmod; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3462 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3463 // Bail out on the first error to avoid a flood of errors and report |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3464 // the right line number when inside try/catch. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3465 if (did_emsg_before != did_emsg) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3466 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3467 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3468 if (line != NULL && *line == '|') |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3469 // the line continues after a '|' |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3470 ++line; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3471 else if (line != NULL && *skipwhite(line) != NUL |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3472 && !(*line == '#' && (line == cctx->ctx_line_start |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3473 || VIM_ISWHITE(line[-1])))) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3474 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3475 semsg(_(e_trailing_characters_str), line); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3476 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3477 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3478 else if (line != NULL && vim9_bad_comment(skipwhite(line))) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3479 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3480 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3481 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3482 line = next_line_from_context(cctx, FALSE); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3483 if (cctx->ctx_lnum >= last_func_lnum) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3484 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3485 // beyond the last line |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3486 #ifdef FEAT_PROFILE |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3487 if (cctx->ctx_skip != SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3488 may_generate_prof_end(cctx, prof_lnum); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3489 #endif |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3490 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3491 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3492 // Make a copy, splitting off nextcmd and removing trailing spaces |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3493 // may change it. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3494 if (line != NULL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3495 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3496 line = vim_strsave(line); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3497 if (ga_add_string(lines_to_free, line) == FAIL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3498 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3499 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3500 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3501 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3502 CLEAR_FIELD(ea); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3503 ea.cmdlinep = &line; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3504 ea.cmd = skipwhite(line); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3505 ea.skip = cctx->ctx_skip == SKIP_YES; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3506 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3507 if (*ea.cmd == '#') |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3508 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3509 // "#" starts a comment, but "#{" is an error |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3510 if (vim9_bad_comment(ea.cmd)) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3511 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3512 line = (char_u *)""; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3513 continue; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3514 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3515 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3516 #ifdef FEAT_PROFILE |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3517 if (cctx->ctx_compile_type == CT_PROFILE && cctx->ctx_lnum != prof_lnum |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3518 && cctx->ctx_skip != SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3519 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3520 may_generate_prof_end(cctx, prof_lnum); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3521 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3522 prof_lnum = cctx->ctx_lnum; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3523 generate_instr(cctx, ISN_PROF_START); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3524 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3525 #endif |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3526 if (cctx->ctx_compile_type == CT_DEBUG && cctx->ctx_lnum != debug_lnum |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3527 && cctx->ctx_skip != SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3528 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3529 debug_lnum = cctx->ctx_lnum; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3530 generate_instr_debug(cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3531 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3532 cctx->ctx_prev_lnum = cctx->ctx_lnum + 1; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3533 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3534 // Some things can be recognized by the first character. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3535 switch (*ea.cmd) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3536 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3537 case '}': |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3538 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3539 // "}" ends a block scope |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3540 scopetype_T stype = cctx->ctx_scope == NULL |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3541 ? NO_SCOPE : cctx->ctx_scope->se_type; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3542 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3543 if (stype == BLOCK_SCOPE) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3544 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3545 compile_endblock(cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3546 line = ea.cmd; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3547 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3548 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3549 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3550 emsg(_(e_using_rcurly_outside_if_block_scope)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3551 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3552 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3553 if (line != NULL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3554 line = skipwhite(ea.cmd + 1); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3555 continue; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3556 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3557 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3558 case '{': |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3559 // "{" starts a block scope |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3560 // "{'a': 1}->func() is something else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3561 if (ends_excmd(*skipwhite(ea.cmd + 1))) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3562 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3563 line = compile_block(ea.cmd, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3564 continue; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3565 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3566 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3567 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3568 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3569 /* |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3570 * COMMAND MODIFIERS |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3571 */ |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3572 cctx->ctx_has_cmdmod = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3573 if (parse_command_modifiers(&ea, errormsg, &local_cmdmod, FALSE) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3574 == FAIL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3575 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3576 generate_cmdmods(cctx, &local_cmdmod); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3577 undo_cmdmod(&local_cmdmod); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3578 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3579 // Check if there was a colon after the last command modifier or before |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3580 // the current position. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3581 for (p = ea.cmd; p >= line; --p) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3582 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3583 if (*p == ':') |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3584 starts_with_colon = TRUE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3585 if (p < ea.cmd && !VIM_ISWHITE(*p)) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3586 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3587 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3588 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3589 // Skip ":call" to get to the function name, unless using :legacy |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3590 p = ea.cmd; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3591 if (!(local_cmdmod.cmod_flags & CMOD_LEGACY)) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3592 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3593 if (checkforcmd(&ea.cmd, "call", 3)) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3594 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3595 if (*ea.cmd == '(') |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3596 // not for "call()" |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3597 ea.cmd = p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3598 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3599 ea.cmd = skipwhite(ea.cmd); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3600 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3601 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3602 if (!starts_with_colon) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3603 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3604 int assign; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3605 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3606 // Check for assignment after command modifiers. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3607 assign = may_compile_assignment(&ea, &line, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3608 if (assign == OK) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3609 goto nextline; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3610 if (assign == FAIL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3611 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3612 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3613 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3614 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3615 /* |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3616 * COMMAND after range |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3617 * 'text'->func() should not be confused with 'a mark |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3618 * 0z1234->func() should not be confused with a zero line number |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3619 * "++nr" and "--nr" are eval commands |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3620 * in "$ENV->func()" the "$" is not a range |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3621 * "123->func()" is a method call |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3622 */ |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3623 cmd = ea.cmd; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3624 if ((*cmd != '$' || starts_with_colon) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3625 && (starts_with_colon |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3626 || !(*cmd == '\'' |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3627 || (cmd[0] == '0' && cmd[1] == 'z') |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3628 || (cmd[0] != NUL && cmd[0] == cmd[1] |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3629 && (*cmd == '+' || *cmd == '-')) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3630 || number_method(cmd)))) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3631 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3632 ea.cmd = skip_range(ea.cmd, TRUE, NULL); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3633 if (ea.cmd > cmd) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3634 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3635 if (!starts_with_colon |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3636 && !(local_cmdmod.cmod_flags & CMOD_LEGACY)) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3637 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3638 semsg(_(e_colon_required_before_range_str), cmd); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3639 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3640 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3641 ea.addr_count = 1; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3642 if (ends_excmd2(line, ea.cmd)) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3643 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3644 // A range without a command: jump to the line. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3645 generate_EXEC(cctx, ISN_EXECRANGE, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3646 vim_strnsave(cmd, ea.cmd - cmd)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3647 line = ea.cmd; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3648 goto nextline; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3649 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3650 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3651 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3652 p = find_ex_command(&ea, NULL, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3653 starts_with_colon || (local_cmdmod.cmod_flags & CMOD_LEGACY) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3654 ? NULL : item_exists, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3655 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3656 if (p == NULL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3657 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3658 if (cctx->ctx_skip != SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3659 semsg(_(e_ambiguous_use_of_user_defined_command_str), ea.cmd); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3660 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3661 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3662 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3663 // When using ":legacy cmd" always use compile_exec(). |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3664 if (local_cmdmod.cmod_flags & CMOD_LEGACY) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3665 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3666 char_u *start = ea.cmd; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3667 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3668 switch (ea.cmdidx) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3669 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3670 case CMD_if: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3671 case CMD_elseif: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3672 case CMD_else: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3673 case CMD_endif: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3674 case CMD_for: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3675 case CMD_endfor: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3676 case CMD_continue: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3677 case CMD_break: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3678 case CMD_while: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3679 case CMD_endwhile: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3680 case CMD_try: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3681 case CMD_catch: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3682 case CMD_finally: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3683 case CMD_endtry: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3684 semsg(_(e_cannot_use_legacy_with_command_str), ea.cmd); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3685 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3686 default: break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3687 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3688 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3689 // ":legacy return expr" needs to be handled differently. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3690 if (checkforcmd(&start, "return", 4)) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3691 ea.cmdidx = CMD_return; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3692 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3693 ea.cmdidx = CMD_legacy; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3694 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3695 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3696 if (p == ea.cmd && ea.cmdidx != CMD_SIZE) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3697 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3698 // "eval" is used for "val->func()" and "var" for "var = val", then |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3699 // "p" is equal to "ea.cmd" for a valid command. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3700 if (ea.cmdidx == CMD_eval || ea.cmdidx == CMD_var) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3701 ; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3702 else if (cctx->ctx_skip == SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3703 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3704 line += STRLEN(line); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3705 goto nextline; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3706 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3707 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3708 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3709 semsg(_(e_command_not_recognized_str), ea.cmd); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3710 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3711 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3712 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3713 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3714 if ((cctx->ctx_had_return || cctx->ctx_had_throw) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3715 && ea.cmdidx != CMD_elseif |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3716 && ea.cmdidx != CMD_else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3717 && ea.cmdidx != CMD_endif |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3718 && ea.cmdidx != CMD_endfor |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3719 && ea.cmdidx != CMD_endwhile |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3720 && ea.cmdidx != CMD_catch |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3721 && ea.cmdidx != CMD_finally |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3722 && ea.cmdidx != CMD_endtry |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3723 && !ignore_unreachable_code_for_testing) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3724 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3725 semsg(_(e_unreachable_code_after_str), |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3726 cctx->ctx_had_return ? "return" : "throw"); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3727 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3728 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3729 cctx->ctx_had_throw = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3730 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3731 p = skipwhite(p); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3732 if (ea.cmdidx != CMD_SIZE |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3733 && ea.cmdidx != CMD_write && ea.cmdidx != CMD_read) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3734 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3735 if (ea.cmdidx >= 0) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3736 ea.argt = excmd_get_argt(ea.cmdidx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3737 if ((ea.argt & EX_BANG) && *p == '!') |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3738 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3739 ea.forceit = TRUE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3740 p = skipwhite(p + 1); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3741 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3742 if ((ea.argt & EX_RANGE) == 0 && ea.addr_count > 0) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3743 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3744 emsg(_(e_no_range_allowed)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3745 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3746 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3747 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3748 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3749 switch (ea.cmdidx) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3750 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3751 case CMD_def: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3752 case CMD_function: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3753 ea.arg = p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3754 line = compile_nested_function(&ea, cctx, lines_to_free); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3755 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3756 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3757 case CMD_return: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3758 line = compile_return(p, check_return_type, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3759 local_cmdmod.cmod_flags & CMOD_LEGACY, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3760 cctx->ctx_had_return = TRUE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3761 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3762 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3763 case CMD_let: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3764 emsg(_(e_cannot_use_let_in_vim9_script)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3765 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3766 case CMD_var: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3767 case CMD_final: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3768 case CMD_const: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3769 case CMD_increment: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3770 case CMD_decrement: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3771 line = compile_assignment(p, &ea, ea.cmdidx, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3772 if (line == p) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3773 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3774 emsg(_(e_invalid_assignment)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3775 line = NULL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3776 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3777 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3778 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3779 case CMD_unlet: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3780 case CMD_unlockvar: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3781 case CMD_lockvar: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3782 line = compile_unletlock(p, &ea, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3783 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3784 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3785 case CMD_import: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3786 emsg(_(e_import_can_only_be_used_in_script)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3787 line = NULL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3788 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3789 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3790 case CMD_if: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3791 line = compile_if(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3792 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3793 case CMD_elseif: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3794 line = compile_elseif(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3795 cctx->ctx_had_return = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3796 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3797 case CMD_else: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3798 line = compile_else(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3799 cctx->ctx_had_return = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3800 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3801 case CMD_endif: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3802 line = compile_endif(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3803 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3804 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3805 case CMD_while: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3806 line = compile_while(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3807 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3808 case CMD_endwhile: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3809 line = compile_endwhile(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3810 cctx->ctx_had_return = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3811 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3812 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3813 case CMD_for: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3814 line = compile_for(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3815 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3816 case CMD_endfor: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3817 line = compile_endfor(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3818 cctx->ctx_had_return = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3819 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3820 case CMD_continue: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3821 line = compile_continue(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3822 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3823 case CMD_break: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3824 line = compile_break(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3825 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3826 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3827 case CMD_try: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3828 line = compile_try(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3829 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3830 case CMD_catch: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3831 line = compile_catch(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3832 cctx->ctx_had_return = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3833 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3834 case CMD_finally: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3835 line = compile_finally(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3836 cctx->ctx_had_return = FALSE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3837 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3838 case CMD_endtry: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3839 line = compile_endtry(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3840 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3841 case CMD_throw: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3842 line = compile_throw(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3843 cctx->ctx_had_throw = TRUE; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3844 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3845 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3846 case CMD_eval: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3847 line = compile_eval(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3848 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3849 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3850 case CMD_defer: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3851 line = compile_defer(p, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3852 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3853 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3854 #ifdef HAS_MESSAGE_WINDOW |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3855 case CMD_echowindow: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3856 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3857 long cmd_count = get_cmd_count(line, &ea); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3858 if (cmd_count < 0) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3859 line = NULL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3860 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3861 line = compile_mult_expr(p, ea.cmdidx, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3862 cmd_count, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3863 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3864 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3865 #endif |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3866 case CMD_echo: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3867 case CMD_echon: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3868 case CMD_echoconsole: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3869 case CMD_echoerr: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3870 case CMD_echomsg: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3871 case CMD_execute: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3872 line = compile_mult_expr(p, ea.cmdidx, 0, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3873 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3874 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3875 case CMD_put: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3876 ea.cmd = cmd; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3877 line = compile_put(p, &ea, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3878 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3879 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3880 case CMD_substitute: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3881 if (check_global_and_subst(ea.cmd, p) == FAIL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3882 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3883 if (cctx->ctx_skip == SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3884 line = (char_u *)""; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3885 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3886 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3887 ea.arg = p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3888 line = compile_substitute(line, &ea, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3889 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3890 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3891 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3892 case CMD_redir: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3893 ea.arg = p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3894 line = compile_redir(line, &ea, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3895 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3896 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3897 case CMD_cexpr: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3898 case CMD_lexpr: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3899 case CMD_caddexpr: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3900 case CMD_laddexpr: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3901 case CMD_cgetexpr: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3902 case CMD_lgetexpr: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3903 #ifdef FEAT_QUICKFIX |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3904 ea.arg = p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3905 line = compile_cexpr(line, &ea, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3906 #else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3907 ex_ni(&ea); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3908 line = NULL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3909 #endif |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3910 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3911 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3912 case CMD_append: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3913 case CMD_change: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3914 case CMD_insert: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3915 case CMD_k: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3916 case CMD_t: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3917 case CMD_xit: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3918 not_in_vim9(&ea); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3919 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3920 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3921 case CMD_SIZE: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3922 if (cctx->ctx_skip != SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3923 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3924 semsg(_(e_invalid_command_str), ea.cmd); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3925 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3926 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3927 // We don't check for a next command here. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3928 line = (char_u *)""; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3929 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3930 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3931 case CMD_lua: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3932 case CMD_mzscheme: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3933 case CMD_perl: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3934 case CMD_py3: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3935 case CMD_python3: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3936 case CMD_python: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3937 case CMD_pythonx: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3938 case CMD_ruby: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3939 case CMD_tcl: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3940 ea.arg = p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3941 if (vim_strchr(line, '\n') == NULL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3942 line = compile_exec(line, &ea, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3943 else |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3944 // heredoc lines have been concatenated with NL |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3945 // characters in get_function_body() |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3946 line = compile_script(line, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3947 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3948 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3949 case CMD_vim9script: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3950 if (cctx->ctx_skip != SKIP_YES) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3951 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3952 emsg(_(e_vim9script_can_only_be_used_in_script)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3953 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3954 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3955 line = (char_u *)""; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3956 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3957 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3958 case CMD_class: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3959 emsg(_(e_class_can_only_be_used_in_script)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3960 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3961 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3962 case CMD_type: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3963 emsg(_(e_type_can_only_be_used_in_script)); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3964 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3965 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3966 case CMD_global: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3967 if (check_global_and_subst(ea.cmd, p) == FAIL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3968 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3969 // FALLTHROUGH |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3970 default: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3971 // Not recognized, execute with do_cmdline_cmd(). |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3972 ea.arg = p; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3973 line = compile_exec(line, &ea, cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3974 break; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3975 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3976 nextline: |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3977 if (line == NULL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3978 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3979 line = skipwhite(line); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3980 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3981 // Undo any command modifiers. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3982 generate_undo_cmdmods(cctx); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3983 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3984 if (cctx->ctx_type_stack.ga_len < 0) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3985 { |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3986 iemsg("Type stack underflow"); |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3987 return FAIL; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3988 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3989 } // END of the loop over all the function body lines. |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3990 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3991 return OK; |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3992 } |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3993 |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
3994 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3995 * After ex_function() has collected all the function lines: parse and compile |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3996 * the lines into instructions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3997 * Adds the function to "def_functions". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3998 * When "check_return_type" is set then set ufunc->uf_ret_type to the type of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3999 * the return statement (used for lambda). When uf_ret_type is already set |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4000 * then check that it matches. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4001 * When "profiling" is true add ISN_PROF_START instructions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4002 * "outer_cctx" is set for a nested function. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4003 * This can be used recursively through compile_lambda(), which may reallocate |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4004 * "def_functions". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4005 * Returns OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4006 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4007 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4008 compile_def_function( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4009 ufunc_T *ufunc, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4010 int check_return_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4011 compiletype_T compile_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4012 cctx_T *outer_cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4013 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4014 garray_T lines_to_free; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4015 char *errormsg = NULL; // error message |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4016 cctx_T cctx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4017 garray_T *instr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4018 int did_emsg_before = did_emsg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4019 int did_emsg_silent_before = did_emsg_silent; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4020 int ret = FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4021 sctx_T save_current_sctx = current_sctx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4022 int save_estack_compiling = estack_compiling; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4023 int save_cmod_flags = cmdmod.cmod_flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4024 int do_estack_push; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4025 int new_def_function = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4026 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4027 // allocated lines are freed at the end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4028 ga_init2(&lines_to_free, sizeof(char_u *), 50); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4029 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4030 // When using a function that was compiled before: Free old instructions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4031 // The index is reused. Otherwise add a new entry in "def_functions". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4032 if (ufunc->uf_dfunc_idx > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4033 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4034 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4035 + ufunc->uf_dfunc_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4036 isn_T *instr_dest = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4037 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4038 switch (compile_type) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4039 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4040 case CT_PROFILE: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4041 #ifdef FEAT_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4042 instr_dest = dfunc->df_instr_prof; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4043 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4044 case CT_NONE: instr_dest = dfunc->df_instr; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4045 case CT_DEBUG: instr_dest = dfunc->df_instr_debug; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4046 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4047 if (instr_dest != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4048 // Was compiled in this mode before: Free old instructions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4049 delete_def_function_contents(dfunc, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4050 ga_clear_strings(&dfunc->df_var_names); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4051 dfunc->df_defer_var_idx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4052 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4053 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4054 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4055 if (add_def_function(ufunc) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4056 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4057 new_def_function = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4058 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4059 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4060 if ((ufunc->uf_flags & FC_CLOSURE) && outer_cctx == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4061 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4062 semsg(_(e_compiling_closure_without_context_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4063 printable_func_name(ufunc)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4064 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4065 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4066 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4067 ufunc->uf_def_status = UF_COMPILING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4068 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4069 CLEAR_FIELD(cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4070 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4071 cctx.ctx_compile_type = compile_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4072 cctx.ctx_ufunc = ufunc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4073 cctx.ctx_lnum = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4074 cctx.ctx_outer = outer_cctx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4075 ga_init2(&cctx.ctx_locals, sizeof(lvar_T), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4076 // Each entry on the type stack consists of two type pointers. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4077 ga_init2(&cctx.ctx_type_stack, sizeof(type2_T), 50); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4078 cctx.ctx_type_list = &ufunc->uf_type_list; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4079 ga_init2(&cctx.ctx_instr, sizeof(isn_T), 50); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4080 instr = &cctx.ctx_instr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4081 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4082 // Set the context to the function, it may be compiled when called from |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4083 // another script. Set the script version to the most modern one. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4084 // The line number will be set in next_line_from_context(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4085 current_sctx = ufunc->uf_script_ctx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4086 current_sctx.sc_version = SCRIPT_VERSION_VIM9; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4087 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4088 // Don't use the flag from ":legacy" here. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4089 cmdmod.cmod_flags &= ~CMOD_LEGACY; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4090 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4091 // Make sure error messages are OK. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4092 do_estack_push = !estack_top_is_ufunc(ufunc, 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4093 if (do_estack_push) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4094 estack_push_ufunc(ufunc, 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4095 estack_compiling = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4096 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4097 if (check_args_shadowing(ufunc, &cctx) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4098 goto erret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4099 |
35044
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
4100 // For an object method and a constructor generate instructions to |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
4101 // initialize "this" and the object variables. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4102 if (ufunc->uf_flags & (FC_OBJECT|FC_NEW)) |
35044
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
4103 if (obj_method_prologue(ufunc, &cctx) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4104 goto erret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4105 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4106 if (ufunc->uf_def_args.ga_len > 0) |
35044
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
4107 if (compile_def_function_default_args(ufunc, &cctx, instr) == FAIL) |
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
4108 goto erret; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4109 ufunc->uf_args_visible = ufunc->uf_args.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4110 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4111 // Compiling a function in an interface is done to get the function type. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4112 // No code is actually compiled. |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34618
diff
changeset
|
4113 if (ufunc->uf_class != NULL && IS_INTERFACE(ufunc->uf_class)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4114 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4115 ufunc->uf_def_status = UF_NOT_COMPILED; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4116 ret = OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4117 goto erret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4118 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4119 |
35044
2e492a1539e0
patch 9.1.0371: Vim9: compile_def_function() still too long
Christian Brabandt <cb@256bit.org>
parents:
35037
diff
changeset
|
4120 // compile the function body |
35032
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
4121 if (compile_def_function_body(&cctx, ufunc->uf_lines.ga_len, |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
4122 check_return_type, &lines_to_free, &errormsg) == FAIL) |
eeab9c4c801b
patch 9.1.0367: compile_def_function is too long
Christian Brabandt <cb@256bit.org>
parents:
34957
diff
changeset
|
4123 goto erret; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4124 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4125 if (cctx.ctx_scope != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4126 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4127 if (cctx.ctx_scope->se_type == IF_SCOPE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4128 emsg(_(e_missing_endif)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4129 else if (cctx.ctx_scope->se_type == WHILE_SCOPE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4130 emsg(_(e_missing_endwhile)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4131 else if (cctx.ctx_scope->se_type == FOR_SCOPE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4132 emsg(_(e_missing_endfor)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4133 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4134 emsg(_(e_missing_rcurly)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4135 goto erret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4136 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4137 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4138 // TODO: if a function ends in "throw" but there was a return elsewhere we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4139 // should not assume the return type is "void". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4140 if (!cctx.ctx_had_return && !cctx.ctx_had_throw) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4141 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4142 if (ufunc->uf_ret_type->tt_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4143 ufunc->uf_ret_type = &t_void; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4144 else if (ufunc->uf_ret_type->tt_type != VAR_VOID |
33297
6340c608ca54
patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents:
33286
diff
changeset
|
4145 && !IS_CONSTRUCTOR_METHOD(ufunc)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4146 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4147 emsg(_(e_missing_return_statement)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4148 goto erret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4149 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4150 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4151 // Return void if there is no return at the end. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4152 // For a constructor return the object. |
33297
6340c608ca54
patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents:
33286
diff
changeset
|
4153 if (IS_CONSTRUCTOR_METHOD(ufunc)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4154 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4155 generate_instr(&cctx, ISN_RETURN_OBJECT); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4156 ufunc->uf_ret_type = &ufunc->uf_class->class_object_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4157 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4158 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4159 generate_instr(&cctx, ISN_RETURN_VOID); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4160 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4161 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4162 // When compiled with ":silent!" and there was an error don't consider the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4163 // function compiled. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4164 if (emsg_silent == 0 || did_emsg_silent == did_emsg_silent_before) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4165 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4166 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4167 + ufunc->uf_dfunc_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4168 dfunc->df_deleted = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4169 dfunc->df_script_seq = current_sctx.sc_seq; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4170 #ifdef FEAT_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4171 if (cctx.ctx_compile_type == CT_PROFILE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4172 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4173 dfunc->df_instr_prof = instr->ga_data; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4174 dfunc->df_instr_prof_count = instr->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4175 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4176 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4177 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4178 if (cctx.ctx_compile_type == CT_DEBUG) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4179 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4180 dfunc->df_instr_debug = instr->ga_data; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4181 dfunc->df_instr_debug_count = instr->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4182 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4183 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4184 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4185 dfunc->df_instr = instr->ga_data; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4186 dfunc->df_instr_count = instr->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4187 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4188 dfunc->df_varcount = dfunc->df_var_names.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4189 dfunc->df_has_closure = cctx.ctx_has_closure; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4190 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4191 if (cctx.ctx_outer_used) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4192 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4193 ufunc->uf_flags |= FC_CLOSURE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4194 if (outer_cctx != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4195 ++outer_cctx->ctx_closure_count; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4196 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4197 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4198 ufunc->uf_def_status = UF_COMPILED; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4199 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4200 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4201 ret = OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4202 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4203 erret: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4204 if (ufunc->uf_def_status == UF_COMPILING) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4205 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4206 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4207 + ufunc->uf_dfunc_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4208 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4209 // Compiling aborted, free the generated instructions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4210 clear_instr_ga(instr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4211 VIM_CLEAR(dfunc->df_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4212 ga_clear_strings(&dfunc->df_var_names); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4213 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4214 // If using the last entry in the table and it was added above, we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4215 // might as well remove it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4216 if (!dfunc->df_deleted && new_def_function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4217 && ufunc->uf_dfunc_idx == def_functions.ga_len - 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4218 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4219 --def_functions.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4220 ufunc->uf_dfunc_idx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4221 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4222 ufunc->uf_def_status = UF_COMPILE_ERROR; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4223 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4224 while (cctx.ctx_scope != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4225 drop_scope(&cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4226 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4227 if (errormsg != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4228 emsg(errormsg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4229 else if (did_emsg == did_emsg_before) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4230 emsg(_(e_compiling_def_function_failed)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4231 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4232 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4233 if (cctx.ctx_redir_lhs.lhs_name != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4234 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4235 if (ret == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4236 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4237 emsg(_(e_missing_redir_end)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4238 ret = FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4239 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4240 vim_free(cctx.ctx_redir_lhs.lhs_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4241 vim_free(cctx.ctx_redir_lhs.lhs_whole); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4242 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4243 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4244 current_sctx = save_current_sctx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4245 estack_compiling = save_estack_compiling; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4246 cmdmod.cmod_flags = save_cmod_flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4247 if (do_estack_push) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4248 estack_pop(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4249 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4250 ga_clear_strings(&lines_to_free); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4251 free_locals(&cctx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4252 ga_clear(&cctx.ctx_type_stack); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4253 return ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4254 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4255 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4256 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4257 set_function_type(ufunc_T *ufunc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4258 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4259 int varargs = ufunc->uf_va_name != NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4260 int argcount = ufunc->uf_args.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4261 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4262 // Create a type for the function, with the return type and any |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4263 // argument types. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4264 // A vararg is included in uf_args.ga_len but not in uf_arg_types. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4265 // The type is included in "tt_args". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4266 if (argcount > 0 || varargs) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4267 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4268 if (ufunc->uf_type_list.ga_itemsize == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4269 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4270 ufunc->uf_func_type = alloc_func_type(ufunc->uf_ret_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4271 argcount, &ufunc->uf_type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4272 // Add argument types to the function type. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4273 if (func_type_add_arg_types(ufunc->uf_func_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4274 argcount + varargs, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4275 &ufunc->uf_type_list) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4276 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4277 ufunc->uf_func_type->tt_argcount = argcount + varargs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4278 ufunc->uf_func_type->tt_min_argcount = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4279 argcount - ufunc->uf_def_args.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4280 if (ufunc->uf_arg_types == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4281 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4282 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4283 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4284 // lambda does not have argument types. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4285 for (i = 0; i < argcount; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4286 ufunc->uf_func_type->tt_args[i] = &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4287 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4288 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4289 mch_memmove(ufunc->uf_func_type->tt_args, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4290 ufunc->uf_arg_types, sizeof(type_T *) * argcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4291 if (varargs) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4292 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4293 ufunc->uf_func_type->tt_args[argcount] = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4294 ufunc->uf_va_type == NULL ? &t_list_any : ufunc->uf_va_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4295 ufunc->uf_func_type->tt_flags = TTFLAG_VARARGS; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4296 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4297 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4298 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4299 // No arguments, can use a predefined type. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4300 ufunc->uf_func_type = get_func_type(ufunc->uf_ret_type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4301 argcount, &ufunc->uf_type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4302 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4303 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4304 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4305 * Free all instructions for "dfunc" except df_name. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4306 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4307 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4308 delete_def_function_contents(dfunc_T *dfunc, int mark_deleted) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4309 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4310 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4311 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4312 // In same cases the instructions may refer to a class in which the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4313 // function is defined and unreferencing the class may call back here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4314 // recursively. Set the df_delete_busy to avoid problems. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4315 if (dfunc->df_delete_busy) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4316 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4317 dfunc->df_delete_busy = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4318 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4319 ga_clear(&dfunc->df_def_args_isn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4320 ga_clear_strings(&dfunc->df_var_names); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4321 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4322 if (dfunc->df_instr != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4323 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4324 for (idx = 0; idx < dfunc->df_instr_count; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4325 delete_instr(dfunc->df_instr + idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4326 VIM_CLEAR(dfunc->df_instr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4327 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4328 if (dfunc->df_instr_debug != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4329 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4330 for (idx = 0; idx < dfunc->df_instr_debug_count; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4331 delete_instr(dfunc->df_instr_debug + idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4332 VIM_CLEAR(dfunc->df_instr_debug); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4333 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4334 #ifdef FEAT_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4335 if (dfunc->df_instr_prof != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4336 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4337 for (idx = 0; idx < dfunc->df_instr_prof_count; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4338 delete_instr(dfunc->df_instr_prof + idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4339 VIM_CLEAR(dfunc->df_instr_prof); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4340 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4341 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4342 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4343 if (mark_deleted) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4344 dfunc->df_deleted = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4345 if (dfunc->df_ufunc != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4346 dfunc->df_ufunc->uf_def_status = UF_NOT_COMPILED; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4347 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4348 dfunc->df_delete_busy = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4349 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4350 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4351 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4352 * When a user function is deleted, clear the contents of any associated def |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4353 * function, unless another user function still uses it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4354 * The position in def_functions can be re-used. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4355 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4356 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4357 unlink_def_function(ufunc_T *ufunc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4358 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4359 if (ufunc->uf_dfunc_idx <= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4360 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4361 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4362 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4363 + ufunc->uf_dfunc_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4364 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4365 if (--dfunc->df_refcount <= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4366 delete_def_function_contents(dfunc, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4367 ufunc->uf_def_status = UF_NOT_COMPILED; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4368 ufunc->uf_dfunc_idx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4369 if (dfunc->df_ufunc == ufunc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4370 dfunc->df_ufunc = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4371 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4372 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4373 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4374 * Used when a user function refers to an existing dfunc. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4375 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4376 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4377 link_def_function(ufunc_T *ufunc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4378 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4379 if (ufunc->uf_dfunc_idx <= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4380 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4381 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4382 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4383 + ufunc->uf_dfunc_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4384 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4385 ++dfunc->df_refcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4386 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4387 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4388 #if defined(EXITFREE) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4389 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4390 * Free all functions defined with ":def". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4391 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4392 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4393 free_def_functions(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4394 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4395 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4396 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4397 for (idx = 0; idx < def_functions.ga_len; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4398 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4399 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4400 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4401 delete_def_function_contents(dfunc, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4402 vim_free(dfunc->df_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4403 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4404 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4405 ga_clear(&def_functions); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4406 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4407 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4408 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4409 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4410 #endif // FEAT_EVAL |