annotate src/eval.c @ 28119:57ea74314c1b v8.2.4584

patch 8.2.4584: error for using autoload function in custom completion Commit: https://github.com/vim/vim/commit/da6d42c35a68610af872551b03077047258a7551 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 17 11:46:55 2022 +0000 patch 8.2.4584: error for using autoload function in custom completion Problem: Error for using autoload function in custom completion. Solution: Do not check for errors when using an autoload function. (closes #9962)
author Bram Moolenaar <Bram@vim.org>
date Thu, 17 Mar 2022 13:00:07 +0100
parents 62a57c60edc1
children dd2ed5345f20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 10000
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * eval.c: Expression evaluation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
8295
18fd94bd4eb8 commit https://github.com/vim/vim/commit/fefecb0fbe14c44d46f91036d76bbb6c28162da8
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
13 #define USING_FLOAT_STUFF
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
18
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
19 #ifdef VMS
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
20 # include <float.h>
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
21 #endif
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
22
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
23 #define NAMESPACE_CHAR (char_u *)"abglstvw"
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
24
142
0ef5b70c3eaf updated for version 7.0045
vimboss
parents: 137
diff changeset
25 /*
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
26 * When recursively copying lists and dicts we need to remember which ones we
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
27 * have done to avoid endless recursiveness. This unique ID is used for that.
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
28 * The last bit is used for previous_funccal, ignored when comparing.
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
29 */
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
30 static int current_copyID = 0;
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
31
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 /*
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
33 * Info used by a ":for" loop.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
34 */
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
35 typedef struct
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
36 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
37 int fi_semicolon; // TRUE if ending in '; var]'
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
38 int fi_varcount; // nr of variables in the list
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
39 int fi_break_count; // nr of line breaks encountered
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
40 listwatch_T fi_lw; // keep an eye on the item used.
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
41 list_T *fi_list; // list being used
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
42 int fi_bi; // index of blob
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
43 blob_T *fi_blob; // blob being used
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
44 char_u *fi_string; // copy of string being used
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
45 int fi_byte_idx; // byte index in fi_string
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
46 } forinfo_T;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
47
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
48 static int eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
49 static int eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
50 static int eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
51 static int eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
52 static int eval6(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int want_string);
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
53 static int eval7t(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int want_string);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
54 static int eval7(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int want_string);
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
55 static int eval7_leader(typval_T *rettv, int numeric_only, char_u *start_leader, char_u **end_leaderp);
7720
7c52f11e6df3 commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
56
7c52f11e6df3 commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
57 static int free_unref_items(int copyID);
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
58 static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end);
2247
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
59
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
60 /*
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
61 * Return "n1" divided by "n2", taking care of dividing by zero.
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
62 * If "failed" is not NULL set it to TRUE when dividing by zero fails.
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
63 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
64 varnumber_T
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
65 num_divide(varnumber_T n1, varnumber_T n2, int *failed)
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
66 {
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
67 varnumber_T result;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
68
23673
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
69 if (n2 == 0)
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
70 {
23673
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
71 if (in_vim9script())
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
72 {
23673
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
73 emsg(_(e_divide_by_zero));
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
74 if (failed != NULL)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
75 *failed = TRUE;
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
76 }
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
77 if (n1 == 0)
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
78 result = VARNUM_MIN; // similar to NaN
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
79 else if (n1 < 0)
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
80 result = -VARNUM_MAX;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
81 else
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
82 result = VARNUM_MAX;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
83 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
84 else
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
85 result = n1 / n2;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
86
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
87 return result;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
88 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
89
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
90 /*
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
91 * Return "n1" modulus "n2", taking care of dividing by zero.
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
92 * If "failed" is not NULL set it to TRUE when dividing by zero fails.
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
93 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
94 varnumber_T
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
95 num_modulus(varnumber_T n1, varnumber_T n2, int *failed)
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
96 {
23673
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
97 if (n2 == 0 && in_vim9script())
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
98 {
23673
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
99 emsg(_(e_divide_by_zero));
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
100 if (failed != NULL)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
101 *failed = TRUE;
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
102 }
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
103 return (n2 == 0) ? 0 : (n1 % n2);
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
104 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
105
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
106 /*
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
107 * Initialize the global and v: variables.
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
108 */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
109 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
110 eval_init(void)
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
111 {
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
112 evalvars_init();
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
113 func_init();
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
114 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
115
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
116 #if defined(EXITFREE) || defined(PROTO)
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
117 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
118 eval_clear(void)
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
119 {
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
120 evalvars_clear();
19108
44c6498535c9 patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents: 19102
diff changeset
121 free_scriptnames(); // must come after evalvars_clear().
2849
b0190e93e601 updated for version 7.3.198
Bram Moolenaar <bram@vim.org>
parents: 2845
diff changeset
122 free_locales();
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
123
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
124 // autoloaded script names
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
125 free_autoload_scriptnames();
855
d2a4f08396fe updated for version 7.0f05
vimboss
parents: 846
diff changeset
126
16967
586d625e21b4 patch 8.1.1484: some tests are slow
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
127 // unreferenced lists and dicts
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
128 (void)garbage_collect(FALSE);
16969
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16967
diff changeset
129
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16967
diff changeset
130 // functions not garbage collected
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16967
diff changeset
131 free_all_functions();
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
132 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
133 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
134
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
135 void
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
136 fill_evalarg_from_eap(evalarg_T *evalarg, exarg_T *eap, int skip)
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
137 {
26053
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
138 init_evalarg(evalarg);
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
139 evalarg->eval_flags = skip ? 0 : EVAL_EVALUATE;
25358
f03271631eb5 patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents: 25328
diff changeset
140 if (eap != NULL)
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
141 {
25358
f03271631eb5 patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents: 25328
diff changeset
142 evalarg->eval_cstack = eap->cstack;
f03271631eb5 patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents: 25328
diff changeset
143 if (getline_equal(eap->getline, eap->cookie, getsourceline))
f03271631eb5 patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents: 25328
diff changeset
144 {
f03271631eb5 patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents: 25328
diff changeset
145 evalarg->eval_getline = eap->getline;
f03271631eb5 patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents: 25328
diff changeset
146 evalarg->eval_cookie = eap->cookie;
f03271631eb5 patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents: 25328
diff changeset
147 }
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
148 }
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
149 }
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
150
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 * Top level evaluation function, returning a boolean.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 * Sets "error" to TRUE if there was an error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 * Return TRUE or FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
157 eval_to_bool(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
158 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
159 int *error,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
160 exarg_T *eap,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
161 int skip) // only parse, don't execute
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
163 typval_T tv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
164 varnumber_T retval = FALSE;
21050
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
165 evalarg_T evalarg;
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
166
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
167 fill_evalarg_from_eap(&evalarg, eap, skip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 ++emsg_skip;
21050
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
171 if (eval0(arg, &tv, eap, &evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 *error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 *error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 if (!skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 {
21733
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
178 if (in_vim9script())
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
179 retval = tv_get_bool_chk(&tv, error);
21733
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
180 else
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
181 retval = (tv_get_number_chk(&tv, error) != 0);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
182 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 --emsg_skip;
21050
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
187 clear_evalarg(&evalarg, eap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
189 return (int)retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
192 /*
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
193 * Call eval1() and give an error message if not done at a lower level.
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
194 */
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
195 static int
21098
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
196 eval1_emsg(char_u **arg, typval_T *rettv, exarg_T *eap)
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
197 {
15482
18dd04f7c4a1 patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents: 15478
diff changeset
198 char_u *start = *arg;
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
199 int ret;
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
200 int did_emsg_before = did_emsg;
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
201 int called_emsg_before = called_emsg;
21098
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
202 evalarg_T evalarg;
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
203
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
204 fill_evalarg_from_eap(&evalarg, eap, eap != NULL && eap->skip);
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
205
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
206 ret = eval1(arg, rettv, &evalarg);
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
207 if (ret == FAIL)
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
208 {
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
209 // Report the invalid expression unless the expression evaluation has
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
210 // been cancelled due to an aborting error, an interrupt, or an
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
211 // exception, or we already gave a more specific error.
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
212 // Also check called_emsg for when using assert_fails().
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
213 if (!aborting() && did_emsg == did_emsg_before
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
214 && called_emsg == called_emsg_before)
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
215 semsg(_(e_invalid_expression_str), start);
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
216 }
21098
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
217 clear_evalarg(&evalarg, eap);
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
218 return ret;
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
219 }
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
220
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
221 /*
20731
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
222 * Return whether a typval is a valid expression to pass to eval_expr_typval()
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
223 * or eval_expr_to_bool(). An empty string returns FALSE;
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
224 */
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
225 int
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
226 eval_expr_valid_arg(typval_T *tv)
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
227 {
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
228 return tv->v_type != VAR_UNKNOWN
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
229 && (tv->v_type != VAR_STRING
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
230 || (tv->vval.v_string != NULL && *tv->vval.v_string != NUL));
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
231 }
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
232
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
233 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
234 * Evaluate an expression, which can be a function, partial or string.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
235 * Pass arguments "argv[argc]".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
236 * Return the result in "rettv" and OK or FAIL.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
237 */
16231
0761a4c111a7 patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents: 16223
diff changeset
238 int
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
239 eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
240 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
241 char_u *s;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
242 char_u buf[NUMBUFLEN];
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
243 funcexe_T funcexe;
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
244
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
245 if (expr->v_type == VAR_FUNC)
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
246 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
247 s = expr->vval.v_string;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
248 if (s == NULL || *s == NUL)
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
249 return FAIL;
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
250 CLEAR_FIELD(funcexe);
26534
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
251 funcexe.fe_evaluate = TRUE;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
252 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
253 return FAIL;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
254 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
255 else if (expr->v_type == VAR_PARTIAL)
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
256 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
257 partial_T *partial = expr->vval.v_partial;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
258
20156
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
259 if (partial == NULL)
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
260 return FAIL;
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
261
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20526
diff changeset
262 if (partial->pt_func != NULL
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
263 && partial->pt_func->uf_def_status != UF_NOT_COMPILED)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
264 {
20433
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20401
diff changeset
265 if (call_def_function(partial->pt_func, argc, argv,
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20401
diff changeset
266 partial, rettv) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
267 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
268 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
269 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
270 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
271 s = partial_name(partial);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
272 if (s == NULL || *s == NUL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
273 return FAIL;
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
274 CLEAR_FIELD(funcexe);
26534
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
275 funcexe.fe_evaluate = TRUE;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
276 funcexe.fe_partial = partial;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
277 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
278 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
279 }
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
280 }
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
281 else if (expr->v_type == VAR_INSTR)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
282 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
283 return exe_typval_instr(expr, rettv);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
284 }
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
285 else
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
286 {
27396
ab690582075a patch 8.2.4226: filter-map test fails
Bram Moolenaar <Bram@vim.org>
parents: 27392
diff changeset
287 s = tv_get_string_buf_chk_strict(expr, buf, in_vim9script());
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
288 if (s == NULL)
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
289 return FAIL;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
290 s = skipwhite(s);
21098
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
291 if (eval1_emsg(&s, rettv, NULL) == FAIL)
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
292 return FAIL;
21620
46956b6811a1 patch 8.2.1360: stray error for white space after expression
Bram Moolenaar <Bram@vim.org>
parents: 21552
diff changeset
293 if (*skipwhite(s) != NUL) // check for trailing chars after expr
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
294 {
14331
f8280e1bfc84 patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents: 14071
diff changeset
295 clear_tv(rettv);
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
296 semsg(_(e_invalid_expression_str), s);
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
297 return FAIL;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
298 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
299 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
300 return OK;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
301 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
302
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
303 /*
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
304 * Like eval_to_bool() but using a typval_T instead of a string.
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
305 * Works for string, funcref and partial.
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
306 */
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
307 int
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
308 eval_expr_to_bool(typval_T *expr, int *error)
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
309 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
310 typval_T rettv;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
311 int res;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
312
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
313 if (eval_expr_typval(expr, NULL, 0, &rettv) == FAIL)
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
314 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
315 *error = TRUE;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
316 return FALSE;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
317 }
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21847
diff changeset
318 res = (tv_get_bool_chk(&rettv, error) != 0);
12722
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
319 clear_tv(&rettv);
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
320 return res;
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
321 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
322
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 * Top level evaluation function, returning a string. If "skip" is TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 * only parsing to "nextcmd" is done, without reporting errors. Return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
329 eval_to_string_skip(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
330 char_u *arg,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
331 exarg_T *eap,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
332 int skip) // only parse, don't execute
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
334 typval_T tv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 char_u *retval;
21094
376b520312d6 patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents: 21077
diff changeset
336 evalarg_T evalarg;
376b520312d6 patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents: 21077
diff changeset
337
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
338 fill_evalarg_from_eap(&evalarg, eap, skip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 ++emsg_skip;
21094
376b520312d6 patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents: 21077
diff changeset
341 if (eval0(arg, &tv, eap, &evalarg) == FAIL || skip)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
345 retval = vim_strsave(tv_get_string(&tv));
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
346 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 --emsg_skip;
21094
376b520312d6 patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents: 21077
diff changeset
350 clear_evalarg(&evalarg, eap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 /*
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
356 * Skip over an expression at "*pp".
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
357 * Return FAIL for an error, OK otherwise.
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
358 */
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
359 int
22685
80b4e604d1d5 patch 8.2.1891: Vim9: skipping over expression doesn't handle line breaks
Bram Moolenaar <Bram@vim.org>
parents: 22683
diff changeset
360 skip_expr(char_u **pp, evalarg_T *evalarg)
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
361 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
362 typval_T rettv;
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
363
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
364 *pp = skipwhite(*pp);
22685
80b4e604d1d5 patch 8.2.1891: Vim9: skipping over expression doesn't handle line breaks
Bram Moolenaar <Bram@vim.org>
parents: 22683
diff changeset
365 return eval1(pp, &rettv, evalarg);
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
366 }
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
367
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
368 /*
24553
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
369 * Skip over an expression at "*arg".
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
370 * If in Vim9 script and line breaks are encountered, the lines are
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
371 * concatenated. "evalarg->eval_tofree" will be set accordingly.
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
372 * "arg" is advanced to just after the expression.
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
373 * "start" is set to the start of the expression, "end" to just after the end.
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
374 * Also when the expression is copied to allocated memory.
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
375 * Return FAIL for an error, OK otherwise.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
376 */
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
377 int
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
378 skip_expr_concatenate(
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
379 char_u **arg,
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
380 char_u **start,
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
381 char_u **end,
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
382 evalarg_T *evalarg)
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
383 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
384 typval_T rettv;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
385 int res;
21279
8d1d11afd8c8 patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents: 21277
diff changeset
386 int vim9script = in_vim9script();
22021
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
387 garray_T *gap = evalarg == NULL ? NULL : &evalarg->eval_ga;
24655
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
388 garray_T *freegap = evalarg == NULL ? NULL : &evalarg->eval_freega;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
389 int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
21865
c16af87df654 patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
390 int evaluate = evalarg == NULL
c16af87df654 patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
391 ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE);
c16af87df654 patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
392
c16af87df654 patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
393 if (vim9script && evaluate
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
394 && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL))
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
395 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
396 ga_init2(gap, sizeof(char_u *), 10);
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
397 // leave room for "start"
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
398 if (ga_grow(gap, 1) == OK)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
399 ++gap->ga_len;
24655
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
400 ga_init2(freegap, sizeof(char_u *), 10);
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
401 }
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
402 *start = *arg;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
403
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
404 // Don't evaluate the expression.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
405 if (evalarg != NULL)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
406 evalarg->eval_flags &= ~EVAL_EVALUATE;
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
407 *arg = skipwhite(*arg);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
408 res = eval1(arg, &rettv, evalarg);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
409 *end = *arg;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
410 if (evalarg != NULL)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
411 evalarg->eval_flags = save_flags;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
412
21865
c16af87df654 patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
413 if (vim9script && evaluate
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
414 && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL))
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
415 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
416 if (evalarg->eval_ga.ga_len == 1)
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
417 {
24655
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
418 // just the one line, no need to concatenate
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
419 ga_clear(gap);
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
420 gap->ga_itemsize = 0;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
421 }
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
422 else
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
423 {
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
424 char_u *p;
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
425 size_t endoff = STRLEN(*arg);
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
426
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
427 // Line breaks encountered, concatenate all the lines.
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
428 *((char_u **)gap->ga_data) = *start;
24553
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
429 p = ga_concat_strings(gap, " ");
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
430
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
431 // free the lines only when using getsourceline()
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
432 if (evalarg->eval_cookie != NULL)
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
433 {
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
434 // Do not free the first line, the caller can still use it.
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
435 *((char_u **)gap->ga_data) = NULL;
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
436 // Do not free the last line, "arg" points into it, free it
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
437 // later.
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
438 vim_free(evalarg->eval_tofree);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
439 evalarg->eval_tofree =
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
440 ((char_u **)gap->ga_data)[gap->ga_len - 1];
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
441 ((char_u **)gap->ga_data)[gap->ga_len - 1] = NULL;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
442 ga_clear_strings(gap);
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
443 }
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
444 else
24655
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
445 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
446 ga_clear(gap);
24655
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
447
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
448 // free lines that were explicitly marked for freeing
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
449 ga_clear_strings(freegap);
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
450 }
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
451
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
452 gap->ga_itemsize = 0;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
453 if (p == NULL)
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
454 return FAIL;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
455 *start = p;
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
456 vim_free(evalarg->eval_tofree_lambda);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
457 evalarg->eval_tofree_lambda = p;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
458 // Compute "end" relative to the end.
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
459 *end = *start + STRLEN(*start) - endoff;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
460 }
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
461 }
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
462
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
463 return res;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
464 }
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
465
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
466 /*
23628
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
467 * Convert "tv" to a string.
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
468 * When "convert" is TRUE convert a List into a sequence of lines and convert
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
469 * a Float to a String.
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
470 * Returns an allocated string (NULL when out of memory).
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
471 */
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
472 char_u *
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
473 typval2string(typval_T *tv, int convert)
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
474 {
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
475 garray_T ga;
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
476 char_u *retval;
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
477 #ifdef FEAT_FLOAT
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
478 char_u numbuf[NUMBUFLEN];
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
479 #endif
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
480
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
481 if (convert && tv->v_type == VAR_LIST)
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
482 {
27028
c9474ae175f4 patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
483 ga_init2(&ga, sizeof(char), 80);
23628
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
484 if (tv->vval.v_list != NULL)
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
485 {
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
486 list_join(&ga, tv->vval.v_list, (char_u *)"\n", TRUE, FALSE, 0);
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
487 if (tv->vval.v_list->lv_len > 0)
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
488 ga_append(&ga, NL);
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
489 }
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
490 ga_append(&ga, NUL);
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
491 retval = (char_u *)ga.ga_data;
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
492 }
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
493 #ifdef FEAT_FLOAT
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
494 else if (convert && tv->v_type == VAR_FLOAT)
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
495 {
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
496 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float);
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
497 retval = vim_strsave(numbuf);
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
498 }
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
499 #endif
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
500 else
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
501 retval = vim_strsave(tv_get_string(tv));
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
502 return retval;
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
503 }
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
504
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
505 /*
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
506 * Top level evaluation function, returning a string. Does not handle line
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
507 * breaks.
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
508 * When "convert" is TRUE convert a List into a sequence of lines and convert
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
509 * a Float to a String.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 * Return pointer to allocated memory, or NULL for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 char_u *
22732
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
513 eval_to_string_eap(
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
514 char_u *arg,
22732
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
515 int convert,
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
516 exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
518 typval_T tv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 char_u *retval;
22732
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
520 evalarg_T evalarg;
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
521
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
522 fill_evalarg_from_eap(&evalarg, eap, eap != NULL && eap->skip);
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
523 if (eval0(arg, &tv, NULL, &evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 {
23628
b26bbc03126a patch 8.2.2356: Vim9: ":put =expr" does not handle a list properly
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
527 retval = typval2string(&tv, convert);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
528 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 }
22732
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
530 clear_evalarg(&evalarg, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534
22732
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
535 char_u *
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
536 eval_to_string(
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
537 char_u *arg,
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
538 int convert)
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
539 {
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
540 return eval_to_string_eap(arg, convert, NULL);
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
541 }
4c21a3a47707 patch 8.2.1914: Vim9: cannot put line break in expression for '=' register
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
542
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 /*
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
544 * Call eval_to_string() without using current local variables and using
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
545 * textwinlock. When "use_sandbox" is TRUE use the sandbox.
21775
6922d78b4d52 patch 8.2.1437: Vim9: 'statusline' is evaluated using Vim9 script syntax
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
546 * Use legacy Vim script syntax.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
549 eval_to_string_safe(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
550 char_u *arg,
27301
ebe56a24acb6 patch 8.2.4179: 'foldtext' is evaluated in the current script context
Bram Moolenaar <Bram@vim.org>
parents: 27289
diff changeset
551 int use_sandbox,
ebe56a24acb6 patch 8.2.4179: 'foldtext' is evaluated in the current script context
Bram Moolenaar <Bram@vim.org>
parents: 27289
diff changeset
552 int keep_script_version)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 char_u *retval;
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14897
diff changeset
555 funccal_entry_T funccal_entry;
21775
6922d78b4d52 patch 8.2.1437: Vim9: 'statusline' is evaluated using Vim9 script syntax
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
556 int save_sc_version = current_sctx.sc_version;
25765
d62bf68986df patch 8.2.3418: garbage collection while evaluating may cause trouble
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
557 int save_garbage = may_garbage_collect;
21775
6922d78b4d52 patch 8.2.1437: Vim9: 'statusline' is evaluated using Vim9 script syntax
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
558
27301
ebe56a24acb6 patch 8.2.4179: 'foldtext' is evaluated in the current script context
Bram Moolenaar <Bram@vim.org>
parents: 27289
diff changeset
559 if (!keep_script_version)
ebe56a24acb6 patch 8.2.4179: 'foldtext' is evaluated in the current script context
Bram Moolenaar <Bram@vim.org>
parents: 27289
diff changeset
560 current_sctx.sc_version = 1;
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14897
diff changeset
561 save_funccal(&funccal_entry);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
562 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
563 ++sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
564 ++textwinlock;
25765
d62bf68986df patch 8.2.3418: garbage collection while evaluating may cause trouble
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
565 may_garbage_collect = FALSE;
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
566 retval = eval_to_string(arg, FALSE);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
567 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
568 --sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
569 --textwinlock;
25765
d62bf68986df patch 8.2.3418: garbage collection while evaluating may cause trouble
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
570 may_garbage_collect = save_garbage;
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14897
diff changeset
571 restore_funccal();
21775
6922d78b4d52 patch 8.2.1437: Vim9: 'statusline' is evaluated using Vim9 script syntax
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
572 current_sctx.sc_version = save_sc_version;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 * Top level evaluation function, returning a number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 * Evaluates "expr" silently.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 * Returns -1 for an error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
581 varnumber_T
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
582 eval_to_number(char_u *expr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
584 typval_T rettv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
585 varnumber_T retval;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
586 char_u *p = skipwhite(expr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 ++emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
590 if (eval1(&p, &rettv, &EVALARG_EVALUATE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 retval = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
594 retval = tv_get_number_chk(&rettv, NULL);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
595 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 --emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
602 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
603 * Top level evaluation function.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
604 * Returns an allocated typval_T with the result.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
605 * Returns NULL when there is an error.
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
606 */
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
607 typval_T *
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
608 eval_expr(char_u *arg, exarg_T *eap)
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
609 {
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
610 typval_T *tv;
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
611 evalarg_T evalarg;
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
612
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
613 fill_evalarg_from_eap(&evalarg, eap, eap != NULL && eap->skip);
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
614
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16796
diff changeset
615 tv = ALLOC_ONE(typval_T);
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
616 if (tv != NULL && eval0(arg, tv, eap, &evalarg) == FAIL)
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
617 VIM_CLEAR(tv);
21096
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
618
74e5e212e550 patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents: 21094
diff changeset
619 clear_evalarg(&evalarg, eap);
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
620 return tv;
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
621 }
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
622
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 /*
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
624 * "*arg" points to what can be a function name in the form of "import.Name" or
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
625 * "Funcref". Return the name of the function. Set "tofree" to something that
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
626 * was allocated.
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
627 * If "verbose" is FALSE no errors are given.
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
628 * Return NULL for any failure.
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
629 */
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
630 static char_u *
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
631 deref_function_name(
27583
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27517
diff changeset
632 char_u **arg,
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27517
diff changeset
633 char_u **tofree,
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27517
diff changeset
634 evalarg_T *evalarg,
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27517
diff changeset
635 int verbose)
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
636 {
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
637 typval_T ref;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
638 char_u *name = *arg;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
639
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
640 ref.v_type = VAR_UNKNOWN;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
641 if (eval7(arg, &ref, evalarg, FALSE) == FAIL)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
642 return NULL;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
643 if (*skipwhite(*arg) != NUL)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
644 {
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
645 if (verbose)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
646 semsg(_(e_trailing_characters_str), *arg);
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
647 name = NULL;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
648 }
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
649 else if (ref.v_type == VAR_FUNC && ref.vval.v_string != NULL)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
650 {
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
651 name = ref.vval.v_string;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
652 ref.vval.v_string = NULL;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
653 *tofree = name;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
654 }
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
655 else if (ref.v_type == VAR_PARTIAL && ref.vval.v_partial != NULL)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
656 {
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
657 if (ref.vval.v_partial->pt_argc > 0
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
658 || ref.vval.v_partial->pt_dict != NULL)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
659 {
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
660 if (verbose)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
661 emsg(_(e_cannot_use_partial_here));
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
662 name = NULL;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
663 }
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
664 else
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
665 {
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
666 name = vim_strsave(partial_name(ref.vval.v_partial));
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
667 *tofree = name;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
668 }
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
669 }
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
670 else
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
671 {
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
672 if (verbose)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
673 semsg(_(e_not_callable_type_str), name);
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
674 name = NULL;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
675 }
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
676 clear_tv(&ref);
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
677 return name;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
678 }
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
679
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
680 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
681 * Call some Vim script function and return the result in "*rettv".
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
682 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc]
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
683 * should have type VAR_UNKNOWN.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
684 * Returns OK or FAIL.
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
685 */
3078
2cbde6bcc623 updated for version 7.3.311
Bram Moolenaar <bram@vim.org>
parents: 3066
diff changeset
686 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
687 call_vim_function(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
688 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
689 int argc,
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
690 typval_T *argv,
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
691 typval_T *rettv)
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
692 {
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
693 int ret;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
694 funcexe_T funcexe;
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
695 char_u *arg;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
696 char_u *name;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
697 char_u *tofree = NULL;
28107
710a509be2cd patch 8.2.4578: no warning when autoload script for completion has an error
Bram Moolenaar <Bram@vim.org>
parents: 28101
diff changeset
698 int ignore_errors;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
700 rettv->v_type = VAR_UNKNOWN; // clear_tv() uses this
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
701 CLEAR_FIELD(funcexe);
26534
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
702 funcexe.fe_firstline = curwin->w_cursor.lnum;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
703 funcexe.fe_lastline = curwin->w_cursor.lnum;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
704 funcexe.fe_evaluate = TRUE;
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
705
28107
710a509be2cd patch 8.2.4578: no warning when autoload script for completion has an error
Bram Moolenaar <Bram@vim.org>
parents: 28101
diff changeset
706 // The name might be "import.Func" or "Funcref". We don't know, we need to
710a509be2cd patch 8.2.4578: no warning when autoload script for completion has an error
Bram Moolenaar <Bram@vim.org>
parents: 28101
diff changeset
707 // ignore errors for an undefined name. But we do want errors when an
28119
57ea74314c1b patch 8.2.4584: error for using autoload function in custom completion
Bram Moolenaar <Bram@vim.org>
parents: 28115
diff changeset
708 // autoload script has errors. Guess that when there is a dot in the name
57ea74314c1b patch 8.2.4584: error for using autoload function in custom completion
Bram Moolenaar <Bram@vim.org>
parents: 28115
diff changeset
709 // showing errors is the right choice.
57ea74314c1b patch 8.2.4584: error for using autoload function in custom completion
Bram Moolenaar <Bram@vim.org>
parents: 28115
diff changeset
710 ignore_errors = vim_strchr(func, '.') == NULL;
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
711 arg = func;
28107
710a509be2cd patch 8.2.4578: no warning when autoload script for completion has an error
Bram Moolenaar <Bram@vim.org>
parents: 28101
diff changeset
712 if (ignore_errors)
710a509be2cd patch 8.2.4578: no warning when autoload script for completion has an error
Bram Moolenaar <Bram@vim.org>
parents: 28101
diff changeset
713 ++emsg_off;
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
714 name = deref_function_name(&arg, &tofree, &EVALARG_EVALUATE, FALSE);
28107
710a509be2cd patch 8.2.4578: no warning when autoload script for completion has an error
Bram Moolenaar <Bram@vim.org>
parents: 28101
diff changeset
715 if (ignore_errors)
710a509be2cd patch 8.2.4578: no warning when autoload script for completion has an error
Bram Moolenaar <Bram@vim.org>
parents: 28101
diff changeset
716 --emsg_off;
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
717 if (name == NULL)
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
718 name = func;
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
719
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
720 ret = call_func(name, -1, rettv, argc, argv, &funcexe);
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
721
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
722 if (ret == FAIL)
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
723 clear_tv(rettv);
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
724 vim_free(tofree);
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
725
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
726 return ret;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
727 }
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
728
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
729 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
730 * Call Vim script function "func" and return the result as a string.
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26990
diff changeset
731 * Uses "argv[0]" to "argv[argc - 1]" for the function arguments. "argv[argc]"
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26990
diff changeset
732 * should have type VAR_UNKNOWN.
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
733 * Returns NULL when calling the function fails.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
734 */
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
735 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
736 call_func_retstr(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
737 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
738 int argc,
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
739 typval_T *argv)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
740 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
741 typval_T rettv;
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
742 char_u *retval;
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
743
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
744 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
745 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
746
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
747 retval = vim_strsave(tv_get_string(&rettv));
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
748 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 }
1322
4ce0a7e4c6b3 updated for version 7.1-036
vimboss
parents: 1320
diff changeset
751
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
752 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
753 * Call Vim script function "func" and return the result as a List.
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26990
diff changeset
754 * Uses "argv" and "argc" as call_func_retstr().
1690
c6b06a4a8f92 updated for version 7.2b-023
vimboss
parents: 1683
diff changeset
755 * Returns NULL when there is something wrong.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
756 */
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
757 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
758 call_func_retlist(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
759 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
760 int argc,
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
761 typval_T *argv)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
762 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
763 typval_T rettv;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
764
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
765 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
766 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
767
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
768 if (rettv.v_type != VAR_LIST)
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
769 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
770 clear_tv(&rettv);
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
771 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
772 }
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
773
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
774 return rettv.vval.v_list;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
775 }
1322
4ce0a7e4c6b3 updated for version 7.1-036
vimboss
parents: 1320
diff changeset
776
27289
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
777 #if defined(FEAT_FOLDING) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 /*
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
779 * Evaluate "arg", which is 'foldexpr'.
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
780 * Note: caller must set "curwin" to match "arg".
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
781 * Returns the foldlevel, and any character preceding it in "*cp". Doesn't
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
782 * give error messages.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 int
27289
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
785 eval_foldexpr(win_T *wp, int *cp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 {
27289
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
787 char_u *arg;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
788 typval_T tv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
789 varnumber_T retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 char_u *s;
27289
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
791 sctx_T saved_sctx = current_sctx;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
792 int use_sandbox = was_set_insecurely((char_u *)"foldexpr",
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
793 OPT_LOCAL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794
27289
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
795 arg = wp->w_p_fde;
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
796 current_sctx = wp->w_p_script_ctx[WV_FDE];
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
797
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 ++emsg_off;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
799 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
800 ++sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
801 ++textwinlock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 *cp = NUL;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
803 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
807 // If the result is a number, just return the number.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
808 if (tv.v_type == VAR_NUMBER)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
809 retval = tv.vval.v_number;
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
810 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
814 // If the result is a string, check if there is a non-digit before
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
815 // the number.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
816 s = tv.vval.v_string;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 if (!VIM_ISDIGIT(*s) && *s != '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 *cp = *s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 retval = atol((char *)s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
821 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 --emsg_off;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
824 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
825 --sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
826 --textwinlock;
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
827 clear_evalarg(&EVALARG_EVALUATE, NULL);
27289
e11682ba8c80 patch 8.2.4173: cannot use an import in 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27233
diff changeset
828 current_sctx = saved_sctx;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
830 return (int)retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 /*
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
835 * Get an lval: variable, Dict item or List item that can be assigned a value
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
836 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]",
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
837 * "name.key", "name.key[expr]" etc.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
838 * Indexing only works if "name" is an existing List or Dictionary.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
839 * "name" points to the start of the name.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
840 * If "rettv" is not NULL it points to the value to be assigned.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
841 * "unlet" is TRUE for ":unlet": slightly different behavior when something is
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
842 * wrong; must end in space or cmd separator.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
843 *
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
844 * flags:
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
845 * GLV_QUIET: do not give error messages
10912
fd1760f8c215 patch 8.0.0345: islocked('d.changedtick') does not work
Christian Brabandt <cb@256bit.org>
parents: 10910
diff changeset
846 * GLV_READ_ONLY: will not change the variable
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
847 * GLV_NO_AUTOLOAD: do not use script autoloading
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
848 *
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
849 * Returns a pointer to just after the name, including indexes.
124
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
850 * When an evaluation error occurs "lp->ll_name" is NULL;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
851 * Returns NULL for a parsing error. Still need to free items in "lp"!
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
852 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
853 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
854 get_lval(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
855 char_u *name,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
856 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
857 lval_T *lp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
858 int unlet,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
859 int skip,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
860 int flags, // GLV_ values
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
861 int fne_flags) // flags for find_name_end()
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
862 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
863 char_u *p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
864 char_u *expr_start, *expr_end;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
865 int cc;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
866 dictitem_T *v;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
867 typval_T var1;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
868 typval_T var2;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
869 int empty1 = FALSE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
870 char_u *key = NULL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
871 int len;
22963
317462da618a patch 8.2.2028: Coverity warns for using an uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22866
diff changeset
872 hashtab_T *ht = NULL;
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
873 int quiet = flags & GLV_QUIET;
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
874 int writing;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
875 int vim9script = in_vim9script();
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
876
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
877 // Clear everything in "lp".
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
878 CLEAR_POINTER(lp);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
879
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23493
diff changeset
880 if (skip || (flags & GLV_COMPILING))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
881 {
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23493
diff changeset
882 // When skipping or compiling just find the end of the name.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
883 lp->ll_name = name;
21077
794bf2be08be patch 8.2.1090: may use NULL pointer when skipping over name
Bram Moolenaar <Bram@vim.org>
parents: 21058
diff changeset
884 lp->ll_name_end = find_name_end(name, NULL, NULL,
794bf2be08be patch 8.2.1090: may use NULL pointer when skipping over name
Bram Moolenaar <Bram@vim.org>
parents: 21058
diff changeset
885 FNE_INCL_BR | fne_flags);
794bf2be08be patch 8.2.1090: may use NULL pointer when skipping over name
Bram Moolenaar <Bram@vim.org>
parents: 21058
diff changeset
886 return lp->ll_name_end;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
887 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
888
27669
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
889 // Cannot use "s:var" at the Vim9 script level. "s: type" is OK.
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
890 if (vim9script && at_script_level()
27669
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
891 && name[0] == 's' && name[1] == ':' && !VIM_ISWHITE(name[2]))
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
892 {
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
893 semsg(_(e_cannot_use_s_colon_in_vim9_script_str), name);
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
894 return NULL;
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
895 }
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
896
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
897 // Find the end of the name.
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
898 p = find_name_end(name, &expr_start, &expr_end, fne_flags);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
899 lp->ll_name_end = p;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
900 if (expr_start != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
901 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
902 // Don't expand the name when we already know there is an error.
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
903 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
904 && *p != '[' && *p != '.')
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
905 {
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
906 semsg(_(e_trailing_characters_str), p);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
907 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
908 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
909
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
910 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
911 if (lp->ll_exp_name == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
912 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
913 // Report an invalid expression in braces, unless the
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
914 // expression evaluation has been cancelled due to an
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
915 // aborting error, an interrupt, or an exception.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
916 if (!aborting() && !quiet)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
917 {
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
918 emsg_severe = TRUE;
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
919 semsg(_(e_invalid_argument_str), name);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
920 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
921 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
922 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
923 lp->ll_name = lp->ll_exp_name;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
924 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
925 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
926 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
927 lp->ll_name = name;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
928
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
929 if (vim9script)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
930 {
21674
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
931 // "a: type" is declaring variable "a" with a type, not "a:".
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
932 if (p == name + 2 && p[-1] == ':')
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
933 {
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
934 --p;
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
935 lp->ll_name_end = p;
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
936 }
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
937 if (*p == ':')
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
938 {
26954
11ee2667a09a patch 8.2.4006: Vim9: crash when declaring variable on the command line
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
939 char_u *tp = skipwhite(p + 1);
25668
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
940
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
941 if (tp == p + 1 && !quiet)
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
942 {
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
943 semsg(_(e_white_space_required_after_str_str), ":", p);
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
944 return NULL;
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
945 }
21674
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
946
28115
62a57c60edc1 patch 8.2.4582: useless code handling a type declaration
Bram Moolenaar <Bram@vim.org>
parents: 28107
diff changeset
947 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
26954
11ee2667a09a patch 8.2.4006: Vim9: crash when declaring variable on the command line
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
948 {
28115
62a57c60edc1 patch 8.2.4582: useless code handling a type declaration
Bram Moolenaar <Bram@vim.org>
parents: 28107
diff changeset
949 semsg(_(e_using_type_not_in_script_context_str), p);
62a57c60edc1 patch 8.2.4582: useless code handling a type declaration
Bram Moolenaar <Bram@vim.org>
parents: 28107
diff changeset
950 return NULL;
26954
11ee2667a09a patch 8.2.4006: Vim9: crash when declaring variable on the command line
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
951 }
11ee2667a09a patch 8.2.4006: Vim9: crash when declaring variable on the command line
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
952
21674
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
953 // parse the type after the name
28115
62a57c60edc1 patch 8.2.4582: useless code handling a type declaration
Bram Moolenaar <Bram@vim.org>
parents: 28107
diff changeset
954 lp->ll_type = parse_type(&tp,
62a57c60edc1 patch 8.2.4582: useless code handling a type declaration
Bram Moolenaar <Bram@vim.org>
parents: 28107
diff changeset
955 &SCRIPT_ITEM(current_sctx.sc_sid)->sn_type_list,
62a57c60edc1 patch 8.2.4582: useless code handling a type declaration
Bram Moolenaar <Bram@vim.org>
parents: 28107
diff changeset
956 !quiet);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23322
diff changeset
957 if (lp->ll_type == NULL && !quiet)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23322
diff changeset
958 return NULL;
21674
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
959 lp->ll_name_end = tp;
f303d6a01a3e patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
960 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
961 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
962 }
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
963 if (lp->ll_name == NULL)
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
964 return p;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
965
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27453
diff changeset
966 if (*p == '.')
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
967 {
27698
3813036f19cb patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents: 27682
diff changeset
968 imported_T *import = find_imported(lp->ll_name, p - lp->ll_name, TRUE);
27043
15f40772e10a patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
969
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
970 if (import != NULL)
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
971 {
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
972 ufunc_T *ufunc;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
973 type_T *type;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
974
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
975 lp->ll_sid = import->imp_sid;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
976 lp->ll_name = skipwhite(p + 1);
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
977 p = find_name_end(lp->ll_name, NULL, NULL, fne_flags);
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
978 lp->ll_name_end = p;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
979
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
980 // check the item is exported
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
981 cc = *p;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
982 *p = NUL;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
983 if (find_exported(import->imp_sid, lp->ll_name, &ufunc, &type,
27613
42d0279c6e7c patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents: 27591
diff changeset
984 NULL, NULL, TRUE) == -1)
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
985 {
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
986 *p = cc;
27080
9897dd3c6530 patch 8.2.4069: Vim9: import test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 27043
diff changeset
987 return NULL;
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
988 }
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
989 *p = cc;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
990 }
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
991 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
992
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
993 // Without [idx] or .key we are done.
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
994 if ((*p != '[' && *p != '.'))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
995 return p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
996
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
997 if (vim9script && lval_root != NULL)
25605
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
998 {
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
999 // using local variable
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1000 lp->ll_tv = lval_root;
25607
54fef15ed370 patch 8.2.3340: accessing uninitialized pointer
Bram Moolenaar <Bram@vim.org>
parents: 25605
diff changeset
1001 v = NULL;
25605
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1002 }
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1003 else
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1004 {
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1005 cc = *p;
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1006 *p = NUL;
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1007 // When we would write to the variable pass &ht and prevent autoload.
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1008 writing = !(flags & GLV_READ_ONLY);
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1009 v = find_var(lp->ll_name, writing ? &ht : NULL,
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
1010 (flags & GLV_NO_AUTOLOAD) || writing);
25605
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1011 if (v == NULL && !quiet)
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1012 semsg(_(e_undefined_variable_str), lp->ll_name);
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1013 *p = cc;
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1014 if (v == NULL)
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1015 return NULL;
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1016 lp->ll_tv = &v->di_tv;
6f13d9ea0d04 patch 8.2.3339: Vim9: cannot lock a member in a local dict
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1017 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1018
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
1019 if (vim9script && (flags & GLV_NO_DECL) == 0)
23239
a789a688e37d patch 8.2.2165: Vim9: assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1020 {
a789a688e37d patch 8.2.2165: Vim9: assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1021 if (!quiet)
a789a688e37d patch 8.2.2165: Vim9: assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1022 semsg(_(e_variable_already_declared), lp->ll_name);
a789a688e37d patch 8.2.2165: Vim9: assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1023 return NULL;
a789a688e37d patch 8.2.2165: Vim9: assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1024 }
a789a688e37d patch 8.2.2165: Vim9: assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1025
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1026 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1027 * Loop until no more [idx] or .key is following.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1028 */
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1029 var1.v_type = VAR_UNKNOWN;
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1030 var2.v_type = VAR_UNKNOWN;
25036
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24958
diff changeset
1031 while (*p == '[' || (*p == '.' && p[1] != '=' && p[1] != '.'))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1032 {
25036
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24958
diff changeset
1033 if (*p == '.' && lp->ll_tv->v_type != VAR_DICT)
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24958
diff changeset
1034 {
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24958
diff changeset
1035 if (!quiet)
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24958
diff changeset
1036 semsg(_(e_dot_can_only_be_used_on_dictionary_str), name);
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24958
diff changeset
1037 return NULL;
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24958
diff changeset
1038 }
25054
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1039 if (lp->ll_tv->v_type != VAR_LIST
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1040 && lp->ll_tv->v_type != VAR_DICT
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1041 && lp->ll_tv->v_type != VAR_BLOB)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1042 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1043 if (!quiet)
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26925
diff changeset
1044 emsg(_(e_can_only_index_list_dictionary_or_blob));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1045 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1046 }
25054
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1047
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1048 // a NULL list/blob works like an empty list/blob, allocate one now.
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1049 if (lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list == NULL)
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1050 rettv_list_alloc(lp->ll_tv);
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1051 else if (lp->ll_tv->v_type == VAR_BLOB
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1052 && lp->ll_tv->vval.v_blob == NULL)
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1053 rettv_blob_alloc(lp->ll_tv);
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1054
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1055 if (lp->ll_range)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1056 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1057 if (!quiet)
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26925
diff changeset
1058 emsg(_(e_slice_must_come_last));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1059 return NULL;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1060 }
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1061
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
1062 if (vim9script && lp->ll_valtype == NULL
25607
54fef15ed370 patch 8.2.3340: accessing uninitialized pointer
Bram Moolenaar <Bram@vim.org>
parents: 25605
diff changeset
1063 && v != NULL
22529
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1064 && lp->ll_tv == &v->di_tv
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1065 && ht != NULL && ht == get_script_local_ht())
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1066 {
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
1067 svar_T *sv = find_typval_in_script(lp->ll_tv, 0);
22529
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1068
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1069 // Vim9 script local variable: get the type
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1070 if (sv != NULL)
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1071 lp->ll_valtype = sv->sv_type;
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1072 }
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1073
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1074 len = -1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1075 if (*p == '.')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1076 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1077 key = p + 1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1078 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1079 ;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1080 if (len == 0)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1081 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1082 if (!quiet)
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1083 emsg(_(e_cannot_use_empty_key_for_dictionary));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1084 return NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1085 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1086 p = key + len;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1087 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1088 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1089 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1090 // Get the index [expr] or the first index [expr: ].
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1091 p = skipwhite(p + 1);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1092 if (*p == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1093 empty1 = TRUE;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1094 else
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1095 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1096 empty1 = FALSE;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1097 if (eval1(&p, &var1, &EVALARG_EVALUATE) == FAIL) // recursive!
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1098 return NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1099 if (tv_get_string_chk(&var1) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1100 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1101 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1102 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1103 return NULL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1104 }
21622
1f2066e3975a patch 8.2.1361: error for white space after expression in assignment
Bram Moolenaar <Bram@vim.org>
parents: 21620
diff changeset
1105 p = skipwhite(p);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1106 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1107
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1108 // Optionally get the second index [ :expr].
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1109 if (*p == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1110 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1111 if (lp->ll_tv->v_type == VAR_DICT)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1112 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1113 if (!quiet)
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
1114 emsg(_(e_cannot_slice_dictionary));
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1115 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1116 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1117 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1118 if (rettv != NULL
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1119 && !(rettv->v_type == VAR_LIST
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1120 && rettv->vval.v_list != NULL)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1121 && !(rettv->v_type == VAR_BLOB
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1122 && rettv->vval.v_blob != NULL))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1123 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1124 if (!quiet)
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26925
diff changeset
1125 emsg(_(e_slice_requires_list_or_blob_value));
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1126 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1127 return NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1128 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1129 p = skipwhite(p + 1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1130 if (*p == ']')
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1131 lp->ll_empty2 = TRUE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1132 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1133 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1134 lp->ll_empty2 = FALSE;
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1135 // recursive!
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1136 if (eval1(&p, &var2, &EVALARG_EVALUATE) == FAIL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1137 {
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1138 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1139 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1140 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1141 if (tv_get_string_chk(&var2) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1142 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1143 // not a number or string
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1144 clear_tv(&var1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1145 clear_tv(&var2);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1146 return NULL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1147 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1148 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1149 lp->ll_range = TRUE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1150 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1151 else
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1152 lp->ll_range = FALSE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1153
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1154 if (*p != ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1155 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1156 if (!quiet)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26572
diff changeset
1157 emsg(_(e_missing_closing_square_brace));
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1158 clear_tv(&var1);
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1159 clear_tv(&var2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1160 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1161 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1162
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1163 // Skip to past ']'.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1164 ++p;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1165 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1166
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1167 if (lp->ll_tv->v_type == VAR_DICT)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1168 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1169 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1170 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1171 // "[key]": get key from "var1"
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1172 key = tv_get_string_chk(&var1); // is number or string
8839
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8831
diff changeset
1173 if (key == NULL)
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8831
diff changeset
1174 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1175 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1176 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1177 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1178 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1179 lp->ll_list = NULL;
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1180
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1181 // a NULL dict is equivalent with an empty dict
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1182 if (lp->ll_tv->vval.v_dict == NULL)
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1183 {
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1184 lp->ll_tv->vval.v_dict = dict_alloc();
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1185 if (lp->ll_tv->vval.v_dict == NULL)
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1186 {
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1187 clear_tv(&var1);
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1188 return NULL;
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1189 }
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1190 ++lp->ll_tv->vval.v_dict->dv_refcount;
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1191 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1192 lp->ll_dict = lp->ll_tv->vval.v_dict;
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1193
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1194 lp->ll_di = dict_find(lp->ll_dict, key, len);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1195
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1196 // When assigning to a scope dictionary check that a function and
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1197 // variable name is valid (only variable name unless it is l: or
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1198 // g: dictionary). Disallow overwriting a builtin function.
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1199 if (rettv != NULL && lp->ll_dict->dv_scope != 0)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1200 {
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1201 int prevval;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1202 int wrong;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1203
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1204 if (len != -1)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1205 {
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1206 prevval = key[len];
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1207 key[len] = NUL;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1208 }
4819
8c4324e6f477 updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1209 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1210 prevval = 0; // avoid compiler warning
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1211 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1212 && rettv->v_type == VAR_FUNC
21691
f41c646cb8b9 patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents: 21674
diff changeset
1213 && var_wrong_func_name(key, lp->ll_di == NULL))
26238
14b4c778b61e patch 8.2.3650: Vim9: for loop variable can be a list member
Bram Moolenaar <Bram@vim.org>
parents: 26053
diff changeset
1214 || !valid_varname(key, -1, TRUE);
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1215 if (len != -1)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1216 key[len] = prevval;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
1217 if (wrong)
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
1218 {
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
1219 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1220 return NULL;
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
1221 }
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1222 }
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1223
22529
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1224 if (lp->ll_valtype != NULL)
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1225 // use the type of the member
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1226 lp->ll_valtype = lp->ll_valtype->tt_member;
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1227
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1228 if (lp->ll_di == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1229 {
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
1230 // Can't add "v:" or "a:" variable.
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1231 if (lp->ll_dict == get_vimvar_dict()
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
1232 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht())
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1233 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1234 semsg(_(e_illegal_variable_name_str), name);
16013
93b08b92a049 patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents: 15969
diff changeset
1235 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1236 return NULL;
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1237 }
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1238
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
1239 // Key does not exist in dict: may need to add it.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1240 if (*p == '[' || *p == '.' || unlet)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1241 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1242 if (!quiet)
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1243 semsg(_(e_key_not_present_in_dictionary), key);
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1244 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1245 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1246 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1247 if (len == -1)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1248 lp->ll_newkey = vim_strsave(key);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1249 else
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1250 lp->ll_newkey = vim_strnsave(key, len);
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1251 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1252 if (lp->ll_newkey == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1253 p = NULL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1254 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1255 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1256 // existing variable, need to check if it can be changed
10912
fd1760f8c215 patch 8.0.0345: islocked('d.changedtick') does not work
Christian Brabandt <cb@256bit.org>
parents: 10910
diff changeset
1257 else if ((flags & GLV_READ_ONLY) == 0
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
1258 && (var_check_ro(lp->ll_di->di_flags, name, FALSE)
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
1259 || var_check_lock(lp->ll_di->di_flags, name, FALSE)))
10910
8bff367672a4 patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents: 10908
diff changeset
1260 {
8bff367672a4 patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents: 10908
diff changeset
1261 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1262 return NULL;
10910
8bff367672a4 patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents: 10908
diff changeset
1263 }
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
1264
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1265 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1266 lp->ll_tv = &lp->ll_di->di_tv;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1267 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1268 else if (lp->ll_tv->v_type == VAR_BLOB)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1269 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1270 long bloblen = blob_len(lp->ll_tv->vval.v_blob);
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1271
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1272 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1273 * Get the number and item for the only or first index of the List.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1274 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1275 if (empty1)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1276 lp->ll_n1 = 0;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1277 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1278 // is number or string
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1279 lp->ll_n1 = (long)tv_get_number(&var1);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1280 clear_tv(&var1);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1281
24454
53216e87f21c patch 8.2.2767: compiler warning for unused argument
Bram Moolenaar <Bram@vim.org>
parents: 24450
diff changeset
1282 if (check_blob_index(bloblen, lp->ll_n1, quiet) == FAIL)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1283 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1284 clear_tv(&var2);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1285 return NULL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1286 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1287 if (lp->ll_range && !lp->ll_empty2)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1288 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1289 lp->ll_n2 = (long)tv_get_number(&var2);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1290 clear_tv(&var2);
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
1291 if (check_blob_range(bloblen, lp->ll_n1, lp->ll_n2, quiet)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
1292 == FAIL)
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1293 return NULL;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1294 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1295 lp->ll_blob = lp->ll_tv->vval.v_blob;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1296 lp->ll_tv = NULL;
16036
89fb86821b4a patch 8.1.1023: may use NULL pointer when indexing a blob
Bram Moolenaar <Bram@vim.org>
parents: 16013
diff changeset
1297 break;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1298 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1299 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1300 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1301 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1302 * Get the number and item for the only or first index of the List.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1303 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1304 if (empty1)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1305 lp->ll_n1 = 0;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1306 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1307 // is number or string
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1308 lp->ll_n1 = (long)tv_get_number(&var1);
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1309 clear_tv(&var1);
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1310
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1311 lp->ll_dict = NULL;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1312 lp->ll_list = lp->ll_tv->vval.v_list;
25591
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1313 lp->ll_li = check_range_index_one(lp->ll_list, &lp->ll_n1, quiet);
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1314 if (lp->ll_li == NULL)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1315 {
25591
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1316 clear_tv(&var2);
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1317 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1318 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1319
22529
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1320 if (lp->ll_valtype != NULL)
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1321 // use the type of the member
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1322 lp->ll_valtype = lp->ll_valtype->tt_member;
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1323
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1324 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1325 * May need to find the item or absolute index for the second
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1326 * index of a range.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1327 * When no index given: "lp->ll_empty2" is TRUE.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1328 * Otherwise "lp->ll_n2" is set to the second index.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1329 */
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1330 if (lp->ll_range && !lp->ll_empty2)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1331 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1332 lp->ll_n2 = (long)tv_get_number(&var2);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1333 // is number or string
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1334 clear_tv(&var2);
25591
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1335 if (check_range_index_two(lp->ll_list,
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1336 &lp->ll_n1, lp->ll_li,
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1337 &lp->ll_n2, quiet) == FAIL)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1338 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1339 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1340
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1341 lp->ll_tv = &lp->ll_li->li_tv;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1342 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1343 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1344
10926
7dab3a9cb933 patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents: 10912
diff changeset
1345 clear_tv(&var1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1346 lp->ll_name_end = p;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1347 return p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1348 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1349
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1350 /*
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1351 * Clear lval "lp" that was filled by get_lval().
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1352 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1353 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1354 clear_lval(lval_T *lp)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1355 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1356 vim_free(lp->ll_exp_name);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1357 vim_free(lp->ll_newkey);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1358 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1359
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1360 /*
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1361 * Set a variable that was parsed by get_lval() to "rettv".
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1362 * "endp" points to just after the parsed name.
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1363 * "op" is NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=",
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1364 * "%" for "%=", "." for ".=" or "=" for "=".
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1365 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
1366 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1367 set_var_lval(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1368 lval_T *lp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1369 char_u *endp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1370 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1371 int copy,
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23835
diff changeset
1372 int flags, // ASSIGN_CONST, ASSIGN_NO_DECL
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23835
diff changeset
1373 char_u *op,
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23835
diff changeset
1374 int var_idx) // index for "let [a, b] = list"
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1375 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1376 int cc;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1377 dictitem_T *di;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1378
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1379 if (lp->ll_tv == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1380 {
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1381 cc = *endp;
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1382 *endp = NUL;
24717
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24713
diff changeset
1383 if (in_vim9script() && check_reserved_name(lp->ll_name) == FAIL)
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24713
diff changeset
1384 return;
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24713
diff changeset
1385
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1386 if (lp->ll_blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1387 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1388 int error = FALSE, val;
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1389
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1390 if (op != NULL && *op != '=')
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1391 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1392 semsg(_(e_wrong_variable_type_for_str_equal), op);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1393 return;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1394 }
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
1395 if (value_check_lock(lp->ll_blob->bv_lock, lp->ll_name, FALSE))
21847
fb74a3387694 patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents: 21837
diff changeset
1396 return;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1397
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1398 if (lp->ll_range && rettv->v_type == VAR_BLOB)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1399 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1400 if (lp->ll_empty2)
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1401 lp->ll_n2 = blob_len(lp->ll_blob) - 1;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1402
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
1403 if (blob_set_range(lp->ll_blob, lp->ll_n1, lp->ll_n2,
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
1404 rettv) == FAIL)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1405 return;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1406 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1407 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1408 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1409 val = (int)tv_get_number_chk(rettv, &error);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1410 if (!error)
24486
5e0db87e5184 patch 8.2.2783: duplicate code for setting byte in blob, blob test may fail
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
1411 blob_set_append(lp->ll_blob, lp->ll_n1, val);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1412 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1413 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1414 else if (op != NULL && *op != '=')
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1415 {
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1416 typval_T tv;
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1417
24440
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1418 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL))
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1419 && (flags & ASSIGN_FOR_LOOP) == 0)
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1420 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1421 emsg(_(e_cannot_modify_existing_variable));
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1422 *endp = cc;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1423 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1424 }
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1425
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1426 // handle +=, -=, *=, /=, %= and .=
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1427 di = NULL;
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
1428 if (eval_variable(lp->ll_name, (int)STRLEN(lp->ll_name),
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
1429 lp->ll_sid, &tv, &di, EVAL_VAR_VERBOSE) == OK)
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1430 {
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1431 if ((di == NULL
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
1432 || (!var_check_ro(di->di_flags, lp->ll_name, FALSE)
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
1433 && !tv_check_lock(&di->di_tv, lp->ll_name, FALSE)))
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1434 && tv_op(&tv, rettv, op) == OK)
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
1435 set_var_const(lp->ll_name, lp->ll_sid, NULL, &tv, FALSE,
25284
29191571eceb patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents: 25280
diff changeset
1436 ASSIGN_NO_DECL, 0);
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1437 clear_tv(&tv);
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1438 }
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1439 }
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1440 else
21443
66386ca8a69f patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
1441 {
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1442 if (lp->ll_type != NULL && check_typval_arg_type(lp->ll_type, rettv,
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1443 NULL, 0) == FAIL)
21443
66386ca8a69f patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
1444 return;
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
1445 set_var_const(lp->ll_name, lp->ll_sid, lp->ll_type, rettv, copy,
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23835
diff changeset
1446 flags, var_idx);
21443
66386ca8a69f patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
1447 }
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1448 *endp = cc;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1449 }
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
1450 else if (value_check_lock(lp->ll_newkey == NULL
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1451 ? lp->ll_tv->v_lock
6773
eb4b705a5d6a patch 7.4.708
Bram Moolenaar <bram@vim.org>
parents: 6761
diff changeset
1452 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE))
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1453 ;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1454 else if (lp->ll_range)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1455 {
24440
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1456 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL))
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1457 && (flags & ASSIGN_FOR_LOOP) == 0)
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1458 {
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
1459 emsg(_(e_cannot_lock_range));
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1460 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1461 }
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1462
25591
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1463 (void)list_assign_range(lp->ll_list, rettv->vval.v_list,
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1464 lp->ll_n1, lp->ll_n2, lp->ll_empty2, op, lp->ll_name);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1465 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1466 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1467 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1468 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1469 * Assign to a List or Dictionary item.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1470 */
24440
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1471 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL))
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1472 && (flags & ASSIGN_FOR_LOOP) == 0)
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1473 {
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
1474 emsg(_(e_cannot_lock_list_or_dict));
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1475 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1476 }
22529
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1477
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1478 if (lp->ll_valtype != NULL
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1479 && check_typval_arg_type(lp->ll_valtype, rettv,
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1480 NULL, 0) == FAIL)
22529
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1481 return;
35ef9b0a81a3 patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
1482
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1483 if (lp->ll_newkey != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1484 {
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1485 if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1486 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1487 semsg(_(e_key_not_present_in_dictionary), lp->ll_newkey);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1488 return;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1489 }
24764
3907cf9be745 patch 8.2.2920: still a way to shadow a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 24760
diff changeset
1490 if (dict_wrong_func_name(lp->ll_tv->vval.v_dict, rettv,
3907cf9be745 patch 8.2.2920: still a way to shadow a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 24760
diff changeset
1491 lp->ll_newkey))
24760
ca0f983f08cf patch 8.2.2918: builtin function can be shadowed by global variable
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
1492 return;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1493
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1494 // Need to add an item to the Dictionary.
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1495 di = dictitem_alloc(lp->ll_newkey);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1496 if (di == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1497 return;
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1498 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL)
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1499 {
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1500 vim_free(di);
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1501 return;
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1502 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1503 lp->ll_tv = &di->di_tv;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1504 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1505 else if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1506 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1507 tv_op(lp->ll_tv, rettv, op);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1508 return;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1509 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1510 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1511 clear_tv(lp->ll_tv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1512
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1513 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1514 * Assign the value to the variable or list item.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1515 */
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1516 if (copy)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1517 copy_tv(rettv, lp->ll_tv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1518 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1519 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1520 *lp->ll_tv = *rettv;
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
1521 lp->ll_tv->v_lock = 0;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1522 init_tv(rettv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1523 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1524 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1527 /*
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1528 * Handle "tv1 += tv2", "tv1 -= tv2", "tv1 *= tv2", "tv1 /= tv2", "tv1 %= tv2"
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1529 * and "tv1 .= tv2"
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1530 * Returns OK or FAIL.
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1531 */
25591
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25521
diff changeset
1532 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1533 tv_op(typval_T *tv1, typval_T *tv2, char_u *op)
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1534 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
1535 varnumber_T n;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1536 char_u numbuf[NUMBUFLEN];
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1537 char_u *s;
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
1538 int failed = FALSE;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1539
25455
e7c02cbe701f patch 8.2.3264: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 25425
diff changeset
1540 // Can't do anything with a Funcref or Dict on the right.
e7c02cbe701f patch 8.2.3264: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 25425
diff changeset
1541 // v:true and friends only work with "..=".
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
1542 if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT
25455
e7c02cbe701f patch 8.2.3264: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 25425
diff changeset
1543 && ((tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL)
e7c02cbe701f patch 8.2.3264: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 25425
diff changeset
1544 || *op == '.'))
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1545 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1546 switch (tv1->v_type)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1547 {
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
1548 case VAR_UNKNOWN:
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
1549 case VAR_ANY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1550 case VAR_VOID:
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1551 case VAR_DICT:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1552 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
1553 case VAR_PARTIAL:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
1554 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
1555 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
1556 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
1557 case VAR_CHANNEL:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
1558 case VAR_INSTR:
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1559 break;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1560
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1561 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1562 if (*op != '+' || tv2->v_type != VAR_BLOB)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1563 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1564 // BLOB += BLOB
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1565 if (tv1->vval.v_blob != NULL && tv2->vval.v_blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1566 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1567 blob_T *b1 = tv1->vval.v_blob;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1568 blob_T *b2 = tv2->vval.v_blob;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1569 int i, len = blob_len(b2);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1570 for (i = 0; i < len; i++)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1571 ga_append(&b1->bv_ga, blob_get(b2, i));
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1572 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1573 return OK;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1574
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1575 case VAR_LIST:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1576 if (*op != '+' || tv2->v_type != VAR_LIST)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1577 break;
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1578 // List += List
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1579 if (tv2->vval.v_list != NULL)
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1580 {
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1581 if (tv1->vval.v_list == NULL)
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1582 {
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1583 tv1->vval.v_list = tv2->vval.v_list;
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1584 ++tv1->vval.v_list->lv_refcount;
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1585 }
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1586 else
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1587 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
1588 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1589 return OK;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1590
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1591 case VAR_NUMBER:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1592 case VAR_STRING:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1593 if (tv2->v_type == VAR_LIST)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1594 break;
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1595 if (vim_strchr((char_u *)"+-*/%", *op) != NULL)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1596 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1597 // nr += nr , nr -= nr , nr *=nr , nr /= nr , nr %= nr
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1598 n = tv_get_number(tv1);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1599 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1600 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1601 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1602 float_T f = n;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1603
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1604 if (*op == '%')
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1605 break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1606 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1607 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1608 case '+': f += tv2->vval.v_float; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1609 case '-': f -= tv2->vval.v_float; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1610 case '*': f *= tv2->vval.v_float; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1611 case '/': f /= tv2->vval.v_float; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1612 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1613 clear_tv(tv1);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1614 tv1->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1615 tv1->vval.v_float = f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1616 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1617 else
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1618 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1619 {
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1620 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1621 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1622 case '+': n += tv_get_number(tv2); break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1623 case '-': n -= tv_get_number(tv2); break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1624 case '*': n *= tv_get_number(tv2); break;
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
1625 case '/': n = num_divide(n, tv_get_number(tv2),
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
1626 &failed); break;
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
1627 case '%': n = num_modulus(n, tv_get_number(tv2),
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
1628 &failed); break;
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1629 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1630 clear_tv(tv1);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1631 tv1->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1632 tv1->vval.v_number = n;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1633 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1634 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1635 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1636 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1637 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1638 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1639
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1640 // str .= str
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1641 s = tv_get_string(tv1);
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1642 s = concat_str(s, tv_get_string_buf(tv2, numbuf));
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1643 clear_tv(tv1);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1644 tv1->v_type = VAR_STRING;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1645 tv1->vval.v_string = s;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1646 }
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
1647 return failed ? FAIL : OK;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1648
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1649 case VAR_FLOAT:
8364
991d8fd4d841 commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents: 8350
diff changeset
1650 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1651 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1652 float_T f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1653
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1654 if (*op == '%' || *op == '.'
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1655 || (tv2->v_type != VAR_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1656 && tv2->v_type != VAR_NUMBER
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1657 && tv2->v_type != VAR_STRING))
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1658 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1659 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1660 f = tv2->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1661 else
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1662 f = tv_get_number(tv2);
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1663 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1664 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1665 case '+': tv1->vval.v_float += f; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1666 case '-': tv1->vval.v_float -= f; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1667 case '*': tv1->vval.v_float *= f; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1668 case '/': tv1->vval.v_float /= f; break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1669 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1670 }
8364
991d8fd4d841 commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents: 8350
diff changeset
1671 #endif
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1672 return OK;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1673 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1674 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1675
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1676 semsg(_(e_wrong_variable_type_for_str_equal), op);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1677 return FAIL;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1678 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1679
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1680 /*
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1681 * Evaluate the expression used in a ":for var in expr" command.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1682 * "arg" points to "var".
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1683 * Set "*errp" to TRUE for an error, FALSE otherwise;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1684 * Return a pointer that holds the info. Null when there is an error.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1685 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1686 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1687 eval_for_line(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1688 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1689 int *errp,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1690 exarg_T *eap,
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1691 evalarg_T *evalarg)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1692 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1693 forinfo_T *fi;
25149
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1694 char_u *var_list_end;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1695 char_u *expr;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1696 typval_T tv;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1697 list_T *l;
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1698 int skip = !(evalarg->eval_flags & EVAL_EVALUATE);
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1699
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1700 *errp = TRUE; // default: there is an error
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1701
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16796
diff changeset
1702 fi = ALLOC_CLEAR_ONE(forinfo_T);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1703 if (fi == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1704 return NULL;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1705
25149
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1706 var_list_end = skip_var_list(arg, TRUE, &fi->fi_varcount,
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1707 &fi->fi_semicolon, FALSE);
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1708 if (var_list_end == NULL)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1709 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1710
25149
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1711 expr = skipwhite_and_linebreak(var_list_end, evalarg);
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1712 if (expr[0] != 'i' || expr[1] != 'n'
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1713 || !(expr[2] == NUL || VIM_ISWHITE(expr[2])))
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1714 {
25149
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1715 if (in_vim9script() && *expr == ':' && expr != var_list_end)
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1716 semsg(_(e_no_white_space_allowed_before_colon_str), expr);
18b31f0a4bb5 patch 8.2.3111: Vim9: confusing error with extra whitespace before colon
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1717 else
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
1718 emsg(_(e_missing_in_after_for));
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1719 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1720 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1721
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1722 if (skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1723 ++emsg_skip;
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1724 expr = skipwhite_and_linebreak(expr + 2, evalarg);
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1725 if (eval0(expr, &tv, eap, evalarg) == OK)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1726 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1727 *errp = FALSE;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1728 if (!skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1729 {
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1730 if (tv.v_type == VAR_LIST)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1731 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1732 l = tv.vval.v_list;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1733 if (l == NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1734 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1735 // a null list is like an empty list: do nothing
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1736 clear_tv(&tv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1737 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1738 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1739 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1740 // Need a real list here.
20392
4c317d8c1051 patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
1741 CHECK_LIST_MATERIALIZE(l);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1742
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1743 // No need to increment the refcount, it's already set for
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1744 // the list being used in "tv".
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1745 fi->fi_list = l;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1746 list_add_watch(l, &fi->fi_lw);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1747 fi->fi_lw.lw_item = l->lv_first;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1748 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1749 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1750 else if (tv.v_type == VAR_BLOB)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1751 {
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1752 fi->fi_bi = 0;
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1753 if (tv.vval.v_blob != NULL)
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1754 {
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1755 typval_T btv;
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1756
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1757 // Make a copy, so that the iteration still works when the
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1758 // blob is changed.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1759 blob_copy(tv.vval.v_blob, &btv);
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1760 fi->fi_blob = btv.vval.v_blob;
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1761 }
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1762 clear_tv(&tv);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1763 }
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1764 else if (tv.v_type == VAR_STRING)
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1765 {
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1766 fi->fi_byte_idx = 0;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1767 fi->fi_string = tv.vval.v_string;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1768 tv.vval.v_string = NULL;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1769 if (fi->fi_string == NULL)
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1770 fi->fi_string = vim_strsave((char_u *)"");
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1771 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1772 else
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1773 {
25495
7144d2ffc86b patch 8.2.3284: no error for insert() or remove() changing a locked blob
Bram Moolenaar <Bram@vim.org>
parents: 25455
diff changeset
1774 emsg(_(e_string_list_or_blob_required));
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1775 clear_tv(&tv);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1776 }
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1777 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1778 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1779 if (skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1780 --emsg_skip;
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1781 fi->fi_break_count = evalarg->eval_break_count;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1782
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1783 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1784 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1785
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1786 /*
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1787 * Used when looping over a :for line, skip the "in expr" part.
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1788 */
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1789 void
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1790 skip_for_lines(void *fi_void, evalarg_T *evalarg)
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1791 {
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1792 forinfo_T *fi = (forinfo_T *)fi_void;
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1793 int i;
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1794
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1795 for (i = 0; i < fi->fi_break_count; ++i)
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1796 eval_next_line(evalarg);
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1797 }
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1798
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
1799 /*
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1800 * Use the first item in a ":for" list. Advance to the next.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1801 * Assign the values to the variable (list). "arg" points to the first one.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1802 * Return TRUE when a valid item was found, FALSE when at end of list or
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1803 * something wrong.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1804 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1805 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1806 next_for_item(void *fi_void, char_u *arg)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1807 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4936
diff changeset
1808 forinfo_T *fi = (forinfo_T *)fi_void;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1809 int result;
24440
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1810 int flag = ASSIGN_FOR_LOOP | (in_vim9script()
25153
610e15e8778d patch 8.2.3113: no error when for loop variable shadows script variable
Bram Moolenaar <Bram@vim.org>
parents: 25149
diff changeset
1811 ? (ASSIGN_FINAL
610e15e8778d patch 8.2.3113: no error when for loop variable shadows script variable
Bram Moolenaar <Bram@vim.org>
parents: 25149
diff changeset
1812 // first round: error if variable exists
610e15e8778d patch 8.2.3113: no error when for loop variable shadows script variable
Bram Moolenaar <Bram@vim.org>
parents: 25149
diff changeset
1813 | (fi->fi_bi == 0 ? 0 : ASSIGN_DECL)
610e15e8778d patch 8.2.3113: no error when for loop variable shadows script variable
Bram Moolenaar <Bram@vim.org>
parents: 25149
diff changeset
1814 | ASSIGN_NO_MEMBER_TYPE)
24440
d2f9bdd938fa patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
1815 : 0);
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1816 listitem_T *item;
25280
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1817 int skip_assign = in_vim9script() && arg[0] == '_'
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1818 && !eval_isnamec(arg[1]);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1819
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1820 if (fi->fi_blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1821 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1822 typval_T tv;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1823
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1824 if (fi->fi_bi >= blob_len(fi->fi_blob))
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1825 return FALSE;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1826 tv.v_type = VAR_NUMBER;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1827 tv.v_lock = VAR_FIXED;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1828 tv.vval.v_number = blob_get(fi->fi_blob, fi->fi_bi);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1829 ++fi->fi_bi;
25280
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1830 if (skip_assign)
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1831 return TRUE;
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1832 return ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1833 fi->fi_varcount, flag, NULL) == OK;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1834 }
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1835
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1836 if (fi->fi_string != NULL)
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1837 {
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1838 typval_T tv;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1839 int len;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1840
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1841 len = mb_ptr2len(fi->fi_string + fi->fi_byte_idx);
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1842 if (len == 0)
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1843 return FALSE;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1844 tv.v_type = VAR_STRING;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1845 tv.v_lock = VAR_FIXED;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1846 tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len);
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1847 fi->fi_byte_idx += len;
25153
610e15e8778d patch 8.2.3113: no error when for loop variable shadows script variable
Bram Moolenaar <Bram@vim.org>
parents: 25149
diff changeset
1848 ++fi->fi_bi;
25280
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1849 if (skip_assign)
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1850 result = TRUE;
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1851 else
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1852 result = ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1853 fi->fi_varcount, flag, NULL) == OK;
24240
2194227d034a patch 8.2.2661: leaking memory when looping over a string
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
1854 vim_free(tv.vval.v_string);
2194227d034a patch 8.2.2661: leaking memory when looping over a string
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
1855 return result;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1856 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1857
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1858 item = fi->fi_lw.lw_item;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1859 if (item == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1860 result = FALSE;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1861 else
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1862 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1863 fi->fi_lw.lw_item = item->li_next;
25153
610e15e8778d patch 8.2.3113: no error when for loop variable shadows script variable
Bram Moolenaar <Bram@vim.org>
parents: 25149
diff changeset
1864 ++fi->fi_bi;
25280
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1865 if (skip_assign)
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1866 result = TRUE;
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1867 else
ca7a8ea2eb5f patch 8.2.3177: Vim9: can not use "for _ in expr" at script level
Bram Moolenaar <Bram@vim.org>
parents: 25276
diff changeset
1868 result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon,
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1869 fi->fi_varcount, flag, NULL) == OK);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1870 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1871 return result;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1872 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1873
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1874 /*
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1875 * Free the structure used to store info used by ":for".
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1876 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1877 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1878 free_for_info(void *fi_void)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1879 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1880 forinfo_T *fi = (forinfo_T *)fi_void;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1881
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1882 if (fi == NULL)
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1883 return;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1884 if (fi->fi_list != NULL)
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1885 {
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1886 list_rem_watch(fi->fi_list, &fi->fi_lw);
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1887 list_unref(fi->fi_list);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1888 }
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1889 else if (fi->fi_blob != NULL)
15460
543cff56dd3f patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15458
diff changeset
1890 blob_unref(fi->fi_blob);
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1891 else
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24194
diff changeset
1892 vim_free(fi->fi_string);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1893 vim_free(fi);
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1894 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1895
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1897 set_context_for_expression(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1898 expand_T *xp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1899 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1900 cmdidx_T cmdidx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 {
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1902 int has_expr = cmdidx != CMD_let && cmdidx != CMD_var;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 int c;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1904 char_u *p;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1905
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1906 if (cmdidx == CMD_let || cmdidx == CMD_var
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1907 || cmdidx == CMD_const || cmdidx == CMD_final)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1908 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1909 xp->xp_context = EXPAND_USER_VARS;
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
1910 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1911 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1912 // ":let var1 var2 ...": find last space.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
1913 for (p = arg + STRLEN(arg); p >= arg; )
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1914 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1915 xp->xp_pattern = p;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
1916 MB_PTR_BACK(arg, p);
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1917 if (VIM_ISWHITE(*p))
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1918 break;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1919 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1920 return;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1921 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1922 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1923 else
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1924 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1925 : EXPAND_EXPRESSION;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 while ((xp->xp_pattern = vim_strpbrk(arg,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 c = *xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 if (c == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 c = xp->xp_pattern[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 if (c == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 ++xp->xp_pattern;
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1936 xp->xp_context = has_expr ? EXPAND_EXPRESSION : EXPAND_NOTHING;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 else if (c != ' ')
201
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1939 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 xp->xp_context = EXPAND_SETTINGS;
201
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1941 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':')
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1942 xp->xp_pattern += 2;
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1943
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1944 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 else if (c == '$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1948 // environment variable
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 xp->xp_context = EXPAND_ENV_VARS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 else if (c == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 {
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1953 has_expr = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 }
8763
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1956 else if (c == '#'
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1957 && xp->xp_context == EXPAND_EXPRESSION)
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1958 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1959 // Autoload function/variable contains '#'.
8763
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1960 break;
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1961 }
6367
81c9b19ee0fb updated for version 7.4.516
Bram Moolenaar <bram@vim.org>
parents: 6361
diff changeset
1962 else if ((c == '<' || c == '#')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 && xp->xp_context == EXPAND_FUNCTIONS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 && vim_strchr(xp->xp_pattern, '(') == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1966 // Function name can start with "<SNR>" and contain '#'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 }
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1969 else if (has_expr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1971 if (c == '"') // string
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 while ((c = *++xp->xp_pattern) != NUL && c != '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 if (c == '\\' && xp->xp_pattern[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 xp->xp_context = EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1978 else if (c == '\'') // literal string
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1980 // Trick: '' is like stopping and starting a literal string.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 while ((c = *++xp->xp_pattern) != NUL && c != '\'')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 /* skip */ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 xp->xp_context = EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 else if (c == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 if (xp->xp_pattern[1] == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 xp->xp_context = EXPAND_COMMANDS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1999 // Doesn't look like something valid, expand as an expression
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2000 // anyway.
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
2001 xp->xp_context = EXPAND_EXPRESSION;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 arg = xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 if (*arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 while ((c = *++arg) != NUL && (c == ' ' || c == '\t'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 /* skip */ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 }
23322
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2007
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2008 // ":exe one two" completes "two"
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2009 if ((cmdidx == CMD_execute
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2010 || cmdidx == CMD_echo
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2011 || cmdidx == CMD_echon
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2012 || cmdidx == CMD_echomsg)
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2013 && xp->xp_context == EXPAND_EXPRESSION)
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2014 {
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2015 for (;;)
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2016 {
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2017 char_u *n = skiptowhite(arg);
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2018
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2019 if (n == arg || IS_WHITE_OR_NUL(*skipwhite(n)))
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2020 break;
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2021 arg = skipwhite(n);
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2022 }
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2023 }
68df9697667a patch 8.2.2206: :exe command line completion only works for first argument
Bram Moolenaar <Bram@vim.org>
parents: 23299
diff changeset
2024
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 xp->xp_pattern = arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 /*
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2029 * Return TRUE if "pat" matches "text".
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2030 * Does not use 'cpo' and always uses 'magic'.
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2031 */
17377
cb008de2a6ec patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17375
diff changeset
2032 int
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2033 pattern_match(char_u *pat, char_u *text, int ic)
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2034 {
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2035 int matches = FALSE;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2036 char_u *save_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2037 regmatch_T regmatch;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2038
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2039 // avoid 'l' flag in 'cpoptions'
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2040 save_cpo = p_cpo;
23493
f8382c4e6551 patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
2041 p_cpo = empty_option;
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2042 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2043 if (regmatch.regprog != NULL)
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2044 {
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2045 regmatch.rm_ic = ic;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2046 matches = vim_regexec_nl(&regmatch, text, (colnr_T)0);
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2047 vim_regfree(regmatch.regprog);
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2048 }
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2049 p_cpo = save_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2050 return matches;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2051 }
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2052
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
2053 /*
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2054 * Handle a name followed by "(". Both for just "name(arg)" and for
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2055 * "expr->name(arg)".
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2056 * Returns OK or FAIL.
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2057 */
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2058 static int
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2059 eval_func(
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2060 char_u **arg, // points to "(", will be advanced
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
2061 evalarg_T *evalarg,
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2062 char_u *name,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2063 int name_len,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2064 typval_T *rettv,
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2065 int flags,
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2066 typval_T *basetv) // "expr" for "expr->name(arg)"
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2067 {
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2068 int evaluate = flags & EVAL_EVALUATE;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2069 char_u *s = name;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2070 int len = name_len;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2071 partial_T *partial;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2072 int ret = OK;
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
2073 type_T *type = NULL;
26506
4a1d2abc2016 patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents: 26474
diff changeset
2074 int found_var = FALSE;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2075
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2076 if (!evaluate)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2077 check_vars(s, len);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2078
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2079 // If "s" is the name of a variable of type VAR_FUNC
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2080 // use its contents.
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
2081 s = deref_func_name(s, &len, &partial,
27233
73232ed49cf2 patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents: 27199
diff changeset
2082 in_vim9script() ? &type : NULL, !evaluate, FALSE, &found_var);
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2083
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2084 // Need to make a copy, in case evaluating the arguments makes
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2085 // the name invalid.
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2086 s = vim_strsave(s);
26562
479022b3e7bd patch 8.2.3810: Vim9: expr4 test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26560
diff changeset
2087 if (s == NULL || (evaluate && (*s == NUL || (flags & EVAL_CONSTANT))))
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2088 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2089 else
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2090 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2091 funcexe_T funcexe;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2092
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2093 // Invoke the function.
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
2094 CLEAR_FIELD(funcexe);
26534
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2095 funcexe.fe_firstline = curwin->w_cursor.lnum;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2096 funcexe.fe_lastline = curwin->w_cursor.lnum;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2097 funcexe.fe_evaluate = evaluate;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2098 funcexe.fe_partial = partial;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2099 funcexe.fe_basetv = basetv;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2100 funcexe.fe_check_type = type;
26506
4a1d2abc2016 patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents: 26474
diff changeset
2101 funcexe.fe_found_var = found_var;
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
2102 ret = get_func_tv(s, len, rettv, arg, evalarg, &funcexe);
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2103 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2104 vim_free(s);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2105
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2106 // If evaluate is FALSE rettv->v_type was not set in
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2107 // get_func_tv, but it's needed in handle_subscript() to parse
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2108 // what follows. So set it here.
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2109 if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(')
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2110 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2111 rettv->vval.v_string = NULL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2112 rettv->v_type = VAR_FUNC;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2113 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2114
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2115 // Stop the expression evaluation when immediately
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2116 // aborting on error, or when an interrupt occurred or
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2117 // an exception was thrown but not caught.
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2118 if (evaluate && aborting())
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2119 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2120 if (ret == OK)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2121 clear_tv(rettv);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2122 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2123 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2124 return ret;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2125 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2126
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2127 /*
22580
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2128 * Get the next line source line without advancing. But do skip over comment
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2129 * lines.
24553
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2130 * Only called for Vim9 script.
22580
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2131 */
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2132 static char_u *
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2133 getline_peek_skip_comments(evalarg_T *evalarg)
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2134 {
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2135 for (;;)
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2136 {
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2137 char_u *next = getline_peek(evalarg->eval_getline,
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2138 evalarg->eval_cookie);
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2139 char_u *p;
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2140
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2141 if (next == NULL)
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2142 break;
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2143 p = skipwhite(next);
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2144 if (*p != NUL && !vim9_comment_start(p))
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2145 return next;
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2146 (void)eval_next_line(evalarg);
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2147 }
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2148 return NULL;
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2149 }
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2150
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2151 /*
21148
667192c5938b patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents: 21142
diff changeset
2152 * If inside Vim9 script, "arg" points to the end of a line (ignoring a #
667192c5938b patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents: 21142
diff changeset
2153 * comment) and there is a next line, return the next line (skipping blanks)
667192c5938b patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents: 21142
diff changeset
2154 * and set "getnext".
24525
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24518
diff changeset
2155 * Otherwise return the next non-white at or after "arg" and set "getnext" to
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24518
diff changeset
2156 * FALSE.
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2157 * "arg" must point somewhere inside a line, not at the start.
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2158 */
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2159 char_u *
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2160 eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2161 {
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2162 char_u *p = skipwhite(arg);
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2163
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2164 *getnext = FALSE;
21279
8d1d11afd8c8 patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents: 21277
diff changeset
2165 if (in_vim9script()
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2166 && evalarg != NULL
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
2167 && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL)
24525
887121a6d7cf patch 8.2.2802: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24518
diff changeset
2168 && (*p == NUL || (vim9_comment_start(p) && VIM_ISWHITE(p[-1]))))
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2169 {
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2170 char_u *next;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
2171
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
2172 if (evalarg->eval_cookie != NULL)
22580
eb54d34ecd27 patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Bram Moolenaar <Bram@vim.org>
parents: 22541
diff changeset
2173 next = getline_peek_skip_comments(evalarg);
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
2174 else
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2175 next = peek_next_line_from_context(evalarg->eval_cctx);
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2176
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2177 if (next != NULL)
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2178 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2179 *getnext = TRUE;
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2180 return skipwhite(next);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2181 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2182 }
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2183 return p;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2184 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2185
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2186 /*
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2187 * To be called after eval_next_non_blank() sets "getnext" to TRUE.
24553
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2188 * Only called for Vim9 script.
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2189 */
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2190 char_u *
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2191 eval_next_line(evalarg_T *evalarg)
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2192 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2193 garray_T *gap = &evalarg->eval_ga;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2194 char_u *line;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2195
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
2196 if (evalarg->eval_cookie != NULL)
21889
e7e485a60caf patch 8.2.1494: missing change to calling eval_getline()
Bram Moolenaar <Bram@vim.org>
parents: 21865
diff changeset
2197 line = evalarg->eval_getline(0, evalarg->eval_cookie, 0,
e7e485a60caf patch 8.2.1494: missing change to calling eval_getline()
Bram Moolenaar <Bram@vim.org>
parents: 21865
diff changeset
2198 GETLINE_CONCAT_ALL);
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
2199 else
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
2200 line = next_line_from_context(evalarg->eval_cctx, TRUE);
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
2201 ++evalarg->eval_break_count;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2202 if (gap->ga_itemsize > 0 && ga_grow(gap, 1) == OK)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2203 {
24553
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2204 char_u *p = skipwhite(line);
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2205
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2206 // Going to concatenate the lines after parsing. For an empty or
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2207 // comment line use an empty string.
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2208 if (*p == NUL || vim9_comment_start(p))
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2209 {
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2210 vim_free(line);
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2211 line = vim_strsave((char_u *)"");
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2212 }
cb0d344bd381 patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2213
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2214 ((char_u **)gap->ga_data)[gap->ga_len] = line;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2215 ++gap->ga_len;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2216 }
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2217 else if (evalarg->eval_cookie != NULL)
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2218 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2219 vim_free(evalarg->eval_tofree);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2220 evalarg->eval_tofree = line;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2221 }
25276
d26dc79c533f patch 8.2.3175: Vim9: using illegal pointer with nested lambdas.
Bram Moolenaar <Bram@vim.org>
parents: 25220
diff changeset
2222
d26dc79c533f patch 8.2.3175: Vim9: using illegal pointer with nested lambdas.
Bram Moolenaar <Bram@vim.org>
parents: 25220
diff changeset
2223 // Advanced to the next line, "arg" no longer points into the previous
d26dc79c533f patch 8.2.3175: Vim9: using illegal pointer with nested lambdas.
Bram Moolenaar <Bram@vim.org>
parents: 25220
diff changeset
2224 // line.
26053
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2225 evalarg->eval_using_cmdline = FALSE;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2226 return skipwhite(line);
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2227 }
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2228
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
2229 /*
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
2230 * Call eval_next_non_blank() and get the next line if needed.
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
2231 */
21046
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2232 char_u *
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2233 skipwhite_and_linebreak(char_u *arg, evalarg_T *evalarg)
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2234 {
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2235 int getnext;
26572
9f7568104726 patch 8.2.3815: Vim9: cannot have a multi-line dict inside a block
Bram Moolenaar <Bram@vim.org>
parents: 26562
diff changeset
2236 char_u *p = skipwhite_and_nl(arg);
21046
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2237
21148
667192c5938b patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents: 21142
diff changeset
2238 if (evalarg == NULL)
667192c5938b patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents: 21142
diff changeset
2239 return skipwhite(arg);
21046
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2240 eval_next_non_blank(p, evalarg, &getnext);
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2241 if (getnext)
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2242 return eval_next_line(evalarg);
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2243 return p;
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2244 }
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2245
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2246 /*
26053
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2247 * Initialize "evalarg" for use.
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2248 */
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2249 void
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2250 init_evalarg(evalarg_T *evalarg)
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2251 {
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2252 CLEAR_POINTER(evalarg);
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2253 ga_init2(&evalarg->eval_tofree_ga, sizeof(char_u *), 20);
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2254 }
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2255
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2256 /*
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2257 * After using "evalarg" filled from "eap": free the memory.
21050
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2258 */
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2259 void
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2260 clear_evalarg(evalarg_T *evalarg, exarg_T *eap)
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2261 {
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2262 if (evalarg != NULL)
21050
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2263 {
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2264 if (evalarg->eval_tofree != NULL)
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
2265 {
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2266 if (eap != NULL)
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2267 {
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2268 // We may need to keep the original command line, e.g. for
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2269 // ":let" it has the variable names. But we may also need the
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2270 // new one, "nextcmd" points into it. Keep both.
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2271 vim_free(eap->cmdline_tofree);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2272 eap->cmdline_tofree = *eap->cmdlinep;
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2273 *eap->cmdlinep = evalarg->eval_tofree;
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2274 }
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2275 else
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2276 vim_free(evalarg->eval_tofree);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2277 evalarg->eval_tofree = NULL;
21058
111f877e63d9 patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 21056
diff changeset
2278 }
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
2279
26053
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2280 ga_clear_strings(&evalarg->eval_tofree_ga);
24190
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24174
diff changeset
2281 VIM_CLEAR(evalarg->eval_tofree_lambda);
21050
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2282 }
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2283 }
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2284
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
2285 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 * The "evaluate" argument: When FALSE, the argument is only parsed but not
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2287 * executed. The function may return OK, but the rettv will be of type
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 * VAR_UNKNOWN. The function still returns FAIL for a syntax error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 * Handle zero level expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 * This calls eval1() and handles error message and nextcmd.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2294 * Put the result in "rettv" when returning OK and "evaluate" is TRUE.
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
2295 * Note: "rettv.v_lock" is not set.
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2296 * "evalarg" can be NULL, EVALARG_EVALUATE or a pointer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
2299 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2300 eval0(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2301 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2302 typval_T *rettv,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2303 exarg_T *eap,
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2304 evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 {
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2306 return eval0_retarg(arg, rettv, eap, evalarg, NULL);
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2307 }
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2308
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2309 /*
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2310 * Like eval0() but when "retarg" is not NULL store the pointer to after the
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2311 * expression and don't check what comes after the expression.
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2312 */
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2313 int
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2314 eval0_retarg(
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2315 char_u *arg,
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2316 typval_T *rettv,
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2317 exarg_T *eap,
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2318 evalarg_T *evalarg,
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2319 char_u **retarg)
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2320 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 int ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 char_u *p;
26614
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2323 char_u *expr_end;
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
2324 int did_emsg_before = did_emsg;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
2325 int called_emsg_before = called_emsg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2326 int flags = evalarg == NULL ? 0 : evalarg->eval_flags;
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2327 int check_for_end = retarg == NULL;
24958
21ec48d542a8 patch 8.2.3016: confusing error when expression is followed by comma
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
2328 int end_error = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 p = skipwhite(arg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2331 ret = eval1(&p, rettv, evalarg);
26614
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2332 expr_end = p;
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2333 p = skipwhite(p);
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2334
26614
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2335 // In Vim9 script a command block is not split at NL characters for
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2336 // commands using an expression argument. Skip over a '#' comment to check
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2337 // for a following NL. Require white space before the '#'.
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2338 if (in_vim9script() && p > expr_end && retarg == NULL)
26614
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2339 while (*p == '#')
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2340 {
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2341 char_u *nl = vim_strchr(p, NL);
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2342
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2343 if (nl == NULL)
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2344 break;
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2345 p = skipwhite(nl + 1);
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2346 if (eap != NULL && *p != NUL)
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2347 eap->nextcmd = p;
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2348 check_for_end = FALSE;
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2349 }
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2350
d9425f5d4b20 patch 8.2.3836: Vim9: comment after expression not skipped to find NL
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
2351 if (ret != FAIL && check_for_end)
24958
21ec48d542a8 patch 8.2.3016: confusing error when expression is followed by comma
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
2352 end_error = !ends_excmd2(arg, p);
21ec48d542a8 patch 8.2.3016: confusing error when expression is followed by comma
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
2353 if (ret == FAIL || end_error)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 if (ret != FAIL)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2356 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 * Report the invalid expression unless the expression evaluation has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 * been cancelled due to an aborting error, an interrupt, or an
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
2360 * exception, or we already gave a more specific error.
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
2361 * Also check called_emsg for when using assert_fails().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 */
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2363 if (!aborting()
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2364 && did_emsg == did_emsg_before
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2365 && called_emsg == called_emsg_before
24174
99bfaa4693db patch 8.2.2628: Vim9: #{ can still be used at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
2366 && (flags & EVAL_CONSTANT) == 0
99bfaa4693db patch 8.2.2628: Vim9: #{ can still be used at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
2367 && (!in_vim9script() || !vim9_bad_comment(p)))
24958
21ec48d542a8 patch 8.2.3016: confusing error when expression is followed by comma
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
2368 {
21ec48d542a8 patch 8.2.3016: confusing error when expression is followed by comma
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
2369 if (end_error)
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
2370 semsg(_(e_trailing_characters_str), p);
24958
21ec48d542a8 patch 8.2.3016: confusing error when expression is followed by comma
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
2371 else
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
2372 semsg(_(e_invalid_expression_str), arg);
24958
21ec48d542a8 patch 8.2.3016: confusing error when expression is followed by comma
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
2373 }
23096
b6aadb0b3a56 patch 8.2.2094: when an expression fails getting next command may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2374
b6aadb0b3a56 patch 8.2.2094: when an expression fails getting next command may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2375 // Some of the expression may not have been consumed. Do not check for
23191
3e7723bab4e5 patch 8.2.2141: a user command with try/catch may not catch an expression error
Bram Moolenaar <Bram@vim.org>
parents: 23096
diff changeset
2376 // a next command to avoid more errors, unless "|" is following, which
3e7723bab4e5 patch 8.2.2141: a user command with try/catch may not catch an expression error
Bram Moolenaar <Bram@vim.org>
parents: 23096
diff changeset
2377 // could only be a command separator.
3e7723bab4e5 patch 8.2.2141: a user command with try/catch may not catch an expression error
Bram Moolenaar <Bram@vim.org>
parents: 23096
diff changeset
2378 if (eap != NULL && skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|')
3e7723bab4e5 patch 8.2.2141: a user command with try/catch may not catch an expression error
Bram Moolenaar <Bram@vim.org>
parents: 23096
diff changeset
2379 eap->nextcmd = check_nextcmd(p);
23096
b6aadb0b3a56 patch 8.2.2094: when an expression fails getting next command may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
2380 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 }
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2382
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2383 if (retarg != NULL)
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2384 *retarg = p;
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
2385 else if (check_for_end && eap != NULL)
25521
2063b858cad9 patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
2386 set_nextcmd(eap, p);
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2387
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 * Handle top level expression:
1800
e7633eb32cfd updated for version 7.2-098
vimboss
parents: 1794
diff changeset
2393 * expr2 ? expr1 : expr1
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2394 * expr2 ?? expr1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 * "arg" must point to the first non-white of the expression.
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2397 * "arg" is advanced to just after the recognized expression.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 *
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
2399 * Note: "rettv.v_lock" is not set.
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
2400 *
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
2403 int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2404 eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 {
21022
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2406 char_u *p;
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2407 int getnext;
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2408
22246
6f83d2adee74 patch 8.2.1672: v_lock is used when it is not initialized
Bram Moolenaar <Bram@vim.org>
parents: 22244
diff changeset
2409 CLEAR_POINTER(rettv);
6f83d2adee74 patch 8.2.1672: v_lock is used when it is not initialized
Bram Moolenaar <Bram@vim.org>
parents: 22244
diff changeset
2410
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2414 if (eval2(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416
21022
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2417 p = eval_next_non_blank(*arg, evalarg, &getnext);
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2418 if (*p == '?')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2420 int op_falsy = p[1] == '?';
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2421 int result;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2422 typval_T var2;
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2423 evalarg_T *evalarg_used = evalarg;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2424 evalarg_T local_evalarg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2425 int orig_flags;
21002
4852db420162 patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
2426 int evaluate;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2427 int vim9script = in_vim9script();
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2428
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2429 if (evalarg == NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2430 {
26053
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2431 init_evalarg(&local_evalarg);
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2432 evalarg_used = &local_evalarg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2433 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2434 orig_flags = evalarg_used->eval_flags;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2435 evaluate = evalarg_used->eval_flags & EVAL_EVALUATE;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2436
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2437 if (getnext)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2438 *arg = eval_next_line(evalarg_used);
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2439 else
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2440 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2441 if (evaluate && vim9script && !VIM_ISWHITE(p[-1]))
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2442 {
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
2443 error_white_both(p, op_falsy ? 2 : 1);
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2444 clear_tv(rettv);
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2445 return FAIL;
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2446 }
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2447 *arg = p;
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2448 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2449
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 result = FALSE;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2451 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2453 int error = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2454
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2455 if (op_falsy)
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
2456 result = tv2bool(rettv);
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2457 else if (vim9script)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2458 result = tv_get_bool_chk(rettv, &error);
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
2459 else if (tv_get_number_chk(rettv, &error) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 result = TRUE;
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2461 if (error || !op_falsy || !result)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2462 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2463 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2464 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 /*
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2468 * Get the second variable. Recursive!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 */
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2470 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2471 ++*arg;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2472 if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[1]))
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2473 {
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2474 error_white_both(*arg - (op_falsy ? 1 : 0), op_falsy ? 2 : 1);
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2475 clear_tv(rettv);
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2476 return FAIL;
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2477 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2478 *arg = skipwhite_and_linebreak(*arg + 1, evalarg_used);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2479 evalarg_used->eval_flags = (op_falsy ? !result : result)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2480 ? orig_flags : orig_flags & ~EVAL_EVALUATE;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2481 if (eval1(arg, &var2, evalarg_used) == FAIL)
21925
51d591dbb8df patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents: 21915
diff changeset
2482 {
51d591dbb8df patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents: 21915
diff changeset
2483 evalarg_used->eval_flags = orig_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 return FAIL;
21925
51d591dbb8df patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents: 21915
diff changeset
2485 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2486 if (!op_falsy || !result)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2487 *rettv = var2;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2488
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2489 if (!op_falsy)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2491 /*
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2492 * Check for the ":".
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2493 */
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2494 p = eval_next_non_blank(*arg, evalarg_used, &getnext);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2495 if (*p != ':')
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2496 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26572
diff changeset
2497 emsg(_(e_missing_colon_after_questionmark));
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2498 if (evaluate && result)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2499 clear_tv(rettv);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2500 evalarg_used->eval_flags = orig_flags;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2501 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2502 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2503 if (getnext)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2504 *arg = eval_next_line(evalarg_used);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2505 else
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2506 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2507 if (evaluate && vim9script && !VIM_ISWHITE(p[-1]))
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2508 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2509 error_white_both(p, 1);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2510 clear_tv(rettv);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2511 evalarg_used->eval_flags = orig_flags;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2512 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2513 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2514 *arg = p;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2515 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2516
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2517 /*
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2518 * Get the third variable. Recursive!
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2519 */
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2520 if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[1]))
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2521 {
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2522 error_white_both(*arg, 1);
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2523 clear_tv(rettv);
21925
51d591dbb8df patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents: 21915
diff changeset
2524 evalarg_used->eval_flags = orig_flags;
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2525 return FAIL;
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2526 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2527 *arg = skipwhite_and_linebreak(*arg + 1, evalarg_used);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2528 evalarg_used->eval_flags = !result ? orig_flags
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2529 : orig_flags & ~EVAL_EVALUATE;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2530 if (eval1(arg, &var2, evalarg_used) == FAIL)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2531 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2532 if (evaluate && result)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2533 clear_tv(rettv);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2534 evalarg_used->eval_flags = orig_flags;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2535 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2536 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2537 if (evaluate && !result)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
2538 *rettv = var2;
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2539 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2540
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2541 if (evalarg == NULL)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2542 clear_evalarg(&local_evalarg, NULL);
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2543 else
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2544 evalarg->eval_flags = orig_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 * Handle first level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 * expr2 || expr2 || expr2 logical OR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 * "arg" must point to the first non-white of the expression.
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2555 * "arg" is advanced to just after the recognized expression.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2560 eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 {
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2562 char_u *p;
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2563 int getnext;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2568 if (eval3(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 /*
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2572 * Handle the "||" operator.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 */
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2574 p = eval_next_non_blank(*arg, evalarg, &getnext);
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2575 if (p[0] == '|' && p[1] == '|')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576 {
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2577 evalarg_T *evalarg_used = evalarg;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2578 evalarg_T local_evalarg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2579 int evaluate;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2580 int orig_flags;
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2581 long result = FALSE;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2582 typval_T var2;
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2583 int error = FALSE;
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2584 int vim9script = in_vim9script();
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2585
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2586 if (evalarg == NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2587 {
26053
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2588 init_evalarg(&local_evalarg);
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2589 evalarg_used = &local_evalarg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2590 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2591 orig_flags = evalarg_used->eval_flags;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2592 evaluate = orig_flags & EVAL_EVALUATE;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2593 if (evaluate)
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2594 {
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2595 if (vim9script)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2596 result = tv_get_bool_chk(rettv, &error);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2597 else if (tv_get_number_chk(rettv, &error) != 0)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2598 result = TRUE;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2599 clear_tv(rettv);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2600 if (error)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2601 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 /*
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2605 * Repeat until there is no following "||".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 */
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2607 while (p[0] == '|' && p[1] == '|')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 {
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2609 if (getnext)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2610 *arg = eval_next_line(evalarg_used);
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2611 else
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2612 {
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
2613 if (evaluate && vim9script && !VIM_ISWHITE(p[-1]))
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2614 {
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2615 error_white_both(p, 2);
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2616 clear_tv(rettv);
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2617 return FAIL;
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2618 }
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2619 *arg = p;
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2620 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2621
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2622 /*
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2623 * Get the second variable.
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2624 */
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
2625 if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[2]))
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2626 {
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2627 error_white_both(*arg, 2);
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2628 clear_tv(rettv);
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2629 return FAIL;
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2630 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2631 *arg = skipwhite_and_linebreak(*arg + 2, evalarg_used);
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2632 evalarg_used->eval_flags = !result ? orig_flags
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2633 : orig_flags & ~EVAL_EVALUATE;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2634 if (eval3(arg, &var2, evalarg_used) == FAIL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2635 return FAIL;
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2636
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2637 /*
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2638 * Compute the result.
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2639 */
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2640 if (evaluate && !result)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2641 {
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2642 if (vim9script)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2643 result = tv_get_bool_chk(&var2, &error);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2644 else if (tv_get_number_chk(&var2, &error) != 0)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2645 result = TRUE;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2646 clear_tv(&var2);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2647 if (error)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2648 return FAIL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2649 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2650 if (evaluate)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2651 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2652 if (vim9script)
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2653 {
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2654 rettv->v_type = VAR_BOOL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2655 rettv->vval.v_number = result ? VVAL_TRUE : VVAL_FALSE;
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2656 }
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2657 else
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2658 {
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2659 rettv->v_type = VAR_NUMBER;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2660 rettv->vval.v_number = result;
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2661 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2662 }
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2663
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2664 p = eval_next_non_blank(*arg, evalarg_used, &getnext);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2666
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2667 if (evalarg == NULL)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2668 clear_evalarg(&local_evalarg, NULL);
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2669 else
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2670 evalarg->eval_flags = orig_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2673 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2674 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 * Handle second level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 * expr3 && expr3 && expr3 logical AND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2680 * "arg" must point to the first non-white of the expression.
21644
7d3ba70a03f1 patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21642
diff changeset
2681 * "arg" is advanced to just after the recognized expression.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2682 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2683 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2684 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2686 eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2687 {
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2688 char_u *p;
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2689 int getnext;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2692 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2694 if (eval4(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2695 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2696
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 /*
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2698 * Handle the "&&" operator.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 */
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2700 p = eval_next_non_blank(*arg, evalarg, &getnext);
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2701 if (p[0] == '&' && p[1] == '&')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 {
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2703 evalarg_T *evalarg_used = evalarg;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2704 evalarg_T local_evalarg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2705 int orig_flags;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2706 int evaluate;
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2707 long result = TRUE;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2708 typval_T var2;
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2709 int error = FALSE;
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2710 int vim9script = in_vim9script();
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2711
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2712 if (evalarg == NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2713 {
26053
e861c5aaedd8 patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents: 25765
diff changeset
2714 init_evalarg(&local_evalarg);
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2715 evalarg_used = &local_evalarg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2716 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2717 orig_flags = evalarg_used->eval_flags;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2718 evaluate = orig_flags & EVAL_EVALUATE;
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2719 if (evaluate)
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2720 {
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2721 if (vim9script)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2722 result = tv_get_bool_chk(rettv, &error);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2723 else if (tv_get_number_chk(rettv, &error) == 0)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2724 result = FALSE;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2725 clear_tv(rettv);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2726 if (error)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2727 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 /*
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2731 * Repeat until there is no following "&&".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 */
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2733 while (p[0] == '&' && p[1] == '&')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 {
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2735 if (getnext)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2736 *arg = eval_next_line(evalarg_used);
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2737 else
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2738 {
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2739 if (evaluate && vim9script && !VIM_ISWHITE(p[-1]))
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2740 {
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2741 error_white_both(p, 2);
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2742 clear_tv(rettv);
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2743 return FAIL;
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2744 }
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
2745 *arg = p;
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2746 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2747
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2748 /*
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2749 * Get the second variable.
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2750 */
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
2751 if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[2]))
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2752 {
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2753 error_white_both(*arg, 2);
21642
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2754 clear_tv(rettv);
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2755 return FAIL;
5ae89c8633ae patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21636
diff changeset
2756 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2757 *arg = skipwhite_and_linebreak(*arg + 2, evalarg_used);
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2758 evalarg_used->eval_flags = result ? orig_flags
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2759 : orig_flags & ~EVAL_EVALUATE;
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2760 CLEAR_FIELD(var2);
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2761 if (eval4(arg, &var2, evalarg_used) == FAIL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2762 return FAIL;
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2763
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2764 /*
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2765 * Compute the result.
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2766 */
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2767 if (evaluate && result)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2768 {
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2769 if (vim9script)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2770 result = tv_get_bool_chk(&var2, &error);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2771 else if (tv_get_number_chk(&var2, &error) == 0)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2772 result = FALSE;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2773 clear_tv(&var2);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2774 if (error)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2775 return FAIL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2776 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2777 if (evaluate)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2778 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2779 if (vim9script)
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2780 {
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2781 rettv->v_type = VAR_BOOL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2782 rettv->vval.v_number = result ? VVAL_TRUE : VVAL_FALSE;
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2783 }
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2784 else
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2785 {
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2786 rettv->v_type = VAR_NUMBER;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
2787 rettv->vval.v_number = result;
21309
31a3f4d408b9 patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents: 21307
diff changeset
2788 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2789 }
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2790
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2791 p = eval_next_non_blank(*arg, evalarg_used, &getnext);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 }
21277
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2793
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2794 if (evalarg == NULL)
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2795 clear_evalarg(&local_evalarg, NULL);
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2796 else
1e5c29d4e5b3 patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents: 21251
diff changeset
2797 evalarg->eval_flags = orig_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 * Handle third level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 * var1 == var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 * var1 =~ var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 * var1 != var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 * var1 !~ var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 * var1 > var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 * var1 >= var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 * var1 < var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 * var1 <= var2
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2813 * var1 is var2
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2814 * var1 isnot var2
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 * "arg" must point to the first non-white of the expression.
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2817 * "arg" is advanced to just after the recognized expression.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2822 eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 char_u *p;
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2825 int getnext;
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23551
diff changeset
2826 exprtype_T type = EXPR_UNKNOWN;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 int len = 2;
21546
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2828 int type_is = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2833 if (eval5(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2836 p = eval_next_non_blank(*arg, evalarg, &getnext);
21546
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2837 type = get_compare_type(p, &len, &type_is);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 /*
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2840 * If there is a comparative operator, use it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 */
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2842 if (type != EXPR_UNKNOWN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 {
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
2844 typval_T var2;
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
2845 int ic;
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
2846 int vim9script = in_vim9script();
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2847 int evaluate = evalarg == NULL
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2848 ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
28031
4aa79224acd2 patch 8.2.4540: line number for error is off by one
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
2849 long comp_lnum = SOURCING_LNUM;
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
2850
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2851 if (getnext)
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2852 {
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2853 *arg = eval_next_line(evalarg);
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2854 p = *arg;
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2855 }
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2856 else if (evaluate && vim9script && !VIM_ISWHITE(**arg))
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2857 {
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
2858 error_white_both(*arg, len);
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2859 clear_tv(rettv);
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2860 return FAIL;
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2861 }
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2862
21546
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2863 if (vim9script && type_is && (p[len] == '?' || p[len] == '#'))
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2864 {
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
2865 semsg(_(e_invalid_expression_str), p);
21546
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2866 clear_tv(rettv);
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2867 return FAIL;
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2868 }
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
2869
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2870 // extra question mark appended: ignore case
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 if (p[len] == '?')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 ic = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2876 // extra '#' appended: match case
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 else if (p[len] == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 ic = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 }
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
2882 // nothing appended: use 'ignorecase' if not in Vim script
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 else
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
2884 ic = vim9script ? FALSE : p_ic;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 */
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2889 if (evaluate && vim9script && !IS_WHITE_OR_NUL(p[len]))
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2890 {
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
2891 error_white_both(p, len);
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2892 clear_tv(rettv);
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2893 return FAIL;
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2894 }
21046
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
2895 *arg = skipwhite_and_linebreak(p + len, evalarg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2896 if (eval5(arg, &var2, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2898 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900 }
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2901 if (evaluate)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2902 {
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2903 int ret;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2904
28031
4aa79224acd2 patch 8.2.4540: line number for error is off by one
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
2905 // use the line of the comparison for messages
4aa79224acd2 patch 8.2.4540: line number for error is off by one
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
2906 SOURCING_LNUM = comp_lnum;
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
2907 if (vim9script && check_compare_types(type, rettv, &var2) == FAIL)
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2908 {
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2909 ret = FAIL;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2910 clear_tv(rettv);
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2911 }
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2912 else
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
2913 ret = typval_compare(rettv, &var2, type, ic);
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2914 clear_tv(&var2);
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2915 return ret;
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2916 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921
22683
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
2922 /*
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
2923 * Make a copy of blob "tv1" and append blob "tv2".
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
2924 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2925 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2926 eval_addblob(typval_T *tv1, typval_T *tv2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2927 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2928 blob_T *b1 = tv1->vval.v_blob;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2929 blob_T *b2 = tv2->vval.v_blob;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2930 blob_T *b = blob_alloc();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2931 int i;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2932
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2933 if (b != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2934 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2935 for (i = 0; i < blob_len(b1); i++)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2936 ga_append(&b->bv_ga, blob_get(b1, i));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2937 for (i = 0; i < blob_len(b2); i++)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2938 ga_append(&b->bv_ga, blob_get(b2, i));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2939
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2940 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2941 rettv_blob_set(tv1, b);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2942 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2943 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2944
22683
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
2945 /*
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
2946 * Make a copy of list "tv1" and append list "tv2".
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
2947 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2948 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2949 eval_addlist(typval_T *tv1, typval_T *tv2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2950 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2951 typval_T var3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2952
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2953 // concatenate Lists
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2954 if (list_concat(tv1->vval.v_list, tv2->vval.v_list, &var3) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2955 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2956 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2957 clear_tv(tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2958 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2959 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2960 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2961 *tv1 = var3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2962 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2963 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2964
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 * Handle fourth level expression:
27583
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27517
diff changeset
2967 * + number addition, concatenation of list or blob
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 * - number subtraction
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2969 * . string concatenation (if script version is 1)
16219
bd49e1656c72 patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents: 16170
diff changeset
2970 * .. string concatenation
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 * "arg" must point to the first non-white of the expression.
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
2973 * "arg" is advanced to just after the recognized expression.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2978 eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2983 if (eval6(arg, rettv, evalarg, FALSE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 * Repeat computing, until no '+', '-' or '.' is following.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 {
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
2991 int evaluate;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2992 int getnext;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2993 char_u *p;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2994 int op;
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
2995 int oplen;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2996 int concat;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2997 typval_T var2;
21949
e6608764248a patch 8.2.1524: no longer get an error for string concatenation with float
Bram Moolenaar <Bram@vim.org>
parents: 21925
diff changeset
2998 int vim9script = in_vim9script();
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2999
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3000 // "." is only string concatenation when scriptversion is 1
24047
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
3001 // "+=", "-=" and "..=" are assignments
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
3002 // "++" and "--" on the next line are a separate command.
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3003 p = eval_next_non_blank(*arg, evalarg, &getnext);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3004 op = *p;
25622
15b54e0a576b patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 25620
diff changeset
3005 concat = op == '.' && (*(p + 1) == '.' || in_old_script(2));
24047
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
3006 if ((op != '+' && op != '-' && !concat) || p[1] == '='
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
3007 || (p[1] == '.' && p[2] == '='))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 break;
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
3009 if (getnext && (op == '+' || op == '-') && p[0] == p[1])
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24525
diff changeset
3010 break;
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3011
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3012 evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
21634
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3013 oplen = (concat && p[1] == '.') ? 2 : 1;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3014 if (getnext)
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
3015 *arg = eval_next_line(evalarg);
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
3016 else
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3017 {
21949
e6608764248a patch 8.2.1524: no longer get an error for string concatenation with float
Bram Moolenaar <Bram@vim.org>
parents: 21925
diff changeset
3018 if (evaluate && vim9script && !VIM_ISWHITE(**arg))
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3019 {
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
3020 error_white_both(*arg, oplen);
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3021 clear_tv(rettv);
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3022 return FAIL;
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3023 }
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
3024 *arg = p;
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3025 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3026 if ((op != '+' || (rettv->v_type != VAR_LIST
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3027 && rettv->v_type != VAR_BLOB))
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3028 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3029 && (op == '.' || rettv->v_type != VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3030 #endif
22683
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
3031 && evaluate)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3032 {
22683
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
3033 int error = FALSE;
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
3034
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3035 // For "list + ...", an illegal use of the first operand as
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3036 // a number cannot be determined before evaluating the 2nd
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3037 // operand: if this is also a list, all is ok.
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3038 // For "something . ...", "something - ..." or "non-list + ...",
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3039 // we know that the first operand needs to be a string or number
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3040 // without evaluating the 2nd operand. So check before to avoid
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3041 // side effects after an error.
22683
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
3042 if (op != '.')
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
3043 tv_get_number_chk(rettv, &error);
5cbcd3768125 patch 8.2.1890: Vim9: strange error for subtracting from a list
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
3044 if ((op == '.' && tv_get_string_chk(rettv) == NULL) || error)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3045 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3046 clear_tv(rettv);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3047 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3048 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3049 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3050
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 */
21949
e6608764248a patch 8.2.1524: no longer get an error for string concatenation with float
Bram Moolenaar <Bram@vim.org>
parents: 21925
diff changeset
3054 if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[oplen]))
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3055 {
24707
ad7cac75b2d1 patch 8.2.2892: error message contains random characters
Bram Moolenaar <Bram@vim.org>
parents: 24655
diff changeset
3056 error_white_both(*arg, oplen);
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3057 clear_tv(rettv);
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3058 return FAIL;
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3059 }
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
3060 *arg = skipwhite_and_linebreak(*arg + oplen, evalarg);
21949
e6608764248a patch 8.2.1524: no longer get an error for string concatenation with float
Bram Moolenaar <Bram@vim.org>
parents: 21925
diff changeset
3061 if (eval6(arg, &var2, evalarg, !vim9script && op == '.') == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3063 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3067 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 * Compute the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 if (op == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3074 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3075 char_u *s1 = tv_get_string_buf(rettv, buf1);
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3076 char_u *s2 = NULL;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3077
21949
e6608764248a patch 8.2.1524: no longer get an error for string concatenation with float
Bram Moolenaar <Bram@vim.org>
parents: 21925
diff changeset
3078 if (vim9script && (var2.v_type == VAR_VOID
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3079 || var2.v_type == VAR_CHANNEL
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3080 || var2.v_type == VAR_JOB))
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3081 semsg(_(e_using_invalid_value_as_string_str),
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3082 vartype_name(var2.v_type));
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3083 #ifdef FEAT_FLOAT
21949
e6608764248a patch 8.2.1524: no longer get an error for string concatenation with float
Bram Moolenaar <Bram@vim.org>
parents: 21925
diff changeset
3084 else if (vim9script && var2.v_type == VAR_FLOAT)
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3085 {
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3086 vim_snprintf((char *)buf2, NUMBUFLEN, "%g",
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3087 var2.vval.v_float);
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3088 s2 = buf2;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3089 }
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3090 #endif
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3091 else
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
3092 s2 = tv_get_string_buf_chk(&var2, buf2);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3093 if (s2 == NULL) // type error ?
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3094 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3095 clear_tv(rettv);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3096 clear_tv(&var2);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3097 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3098 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
3099 p = concat_str(s1, s2);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3100 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3101 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3102 rettv->vval.v_string = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3104 else if (op == '+' && rettv->v_type == VAR_BLOB
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3105 && var2.v_type == VAR_BLOB)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3106 eval_addblob(rettv, &var2);
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
3107 else if (op == '+' && rettv->v_type == VAR_LIST
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
3108 && var2.v_type == VAR_LIST)
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3109 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3110 if (eval_addlist(rettv, &var2) == FAIL)
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3111 return FAIL;
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3112 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3115 int error = FALSE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3116 varnumber_T n1, n2;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3117 #ifdef FEAT_FLOAT
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3118 float_T f1 = 0, f2 = 0;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3119
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3120 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3121 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3122 f1 = rettv->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3123 n1 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3124 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3125 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3126 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3127 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3128 n1 = tv_get_number_chk(rettv, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3129 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3130 {
24343
7735cbff607d patch 8.2.2712: memory leak when adding to a blob fails
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
3131 // This can only happen for "list + non-list" or
7735cbff607d patch 8.2.2712: memory leak when adding to a blob fails
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
3132 // "blob + non-blob". For "non-list + ..." or
7735cbff607d patch 8.2.2712: memory leak when adding to a blob fails
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
3133 // "something - ...", we returned before evaluating the
7735cbff607d patch 8.2.2712: memory leak when adding to a blob fails
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
3134 // 2nd operand.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3135 clear_tv(rettv);
24343
7735cbff607d patch 8.2.2712: memory leak when adding to a blob fails
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
3136 clear_tv(&var2);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3137 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3138 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3139 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3140 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3141 f1 = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3142 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3143 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3144 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3145 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3146 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3147 f2 = var2.vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3148 n2 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3149 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3150 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3151 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3152 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3153 n2 = tv_get_number_chk(&var2, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3154 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3155 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3156 clear_tv(rettv);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3157 clear_tv(&var2);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3158 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3159 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3160 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3161 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3162 f2 = n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3163 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3164 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3165 clear_tv(rettv);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3166
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3167 #ifdef FEAT_FLOAT
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3168 // If there is a float on either side the result is a float.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3169 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3170 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3171 if (op == '+')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3172 f1 = f1 + f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3173 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3174 f1 = f1 - f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3175 rettv->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3176 rettv->vval.v_float = f1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3177 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3178 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3179 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3180 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3181 if (op == '+')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3182 n1 = n1 + n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3183 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3184 n1 = n1 - n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3185 rettv->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3186 rettv->vval.v_number = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3187 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3188 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3189 clear_tv(&var2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 * Handle fifth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 * * number multiplication
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3198 * / number division
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 * % number modulo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201 * "arg" must point to the first non-white of the expression.
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
3202 * "arg" is advanced to just after the recognized expression.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3203 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3204 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3207 eval6(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3208 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3209 typval_T *rettv,
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3210 evalarg_T *evalarg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3211 int want_string) // after "." operator
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3212 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3213 #ifdef FEAT_FLOAT
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3214 int use_float = FALSE;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3215 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3217 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3218 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3219 */
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3220 if (eval7t(arg, rettv, evalarg, want_string) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3223 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3224 * Repeat computing, until no '*', '/' or '%' is following.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3225 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3226 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227 {
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3228 int evaluate;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3229 int getnext;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3230 typval_T var2;
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
3231 char_u *p;
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3232 int op;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3233 varnumber_T n1, n2;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3234 #ifdef FEAT_FLOAT
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3235 float_T f1, f2;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3236 #endif
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3237 int error;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3238
24047
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
3239 // "*=", "/=" and "%=" are assignments
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
3240 p = eval_next_non_blank(*arg, evalarg, &getnext);
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
3241 op = *p;
24047
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
3242 if ((op != '*' && op != '/' && op != '%') || p[1] == '=')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3243 break;
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3244
21634
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3245 evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3246 if (getnext)
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
3247 *arg = eval_next_line(evalarg);
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
3248 else
21634
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3249 {
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3250 if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3251 {
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24707
diff changeset
3252 error_white_both(*arg, 1);
21634
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3253 clear_tv(rettv);
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3254 return FAIL;
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3255 }
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
3256 *arg = p;
21634
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3257 }
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3258
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3259 #ifdef FEAT_FLOAT
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3260 f1 = 0;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3261 f2 = 0;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3262 #endif
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3263 error = FALSE;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3264 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3265 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3266 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3267 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3268 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3269 f1 = rettv->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3270 use_float = TRUE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3271 n1 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3272 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3273 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3274 #endif
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3275 n1 = tv_get_number_chk(rettv, &error);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3276 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3277 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3278 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3280 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 n1 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3285 */
21634
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3286 if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3287 {
24063
d8f3a993dc9a patch 8.2.2573: Vim9: using inalid pointer for error message
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
3288 error_white_both(*arg, 1);
21634
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3289 clear_tv(rettv);
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3290 return FAIL;
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3291 }
3a86e41fdffd patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
3292 *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3293 if (eval7t(arg, &var2, evalarg, FALSE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3294 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3296 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3298 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3299 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3300 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3301 if (!use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3302 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3303 f1 = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3304 use_float = TRUE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3305 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3306 f2 = var2.vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3307 n2 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3308 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3309 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3310 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3311 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3312 n2 = tv_get_number_chk(&var2, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3313 clear_tv(&var2);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3314 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3315 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3316 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3317 if (use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3318 f2 = n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3319 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3320 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3322 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3323 * Compute the result.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3324 * When either side is a float the result is a float.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3325 */
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3326 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3327 if (use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3328 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3329 if (op == '*')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3330 f1 = f1 * f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3331 else if (op == '/')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3332 {
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3333 # ifdef VMS
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3334 // VMS crashes on divide by zero, work around it
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3335 if (f2 == 0.0)
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3336 {
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3337 if (f1 == 0)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3338 f1 = -1 * __F_FLT_MAX - 1L; // similar to NaN
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3339 else if (f1 < 0)
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
3340 f1 = -1 * __F_FLT_MAX;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3341 else
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
3342 f1 = __F_FLT_MAX;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3343 }
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3344 else
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3345 f1 = f1 / f2;
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3346 # else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3347 // We rely on the floating point library to handle divide
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3348 // by zero to result in "inf" and not a crash.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3349 f1 = f1 / f2;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
3350 # endif
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3351 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3352 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3353 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3354 emsg(_(e_cannot_use_percent_with_float));
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3355 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3356 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3357 rettv->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3358 rettv->vval.v_float = f1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3359 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3360 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3361 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3362 {
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3363 int failed = FALSE;
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3364
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3365 if (op == '*')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3366 n1 = n1 * n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3367 else if (op == '/')
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3368 n1 = num_divide(n1, n2, &failed);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3369 else
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3370 n1 = num_modulus(n1, n2, &failed);
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3371 if (failed)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3372 return FAIL;
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
3373
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3374 rettv->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3375 rettv->vval.v_number = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3376 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3383 /*
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3384 * Handle a type cast before a base level expression.
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3385 * "arg" must point to the first non-white of the expression.
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3386 * "arg" is advanced to just after the recognized expression.
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3387 * Return OK or FAIL.
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3388 */
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3389 static int
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3390 eval7t(
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3391 char_u **arg,
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3392 typval_T *rettv,
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3393 evalarg_T *evalarg,
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3394 int want_string) // after "." operator
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3395 {
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3396 type_T *want_type = NULL;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3397 garray_T type_list; // list of pointers to allocated types
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3398 int res;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3399 int evaluate = evalarg == NULL ? 0
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3400 : (evalarg->eval_flags & EVAL_EVALUATE);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3401
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3402 // Recognize <type> in Vim9 script only.
25374
7124992f26ef patch 8.2.3224: cannot call script-local function after :vim9cmd
Bram Moolenaar <Bram@vim.org>
parents: 25358
diff changeset
3403 if (in_vim9script() && **arg == '<' && eval_isnamec1((*arg)[1])
7124992f26ef patch 8.2.3224: cannot call script-local function after :vim9cmd
Bram Moolenaar <Bram@vim.org>
parents: 25358
diff changeset
3404 && STRNCMP(*arg, "<SNR>", 5) != 0)
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3405 {
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3406 ++*arg;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3407 ga_init2(&type_list, sizeof(type_T *), 10);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3408 want_type = parse_type(arg, &type_list, TRUE);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3409 if (want_type == NULL && (evaluate || **arg != '>'))
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3410 {
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3411 clear_type_list(&type_list);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3412 return FAIL;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3413 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3414
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3415 if (**arg != '>')
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3416 {
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3417 if (*skipwhite(*arg) == '>')
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3418 semsg(_(e_no_white_space_allowed_before_str_str), ">", *arg);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3419 else
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3420 emsg(_(e_missing_gt));
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3421 clear_type_list(&type_list);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3422 return FAIL;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3423 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3424 ++*arg;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3425 *arg = skipwhite_and_linebreak(*arg, evalarg);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3426 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3427
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3428 res = eval7(arg, rettv, evalarg, want_string);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3429
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3430 if (want_type != NULL && evaluate)
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3431 {
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3432 if (res == OK)
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3433 {
26925
4e77f9961650 patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
3434 type_T *actual = typval2type(rettv, get_copyID(), &type_list,
4e77f9961650 patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
3435 TVTT_DO_MEMBER);
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3436
25425
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
3437 if (!equal_type(want_type, actual, 0))
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3438 {
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3439 if (want_type == &t_bool && actual != &t_bool
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3440 && (actual->tt_flags & TTFLAG_BOOL_OK))
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3441 {
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3442 int n = tv2bool(rettv);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3443
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3444 // can use "0" and "1" for boolean in some places
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3445 clear_tv(rettv);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3446 rettv->v_type = VAR_BOOL;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3447 rettv->vval.v_number = n ? VVAL_TRUE : VVAL_FALSE;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3448 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3449 else
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3450 {
25328
0aac8880d74d patch 8.2.3201: crash in test
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
3451 where_T where = WHERE_INIT;
0aac8880d74d patch 8.2.3201: crash in test
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
3452
24518
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3453 where.wt_variable = TRUE;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3454 res = check_type(want_type, actual, TRUE, where);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3455 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3456 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3457 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3458 clear_type_list(&type_list);
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3459 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3460
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3461 return res;
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3462 }
cf334a353c30 patch 8.2.2799: Vim9: type casts don't fully work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24486
diff changeset
3463
23525
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3464 int
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3465 eval_leader(char_u **arg, int vim9)
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3466 {
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3467 char_u *s = *arg;
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3468 char_u *p = *arg;
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3469
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3470 while (*p == '!' || *p == '-' || *p == '+')
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3471 {
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3472 char_u *n = skipwhite(p + 1);
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3473
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3474 // ++, --, -+ and +- are not accepted in Vim9 script
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3475 if (vim9 && (*p == '-' || *p == '+') && (*n == '-' || *n == '+'))
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3476 {
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
3477 semsg(_(e_invalid_expression_str), s);
23525
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3478 return FAIL;
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3479 }
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3480 p = n;
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3481 }
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3482 *arg = p;
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3483 return OK;
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3484 }
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3485
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 /*
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3487 * Check for a predefined value "true", "false" and "null.*".
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3488 * Return OK when recognized.
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3489 */
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3490 int
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3491 handle_predefined(char_u *s, int len, typval_T *rettv)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3492 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3493 switch (len)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3494 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3495 case 4: if (STRNCMP(s, "true", 4) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3496 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3497 rettv->v_type = VAR_BOOL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3498 rettv->vval.v_number = VVAL_TRUE;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3499 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3500 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3501 if (STRNCMP(s, "null", 4) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3502 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3503 rettv->v_type = VAR_SPECIAL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3504 rettv->vval.v_number = VVAL_NULL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3505 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3506 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3507 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3508 case 5: if (STRNCMP(s, "false", 5) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3509 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3510 rettv->v_type = VAR_BOOL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3511 rettv->vval.v_number = VVAL_FALSE;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3512 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3513 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3514 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3515 case 8: if (STRNCMP(s, "null_job", 8) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3516 {
28063
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3517 #ifdef FEAT_JOB_CHANNEL
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3518 rettv->v_type = VAR_JOB;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3519 rettv->vval.v_job = NULL;
28063
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3520 #else
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3521 rettv->v_type = VAR_SPECIAL;
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3522 rettv->vval.v_number = VVAL_NULL;
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3523 #endif
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3524 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3525 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3526 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3527 case 9:
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3528 if (STRNCMP(s, "null_", 5) != 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3529 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3530 if (STRNCMP(s + 5, "list", 4) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3531 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3532 rettv->v_type = VAR_LIST;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3533 rettv->vval.v_list = NULL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3534 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3535 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3536 if (STRNCMP(s + 5, "dict", 4) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3537 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3538 rettv->v_type = VAR_DICT;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3539 rettv->vval.v_dict = NULL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3540 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3541 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3542 if (STRNCMP(s + 5, "blob", 4) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3543 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3544 rettv->v_type = VAR_BLOB;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3545 rettv->vval.v_blob = NULL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3546 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3547 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3548 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3549 case 11: if (STRNCMP(s, "null_string", 11) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3550 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3551 rettv->v_type = VAR_STRING;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3552 rettv->vval.v_string = NULL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3553 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3554 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3555 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3556 case 12:
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3557 if (STRNCMP(s, "null_channel", 12) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3558 {
28063
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3559 #ifdef FEAT_JOB_CHANNEL
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3560 rettv->v_type = VAR_CHANNEL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3561 rettv->vval.v_channel = NULL;
28063
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3562 #else
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3563 rettv->v_type = VAR_SPECIAL;
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3564 rettv->vval.v_number = VVAL_NULL;
b47698ee4a14 patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 28031
diff changeset
3565 #endif
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3566 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3567 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3568 if (STRNCMP(s, "null_partial", 12) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3569 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3570 rettv->v_type = VAR_PARTIAL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3571 rettv->vval.v_partial = NULL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3572 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3573 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3574 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3575 case 13: if (STRNCMP(s, "null_function", 13) == 0)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3576 {
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3577 rettv->v_type = VAR_FUNC;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3578 rettv->vval.v_string = NULL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3579 return OK;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3580 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3581 break;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3582 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3583 return FAIL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3584 }
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3585
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3586 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587 * Handle sixth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 * number number constant
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3589 * 0zFFFFFFFF Blob constant
1228
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1109
diff changeset
3590 * "string" string constant
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1109
diff changeset
3591 * 'string' literal string constant
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 * &option-name option value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593 * @r register contents
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 * identifier variable value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 * function() function call
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 * $VAR environment variable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 * (expression) nested expression
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
3598 * [expr, expr] List
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3599 * {arg, arg -> expr} Lambda
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3600 * {key: val, key: val} Dictionary
17413
40417757dffd patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents: 17387
diff changeset
3601 * #{key: val, key: val} Dictionary with literal keys
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3602 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 * Also handle:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 * ! in front logical NOT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 * - in front unary minus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 * + in front unary plus (ignored)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3607 * trailing [] subscript in String or List
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3608 * trailing .name entry in Dictionary
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3609 * trailing ->name() method call
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3611 * "arg" must point to the first non-white of the expression.
21636
dcfcb6163f3d patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21634
diff changeset
3612 * "arg" is advanced to just after the recognized expression.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3617 eval7(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3618 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3619 typval_T *rettv,
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3620 evalarg_T *evalarg,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3621 int want_string) // after "." operator
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3623 int evaluate = evalarg != NULL
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3624 && (evalarg->eval_flags & EVAL_EVALUATE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626 char_u *s;
26990
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
3627 char_u *name_start = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 char_u *start_leader, *end_leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629 int ret = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630 char_u *alias;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3631 static int recurse = 0;
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3632 int vim9script = in_vim9script();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 /*
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3635 * Initialise variable so that clear_tv() can't mistake this for a
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3636 * string and free a string that isn't there.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3638 rettv->v_type = VAR_UNKNOWN;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 /*
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 10000
diff changeset
3641 * Skip '!', '-' and '+' characters. They are handled later.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 start_leader = *arg;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3644 if (eval_leader(arg, vim9script) == FAIL)
23525
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23499
diff changeset
3645 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 end_leader = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3648 if (**arg == '.' && (!isdigit(*(*arg + 1))
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3649 #ifdef FEAT_FLOAT
25622
15b54e0a576b patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 25620
diff changeset
3650 || in_old_script(2)
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3651 #endif
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3652 ))
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3653 {
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
3654 semsg(_(e_invalid_expression_str), *arg);
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3655 ++*arg;
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3656 return FAIL;
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3657 }
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
3658
27356
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3659 // Limit recursion to 1000 levels. At least at 10000 we run out of stack
27358
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3660 // and crash. With MSVC the stack is smaller.
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3661 if (recurse ==
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3662 #ifdef _MSC_VER
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3663 300
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3664 #else
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3665 1000
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3666 #endif
609a8ff1a5d2 patch 8.2.4207: recursion test fails with MSVC
Bram Moolenaar <Bram@vim.org>
parents: 27356
diff changeset
3667 )
27356
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3668 {
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3669 semsg(_(e_expression_too_recursive_str), *arg);
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3670 return FAIL;
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3671 }
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3672 ++recurse;
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3673
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3674 switch (**arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3675 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3676 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3677 * Number constant.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3678 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3679 case '0':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3680 case '1':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3681 case '2':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3682 case '3':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3683 case '4':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3684 case '5':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3685 case '6':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3686 case '7':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 case '8':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3688 case '9':
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3689 case '.': ret = eval_number(arg, rettv, evaluate, want_string);
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3690
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3691 // Apply prefixed "-" and "+" now. Matters especially when
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3692 // "->" follows.
21733
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
3693 if (ret == OK && evaluate && end_leader > start_leader
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
3694 && rettv->v_type != VAR_BLOB)
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3695 ret = eval7_leader(rettv, TRUE, start_leader, &end_leader);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3696 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 * String constant: "string".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3701 case '"': ret = eval_string(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3702 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 /*
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3705 * Literal string constant: 'str''ing'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3706 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3707 case '\'': ret = eval_lit_string(arg, rettv, evaluate);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3708 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3709
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3710 /*
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3711 * List: [expr, expr]
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3712 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3713 case '[': ret = eval_list(arg, rettv, evalarg, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3714 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3716 /*
17413
40417757dffd patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents: 17387
diff changeset
3717 * Dictionary: #{key: val, key: val}
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3718 */
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3719 case '#': if (vim9script)
24174
99bfaa4693db patch 8.2.2628: Vim9: #{ can still be used at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
3720 {
99bfaa4693db patch 8.2.2628: Vim9: #{ can still be used at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
3721 ret = vim9_bad_comment(*arg) ? FAIL : NOTDONE;
99bfaa4693db patch 8.2.2628: Vim9: #{ can still be used at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
3722 }
99bfaa4693db patch 8.2.2628: Vim9: #{ can still be used at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
3723 else if ((*arg)[1] == '{')
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3724 {
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3725 ++*arg;
21034
2f8b0812819f patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents: 21032
diff changeset
3726 ret = eval_dict(arg, rettv, evalarg, TRUE);
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3727 }
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3728 else
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3729 ret = NOTDONE;
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3730 break;
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3731
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3732 /*
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9525
diff changeset
3733 * Lambda: {arg, arg -> expr}
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
3734 * Dictionary: {'key': val, 'key': val}
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3735 */
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3736 case '{': if (vim9script)
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
3737 ret = NOTDONE;
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
3738 else
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3739 ret = get_lambda_tv(arg, rettv, vim9script, evalarg);
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9525
diff changeset
3740 if (ret == NOTDONE)
21034
2f8b0812819f patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents: 21032
diff changeset
3741 ret = eval_dict(arg, rettv, evalarg, FALSE);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3742 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3743
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3744 /*
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
3745 * Option value: &name
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3747 case '&': ret = eval_option(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751 * Environment variable: $VAR.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3752 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3753 case '$': ret = eval_env_var(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3754 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3756 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757 * Register contents: @r.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3758 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3759 case '@': ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3760 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3761 {
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3762 if (vim9script && IS_WHITE_OR_NUL(**arg))
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3763 semsg(_(e_syntax_error_at_str), *arg);
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3764 else if (vim9script && !valid_yank_reg(**arg, FALSE))
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3765 emsg_invreg(**arg);
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3766 else
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3767 {
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3768 rettv->v_type = VAR_STRING;
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3769 rettv->vval.v_string = get_reg_contents(**arg,
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3770 GREG_EXPR_SRC);
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
3771 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773 if (**arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3774 ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3775 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3776
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3777 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3778 * nested expression: (expression).
24655
3876d9629ebd patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents: 24632
diff changeset
3779 * or lambda: (arg) => expr
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3780 */
23338
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
3781 case '(': ret = NOTDONE;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3782 if (vim9script)
23970
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
3783 {
23338
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
3784 ret = get_lambda_tv(arg, rettv, TRUE, evalarg);
23970
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
3785 if (ret == OK && evaluate)
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
3786 {
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
3787 ufunc_T *ufunc = rettv->vval.v_partial->pt_func;
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
3788
24890
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24880
diff changeset
3789 // Compile it here to get the return type. The return
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24880
diff changeset
3790 // type is optional, when it's missing use t_unknown.
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24880
diff changeset
3791 // This is recognized in compile_return().
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24880
diff changeset
3792 if (ufunc->uf_ret_type->tt_type == VAR_VOID)
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24880
diff changeset
3793 ufunc->uf_ret_type = &t_unknown;
28101
3bc0a639dfb0 patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents: 28063
diff changeset
3794 if (compile_def_function(ufunc, FALSE,
3bc0a639dfb0 patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents: 28063
diff changeset
3795 get_compile_type(ufunc), NULL) == FAIL)
23972
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
3796 {
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
3797 clear_tv(rettv);
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
3798 ret = FAIL;
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
3799 }
23970
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
3800 }
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
3801 }
23338
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
3802 if (ret == NOTDONE)
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
3803 {
21046
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
3804 *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3805 ret = eval1(arg, rettv, evalarg); // recursive!
21044
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
3806
21046
0ca7e04d39e3 patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents: 21044
diff changeset
3807 *arg = skipwhite_and_linebreak(*arg, evalarg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3808 if (**arg == ')')
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3809 ++*arg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3810 else if (ret == OK)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3811 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26572
diff changeset
3812 emsg(_(e_missing_closing_paren));
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3813 clear_tv(rettv);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3814 ret = FAIL;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
3815 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3817 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3818
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3819 default: ret = NOTDONE;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3820 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3821 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3822
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3823 if (ret == NOTDONE)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3824 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3825 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3826 * Must be a variable or function name.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3827 * Can also be a curly-braces kind of name: {expr}.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3828 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3829 s = *arg;
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3830 len = get_name_len(arg, &alias, evaluate, TRUE);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3831 if (alias != NULL)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3832 s = alias;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3833
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3834 if (len <= 0)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3835 ret = FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3836 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3837 {
21305
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3838 int flags = evalarg == NULL ? 0 : evalarg->eval_flags;
91d4af3309e7 patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents: 21279
diff changeset
3839
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3840 if (evaluate && vim9script && len == 1 && *s == '_')
24408
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
3841 {
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
3842 emsg(_(e_cannot_use_underscore_here));
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
3843 ret = FAIL;
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
3844 }
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3845 else if (evaluate && vim9script && len > 2
27669
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
3846 && s[0] == 's' && s[1] == ':')
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
3847 {
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
3848 semsg(_(e_cannot_use_s_colon_in_vim9_script_str), s);
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
3849 ret = FAIL;
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27645
diff changeset
3850 }
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3851 else if ((vim9script ? **arg : *skipwhite(*arg)) == '(')
21656
c3f6006bf0ba patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents: 21644
diff changeset
3852 {
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3853 // "name(..." recursive!
21656
c3f6006bf0ba patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents: 21644
diff changeset
3854 *arg = skipwhite(*arg);
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
3855 ret = eval_func(arg, evalarg, s, len, rettv, flags, NULL);
21656
c3f6006bf0ba patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents: 21644
diff changeset
3856 }
20401
918b9a05cf35 patch 8.2.0755: Vim9: No error when variable initializer is not a constant
Bram Moolenaar <Bram@vim.org>
parents: 20397
diff changeset
3857 else if (flags & EVAL_CONSTANT)
918b9a05cf35 patch 8.2.0755: Vim9: No error when variable initializer is not a constant
Bram Moolenaar <Bram@vim.org>
parents: 20397
diff changeset
3858 ret = FAIL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3859 else if (evaluate)
21307
b991565745fb patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21305
diff changeset
3860 {
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3861 // get the value of "true", "false", etc. or a variable
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3862 ret = FAIL;
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3863 if (vim9script)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3864 ret = handle_predefined(s, len, rettv);
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27698
diff changeset
3865 if (ret == FAIL)
26990
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
3866 {
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
3867 name_start = s;
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
3868 ret = eval_variable(s, len, 0, rettv, NULL,
24112
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
3869 EVAL_VAR_VERBOSE + EVAL_VAR_IMPORT);
26990
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
3870 }
21307
b991565745fb patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21305
diff changeset
3871 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
3872 else
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
3873 {
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21118
diff changeset
3874 // skip the name
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
3875 check_vars(s, len);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
3876 ret = OK;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
3877 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3878 }
2690
3ea3dcbf2cd6 updated for version 7.3.108
Bram Moolenaar <bram@vim.org>
parents: 2687
diff changeset
3879 vim_free(alias);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3880 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3881
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3882 // Handle following '[', '(' and '.' for expr[expr], expr.name,
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3883 // expr(expr), expr->name(expr)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3884 if (ret == OK)
26990
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
3885 ret = handle_subscript(arg, name_start, rettv, evalarg, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 * Apply logical NOT and unary '-', from right to left, ignore '+'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 if (ret == OK && evaluate && end_leader > start_leader)
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3891 ret = eval7_leader(rettv, FALSE, start_leader, &end_leader);
27356
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3892
84682ad16c31 patch 8.2.4206: condition with many "(" causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 27301
diff changeset
3893 --recurse;
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3894 return ret;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3895 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3896
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3897 /*
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3898 * Apply the leading "!" and "-" before an eval7 expression to "rettv".
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3899 * When "numeric_only" is TRUE only handle "+" and "-".
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3900 * Adjusts "end_leaderp" until it is at "start_leader".
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3901 */
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3902 static int
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3903 eval7_leader(
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3904 typval_T *rettv,
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3905 int numeric_only,
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3906 char_u *start_leader,
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3907 char_u **end_leaderp)
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3908 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3909 char_u *end_leader = *end_leaderp;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3910 int ret = OK;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3911 int error = FALSE;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3912 varnumber_T val = 0;
21725
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3913 vartype_T type = rettv->v_type;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3914 int vim9script = in_vim9script();
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3915 #ifdef FEAT_FLOAT
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3916 float_T f = 0.0;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3917
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3918 if (rettv->v_type == VAR_FLOAT)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3919 f = rettv->vval.v_float;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3920 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3921 #endif
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22580
diff changeset
3922 {
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22580
diff changeset
3923 while (VIM_ISWHITE(end_leader[-1]))
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22580
diff changeset
3924 --end_leader;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3925 if (vim9script && end_leader[-1] == '!')
21733
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
3926 val = tv2bool(rettv);
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
3927 else
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 21725
diff changeset
3928 val = tv_get_number_chk(rettv, &error);
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22580
diff changeset
3929 }
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3930 if (error)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3931 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3932 clear_tv(rettv);
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3933 ret = FAIL;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3934 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3935 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3936 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3937 while (end_leader > start_leader)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3938 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3939 --end_leader;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3940 if (*end_leader == '!')
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3941 {
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3942 if (numeric_only)
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3943 {
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3944 ++end_leader;
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3945 break;
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3946 }
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3947 #ifdef FEAT_FLOAT
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3948 if (rettv->v_type == VAR_FLOAT)
22866
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3949 {
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3950 if (vim9script)
22866
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3951 {
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3952 rettv->v_type = VAR_BOOL;
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3953 val = f == 0.0 ? VVAL_TRUE : VVAL_FALSE;
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3954 }
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3955 else
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3956 f = !f;
52e64d340a98 patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
3957 }
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3958 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3959 #endif
21725
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3960 {
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3961 val = !val;
21725
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3962 type = VAR_BOOL;
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3963 }
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3964 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3965 else if (*end_leader == '-')
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3966 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3967 #ifdef FEAT_FLOAT
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3968 if (rettv->v_type == VAR_FLOAT)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3969 f = -f;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3970 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3971 #endif
21725
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3972 {
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3973 val = -val;
21725
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3974 type = VAR_NUMBER;
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3975 }
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3976 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3977 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3978 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3979 if (rettv->v_type == VAR_FLOAT)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3980 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3981 clear_tv(rettv);
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3982 rettv->vval.v_float = f;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3983 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3984 else
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3985 #endif
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3986 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3987 clear_tv(rettv);
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
3988 if (vim9script)
21725
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3989 rettv->v_type = type;
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3990 else
741c1d58d50f patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3991 rettv->v_type = VAR_NUMBER;
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3992 rettv->vval.v_number = val;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3993 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3994 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3995 *end_leaderp = end_leader;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 /*
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4000 * Call the function referred to in "rettv".
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4001 */
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4002 static int
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4003 call_func_rettv(
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4004 char_u **arg,
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
4005 evalarg_T *evalarg,
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4006 typval_T *rettv,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4007 int evaluate,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4008 dict_T *selfdict,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4009 typval_T *basetv)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4010 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4011 partial_T *pt = NULL;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4012 funcexe_T funcexe;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4013 typval_T functv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4014 char_u *s;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4015 int ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4016
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4017 // need to copy the funcref so that we can clear rettv
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4018 if (evaluate)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4019 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4020 functv = *rettv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4021 rettv->v_type = VAR_UNKNOWN;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4022
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4023 // Invoke the function. Recursive!
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4024 if (functv.v_type == VAR_PARTIAL)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4025 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4026 pt = functv.vval.v_partial;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4027 s = partial_name(pt);
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4028 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4029 else
24878
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4030 {
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4031 s = functv.vval.v_string;
24878
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4032 if (s == NULL || *s == NUL)
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4033 {
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4034 emsg(_(e_empty_function_name));
24880
d254f5c78b5a patch 8.2.2978: warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 24878
diff changeset
4035 ret = FAIL;
24878
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4036 goto theend;
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4037 }
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4038 }
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4039 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4040 else
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4041 s = (char_u *)"";
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4042
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
4043 CLEAR_FIELD(funcexe);
26534
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
4044 funcexe.fe_firstline = curwin->w_cursor.lnum;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
4045 funcexe.fe_lastline = curwin->w_cursor.lnum;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
4046 funcexe.fe_evaluate = evaluate;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
4047 funcexe.fe_partial = pt;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
4048 funcexe.fe_selfdict = selfdict;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
4049 funcexe.fe_basetv = basetv;
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
4050 ret = get_func_tv(s, -1, rettv, arg, evalarg, &funcexe);
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4051
24878
f67773e26cfa patch 8.2.2977: crash when using a null function reference
Bram Moolenaar <Bram@vim.org>
parents: 24860
diff changeset
4052 theend:
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4053 // Clear the funcref afterwards, so that deleting it while
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4054 // evaluating the arguments is possible (see test55).
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4055 if (evaluate)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4056 clear_tv(&functv);
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4057
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4058 return ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4059 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4060
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4061 /*
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4062 * Evaluate "->method()".
23709
a0c4d04a58c4 patch 8.2.2396: Vim9: no white space allowed before "->"
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
4063 * "*arg" points to "method".
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4064 * Returns FAIL or OK. "*arg" is advanced to after the ')'.
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4065 */
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4066 static int
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4067 eval_lambda(
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4068 char_u **arg,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4069 typval_T *rettv,
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4070 evalarg_T *evalarg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4071 int verbose) // give error messages
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4072 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4073 int evaluate = evalarg != NULL
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4074 && (evalarg->eval_flags & EVAL_EVALUATE);
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4075 typval_T base = *rettv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4076 int ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4077
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4078 rettv->v_type = VAR_UNKNOWN;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4079
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4080 if (**arg == '{')
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4081 {
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4082 // ->{lambda}()
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4083 ret = get_lambda_tv(arg, rettv, FALSE, evalarg);
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4084 }
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4085 else
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4086 {
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4087 // ->(lambda)()
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4088 ++*arg;
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4089 ret = eval1(arg, rettv, evalarg);
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4090 *arg = skipwhite_and_linebreak(*arg, evalarg);
26636
6047c7ea7963 patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents: 26614
diff changeset
4091 if (**arg == ')')
6047c7ea7963 patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents: 26614
diff changeset
4092 {
6047c7ea7963 patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents: 26614
diff changeset
4093 ++*arg;
6047c7ea7963 patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents: 26614
diff changeset
4094 }
6047c7ea7963 patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents: 26614
diff changeset
4095 else
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4096 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26572
diff changeset
4097 emsg(_(e_missing_closing_paren));
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4098 ret = FAIL;
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4099 }
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
4100 }
18851
3cf9529b3a4a patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents: 18777
diff changeset
4101 if (ret != OK)
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4102 return FAIL;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4103 else if (**arg != '(')
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4104 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4105 if (verbose)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4106 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4107 if (*skipwhite(*arg) == '(')
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
4108 emsg(_(e_no_white_space_allowed_before_parenthesis));
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4109 else
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26572
diff changeset
4110 semsg(_(e_missing_parenthesis_str), "lambda");
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4111 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4112 clear_tv(rettv);
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4113 ret = FAIL;
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4114 }
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4115 else
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
4116 ret = call_func_rettv(arg, evalarg, rettv, evaluate, NULL, &base);
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4117
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4118 // Clear the funcref afterwards, so that deleting it while
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4119 // evaluating the arguments is possible (see test55).
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4120 if (evaluate)
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4121 clear_tv(&base);
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4122
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
4123 return ret;
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4124 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4125
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4126 /*
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4127 * Evaluate "->method()".
23709
a0c4d04a58c4 patch 8.2.2396: Vim9: no white space allowed before "->"
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
4128 * "*arg" points to "method".
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4129 * Returns FAIL or OK. "*arg" is advanced to after the ')'.
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4130 */
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4131 static int
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4132 eval_method(
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4133 char_u **arg,
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4134 typval_T *rettv,
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
4135 evalarg_T *evalarg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4136 int verbose) // give error messages
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4137 {
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4138 char_u *name;
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4139 long len;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4140 char_u *alias;
27173
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4141 char_u *tofree = NULL;
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4142 typval_T base = *rettv;
27146
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4143 int ret = OK;
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
4144 int evaluate = evalarg != NULL
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
4145 && (evalarg->eval_flags & EVAL_EVALUATE);
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4146
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4147 rettv->v_type = VAR_UNKNOWN;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4148
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4149 name = *arg;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4150 len = get_name_len(arg, &alias, evaluate, TRUE);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4151 if (alias != NULL)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4152 name = alias;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4153
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4154 if (len <= 0)
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4155 {
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4156 if (verbose)
26897
d02d40f0261c patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
4157 emsg(_(e_missing_name_after_method));
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4158 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4159 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4160 else
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4161 {
27173
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4162 char_u *paren;
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4163
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4164 // If there is no "(" immediately following, but there is further on,
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4165 // it can be "import.Func()", "dict.Func()", "list[nr]", etc.
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4166 // Does not handle anything where "(" is part of the expression.
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4167 *arg = skipwhite(*arg);
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4168
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4169 if (**arg != '(' && alias == NULL
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4170 && (paren = vim_strchr(*arg, '(')) != NULL)
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4171 {
27199
d4f254d02d7c patch 8.2.4128: crash when method cannot be found
Bram Moolenaar <Bram@vim.org>
parents: 27193
diff changeset
4172 char_u *deref;
d4f254d02d7c patch 8.2.4128: crash when method cannot be found
Bram Moolenaar <Bram@vim.org>
parents: 27193
diff changeset
4173
27173
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4174 *arg = name;
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4175 *paren = NUL;
27199
d4f254d02d7c patch 8.2.4128: crash when method cannot be found
Bram Moolenaar <Bram@vim.org>
parents: 27193
diff changeset
4176 deref = deref_function_name(arg, &tofree, evalarg, verbose);
d4f254d02d7c patch 8.2.4128: crash when method cannot be found
Bram Moolenaar <Bram@vim.org>
parents: 27193
diff changeset
4177 if (deref == NULL)
27173
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4178 {
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4179 *arg = name + len;
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4180 ret = FAIL;
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4181 }
27189
a10936038ec9 patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents: 27177
diff changeset
4182 else
27199
d4f254d02d7c patch 8.2.4128: crash when method cannot be found
Bram Moolenaar <Bram@vim.org>
parents: 27193
diff changeset
4183 {
d4f254d02d7c patch 8.2.4128: crash when method cannot be found
Bram Moolenaar <Bram@vim.org>
parents: 27193
diff changeset
4184 name = deref;
27390
018c911eb9cf patch 8.2.4223: long/int compiler warnings; function arguments swapped
Bram Moolenaar <Bram@vim.org>
parents: 27358
diff changeset
4185 len = (long)STRLEN(name);
27199
d4f254d02d7c patch 8.2.4128: crash when method cannot be found
Bram Moolenaar <Bram@vim.org>
parents: 27193
diff changeset
4186 }
27173
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4187 *paren = '(';
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4188 }
27146
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4189
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4190 if (ret == OK)
17661
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
4191 {
27146
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4192 *arg = skipwhite(*arg);
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4193
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4194 if (**arg != '(')
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4195 {
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4196 if (verbose)
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4197 semsg(_(e_missing_parenthesis_str), name);
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4198 ret = FAIL;
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4199 }
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4200 else if (VIM_ISWHITE((*arg)[-1]))
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4201 {
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4202 if (verbose)
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4203 emsg(_(e_no_white_space_allowed_before_parenthesis));
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4204 ret = FAIL;
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4205 }
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4206 else
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4207 ret = eval_func(arg, evalarg, name, len, rettv,
648a5f658990 patch 8.2.4102: Vim9: import cannot be used after method
Bram Moolenaar <Bram@vim.org>
parents: 27080
diff changeset
4208 evaluate ? EVAL_EVALUATE : 0, &base);
17661
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
4209 }
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
4210 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4211
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4212 // Clear the funcref afterwards, so that deleting it while
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4213 // evaluating the arguments is possible (see test55).
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4214 if (evaluate)
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4215 clear_tv(&base);
27173
04af0c68dba8 patch 8.2.4115: cannot use a method with a complex expression
Bram Moolenaar <Bram@vim.org>
parents: 27163
diff changeset
4216 vim_free(tofree);
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4217
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4218 return ret;
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4219 }
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4220
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4221 /*
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
4222 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
4223 * "*arg" points to the '[' or '.'.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4224 * Returns FAIL or OK. "*arg" is advanced to after the ']'.
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4225 */
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4226 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4227 eval_index(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4228 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4229 typval_T *rettv,
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4230 evalarg_T *evalarg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4231 int verbose) // give error messages
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4232 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4233 int evaluate = evalarg != NULL
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4234 && (evalarg->eval_flags & EVAL_EVALUATE);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4235 int empty1 = FALSE, empty2 = FALSE;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4236 typval_T var1, var2;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4237 int range = FALSE;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4238 char_u *key = NULL;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4239 int keylen = -1;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
4240 int vim9script = in_vim9script();
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4241
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4242 if (check_can_index(rettv, evaluate, verbose) == FAIL)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4243 return FAIL;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4244
7046
fd409a0800fd commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents: 7042
diff changeset
4245 init_tv(&var1);
fd409a0800fd commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents: 7042
diff changeset
4246 init_tv(&var2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4247 if (**arg == '.')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4248 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4249 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4250 * dict.name
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4251 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4252 key = *arg + 1;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4253 for (keylen = 0; eval_isdictc(key[keylen]); ++keylen)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4254 ;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4255 if (keylen == 0)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4256 return FAIL;
22244
9f6b8fdea159 patch 8.2.1671: Vim9: stray error for missing white space
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
4257 *arg = key + keylen;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4258 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4259 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4260 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4261 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4262 * something[idx]
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4263 *
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4264 * Get the (first) variable from inside the [].
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4265 */
21142
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
4266 *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4267 if (**arg == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4268 empty1 = TRUE;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4269 else if (eval1(arg, &var1, evalarg) == FAIL) // recursive!
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4270 return FAIL;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
4271 else if (vim9script && **arg == ':')
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4272 {
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
4273 semsg(_(e_white_space_required_before_and_after_str_at_str),
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
4274 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4275 clear_tv(&var1);
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4276 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4277 }
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4278 else if (evaluate)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4279 {
26646
6f8d3470fa90 patch 8.2.3852: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26642
diff changeset
4280 int error = FALSE;
6f8d3470fa90 patch 8.2.3852: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26642
diff changeset
4281
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4282 #ifdef FEAT_FLOAT
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4283 // allow for indexing with float
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
4284 if (vim9script && rettv->v_type == VAR_DICT
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4285 && var1.v_type == VAR_FLOAT)
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4286 {
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4287 var1.vval.v_string = typval_tostring(&var1, TRUE);
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4288 var1.v_type = VAR_STRING;
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4289 }
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4290 #endif
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
4291 if (vim9script && rettv->v_type == VAR_LIST)
26646
6f8d3470fa90 patch 8.2.3852: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26642
diff changeset
4292 tv_get_number_chk(&var1, &error);
6f8d3470fa90 patch 8.2.3852: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26642
diff changeset
4293 else
6f8d3470fa90 patch 8.2.3852: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26642
diff changeset
4294 error = tv_get_string_chk(&var1) == NULL;
6f8d3470fa90 patch 8.2.3852: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26642
diff changeset
4295 if (error)
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4296 {
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4297 // not a number or string
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4298 clear_tv(&var1);
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4299 return FAIL;
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23709
diff changeset
4300 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4301 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4302
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4303 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4304 * Get the second variable from inside the [:].
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4305 */
21142
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
4306 *arg = skipwhite_and_linebreak(*arg, evalarg);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4307 if (**arg == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4308 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4309 range = TRUE;
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4310 ++*arg;
27682
f60d0d823897 patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
4311 if (vim9script && !IS_WHITE_OR_NUL(**arg) && **arg != ']')
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4312 {
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
4313 semsg(_(e_white_space_required_before_and_after_str_at_str),
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
4314 ":", *arg - 1);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4315 if (!empty1)
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4316 clear_tv(&var1);
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4317 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4318 }
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
4319 *arg = skipwhite_and_linebreak(*arg, evalarg);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4320 if (**arg == ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4321 empty2 = TRUE;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4322 else if (eval1(arg, &var2, evalarg) == FAIL) // recursive!
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4323 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4324 if (!empty1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4325 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4326 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4327 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
4328 else if (evaluate && tv_get_string_chk(&var2) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4329 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4330 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4331 if (!empty1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4332 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4333 clear_tv(&var2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4334 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4335 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4336 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4337
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4338 // Check for the ']'.
21142
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
4339 *arg = skipwhite_and_linebreak(*arg, evalarg);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4340 if (**arg != ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4341 {
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4342 if (verbose)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26572
diff changeset
4343 emsg(_(e_missing_closing_square_brace));
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4344 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4345 if (range)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4346 clear_tv(&var2);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4347 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4348 }
21837
2b941fbab4d9 patch 8.2.1468: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
4349 *arg = *arg + 1; // skip over the ']'
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4350 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4351
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4352 if (evaluate)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4353 {
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4354 int res = eval_index_inner(rettv, range,
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4355 empty1 ? NULL : &var1, empty2 ? NULL : &var2, FALSE,
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4356 key, keylen, verbose);
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4357
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4358 if (!empty1)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4359 clear_tv(&var1);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4360 if (range)
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4361 clear_tv(&var2);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4362 return res;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4363 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4364 return OK;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4365 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4366
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4367 /*
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4368 * Check if "rettv" can have an [index] or [sli:ce]
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4369 */
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4370 int
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4371 check_can_index(typval_T *rettv, int evaluate, int verbose)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4372 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4373 switch (rettv->v_type)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4374 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4375 case VAR_FUNC:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4376 case VAR_PARTIAL:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4377 if (verbose)
26646
6f8d3470fa90 patch 8.2.3852: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26642
diff changeset
4378 emsg(_(e_cannot_index_a_funcref));
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4379 return FAIL;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4380 case VAR_FLOAT:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4381 #ifdef FEAT_FLOAT
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4382 if (verbose)
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
4383 emsg(_(e_using_float_as_string));
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4384 return FAIL;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4385 #endif
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4386 case VAR_BOOL:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4387 case VAR_SPECIAL:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4388 case VAR_JOB:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4389 case VAR_CHANNEL:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
4390 case VAR_INSTR:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4391 if (verbose)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4392 emsg(_(e_cannot_index_special_variable));
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4393 return FAIL;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4394 case VAR_UNKNOWN:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4395 case VAR_ANY:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4396 case VAR_VOID:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4397 if (evaluate)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4398 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4399 emsg(_(e_cannot_index_special_variable));
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4400 return FAIL;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4401 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4402 // FALLTHROUGH
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4403
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4404 case VAR_STRING:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4405 case VAR_LIST:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4406 case VAR_DICT:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4407 case VAR_BLOB:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4408 break;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4409 case VAR_NUMBER:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4410 if (in_vim9script())
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4411 emsg(_(e_cannot_index_number));
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4412 break;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4413 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4414 return OK;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4415 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4416
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4417 /*
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4418 * slice() function
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4419 */
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4420 void
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4421 f_slice(typval_T *argvars, typval_T *rettv)
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4422 {
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25284
diff changeset
4423 if (in_vim9script()
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25374
diff changeset
4424 && ((argvars[0].v_type != VAR_STRING
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25374
diff changeset
4425 && argvars[0].v_type != VAR_LIST
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25284
diff changeset
4426 && argvars[0].v_type != VAR_BLOB
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25284
diff changeset
4427 && check_for_list_arg(argvars, 0) == FAIL)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25284
diff changeset
4428 || check_for_number_arg(argvars, 1) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25284
diff changeset
4429 || check_for_opt_number_arg(argvars, 2) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25284
diff changeset
4430 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25284
diff changeset
4431
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4432 if (check_can_index(argvars, TRUE, FALSE) == OK)
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4433 {
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4434 copy_tv(argvars, rettv);
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4435 eval_index_inner(rettv, TRUE, argvars + 1,
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4436 argvars[2].v_type == VAR_UNKNOWN ? NULL : argvars + 2,
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4437 TRUE, NULL, 0, FALSE);
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4438 }
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4439 }
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4440
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4441 /*
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4442 * Apply index or range to "rettv".
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4443 * "var1" is the first index, NULL for [:expr].
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4444 * "var2" is the second index, NULL for [expr] and [expr: ]
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4445 * "exclusive" is TRUE for slice(): second index is exclusive, use character
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4446 * index for string.
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4447 * Alternatively, "key" is not NULL, then key[keylen] is the dict index.
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4448 */
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4449 int
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4450 eval_index_inner(
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4451 typval_T *rettv,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4452 int is_range,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4453 typval_T *var1,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4454 typval_T *var2,
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4455 int exclusive,
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4456 char_u *key,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4457 int keylen,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4458 int verbose)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4459 {
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4460 varnumber_T n1, n2 = 0;
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4461 long len;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4462
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4463 n1 = 0;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4464 if (var1 != NULL && rettv->v_type != VAR_DICT)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4465 n1 = tv_get_number(var1);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4466
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4467 if (is_range)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4468 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4469 if (rettv->v_type == VAR_DICT)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4470 {
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4471 if (verbose)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4472 emsg(_(e_cannot_slice_dictionary));
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4473 return FAIL;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4474 }
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4475 if (var2 != NULL)
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4476 n2 = tv_get_number(var2);
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4477 else
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4478 n2 = VARNUM_MAX;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4479 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4480
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4481 switch (rettv->v_type)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4482 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4483 case VAR_UNKNOWN:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4484 case VAR_ANY:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4485 case VAR_VOID:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4486 case VAR_FUNC:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4487 case VAR_PARTIAL:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4488 case VAR_FLOAT:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4489 case VAR_BOOL:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4490 case VAR_SPECIAL:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4491 case VAR_JOB:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4492 case VAR_CHANNEL:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
4493 case VAR_INSTR:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4494 break; // not evaluating, skipping over subscript
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4495
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4496 case VAR_NUMBER:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4497 case VAR_STRING:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4498 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4499 char_u *s = tv_get_string(rettv);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4500
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4501 len = (long)STRLEN(s);
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4502 if (in_vim9script() || exclusive)
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
4503 {
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4504 if (is_range)
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4505 s = string_slice(s, n1, n2, exclusive);
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
4506 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
4507 s = char_from_string(s, n1);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
4508 }
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4509 else if (is_range)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4510 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4511 // The resulting variable is a substring. If the indexes
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4512 // are out of range the result is empty.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4513 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4514 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4515 n1 = len + n1;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4516 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4517 n1 = 0;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4518 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4519 if (n2 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4520 n2 = len + n2;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4521 else if (n2 >= len)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4522 n2 = len;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4523 if (n1 >= len || n2 < 0 || n1 > n2)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4524 s = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4525 else
20751
d9a2e5dcfd9f patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20731
diff changeset
4526 s = vim_strnsave(s + n1, n2 - n1 + 1);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4527 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4528 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4529 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4530 // The resulting variable is a string of a single
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4531 // character. If the index is too big or negative the
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4532 // result is empty.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4533 if (n1 >= len || n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4534 s = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4535 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4536 s = vim_strnsave(s + n1, 1);
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4537 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4538 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4539 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4540 rettv->vval.v_string = s;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4541 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4542 break;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4543
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4544 case VAR_BLOB:
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
4545 blob_slice_or_index(rettv->vval.v_blob, is_range, n1, n2,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
4546 exclusive, rettv);
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4547 break;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4548
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4549 case VAR_LIST:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4550 if (var1 == NULL)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4551 n1 = 0;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4552 if (var2 == NULL)
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4553 n2 = VARNUM_MAX;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4554 if (list_slice_or_index(rettv->vval.v_list,
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23600
diff changeset
4555 is_range, n1, n2, exclusive, rettv, verbose) == FAIL)
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4556 return FAIL;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4557 break;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4558
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4559 case VAR_DICT:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4560 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4561 dictitem_T *item;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4562 typval_T tmp;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4563
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4564 if (key == NULL)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4565 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4566 key = tv_get_string_chk(var1);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4567 if (key == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4568 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4569 }
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4570
26329
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4571 item = dict_find(rettv->vval.v_dict, key, keylen);
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4572
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4573 if (item == NULL)
26329
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4574 {
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4575 if (verbose)
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4576 {
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4577 if (keylen > 0)
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4578 key[keylen] = NUL;
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4579 semsg(_(e_key_not_present_in_dictionary), key);
26329
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4580 }
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4581 return FAIL;
26329
8afd7aa25ab6 patch 8.2.3695: confusing error for missing key
Bram Moolenaar <Bram@vim.org>
parents: 26238
diff changeset
4582 }
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4583
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4584 copy_tv(&item->di_tv, &tmp);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4585 clear_tv(rettv);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4586 *rettv = tmp;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4587 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
4588 break;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4589 }
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4590 return OK;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4591 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4592
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4593 /*
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
4594 * Return the function name of partial "pt".
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4595 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4596 char_u *
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4597 partial_name(partial_T *pt)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4598 {
24618
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
4599 if (pt != NULL)
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
4600 {
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
4601 if (pt->pt_name != NULL)
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
4602 return pt->pt_name;
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
4603 if (pt->pt_func != NULL)
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
4604 return pt->pt_func->uf_name;
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
4605 }
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
4606 return (char_u *)"";
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4607 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4608
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4609 static void
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4610 partial_free(partial_T *pt)
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4611 {
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4612 int i;
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4613
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4614 for (i = 0; i < pt->pt_argc; ++i)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4615 clear_tv(&pt->pt_argv[i]);
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4616 vim_free(pt->pt_argv);
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4617 dict_unref(pt->pt_dict);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4618 if (pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4619 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4620 func_unref(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4621 vim_free(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4622 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4623 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4624 func_ptr_unref(pt->pt_func);
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4625
24860
594edca79708 patch 8.2.2968: Vim9: memory leak
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
4626 // "out_up" is no longer used, decrement refcount on partial that owns it.
594edca79708 patch 8.2.2968: Vim9: memory leak
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
4627 partial_unref(pt->pt_outer.out_up_partial);
594edca79708 patch 8.2.2968: Vim9: memory leak
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
4628
27591
d91be28bbdbb patch 8.2.4322: Vim9: crash when using funcref with closure
Bram Moolenaar <Bram@vim.org>
parents: 27583
diff changeset
4629 // Using pt_outer from another partial.
d91be28bbdbb patch 8.2.4322: Vim9: crash when using funcref with closure
Bram Moolenaar <Bram@vim.org>
parents: 27583
diff changeset
4630 partial_unref(pt->pt_outer_partial);
d91be28bbdbb patch 8.2.4322: Vim9: crash when using funcref with closure
Bram Moolenaar <Bram@vim.org>
parents: 27583
diff changeset
4631
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4632 // Decrease the reference count for the context of a closure. If down
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4633 // to the minimum it may be time to free it.
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4634 if (pt->pt_funcstack != NULL)
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4635 {
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4636 --pt->pt_funcstack->fs_refcount;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4637 funcstack_check_refcount(pt->pt_funcstack);
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4638 }
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4639
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4640 vim_free(pt);
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4641 }
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4642
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4643 /*
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4644 * Unreference a closure: decrement the reference count and free it when it
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4645 * becomes zero.
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4646 */
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4647 void
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4648 partial_unref(partial_T *pt)
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4649 {
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4650 if (pt != NULL)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4651 {
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4652 if (--pt->pt_refcount <= 0)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4653 partial_free(pt);
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4654
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4655 // If the reference count goes down to one, the funcstack may be the
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4656 // only reference and can be freed if no other partials reference it.
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4657 else if (pt->pt_refcount == 1 && pt->pt_funcstack != NULL)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4658 funcstack_check_refcount(pt->pt_funcstack);
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22529
diff changeset
4659 }
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4660 }
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
4661
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
4662 /*
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4663 * Return the next (unique) copy ID.
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4664 * Used for serializing nested structures.
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4665 */
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4666 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4667 get_copyID(void)
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4668 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4669 current_copyID += COPYID_INC;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4670 return current_copyID;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4671 }
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4672
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4673 /*
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4674 * Garbage collection for lists and dictionaries.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4675 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4676 * We use reference counts to be able to free most items right away when they
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4677 * are no longer used. But for composite items it's possible that it becomes
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4678 * unused while the reference count is > 0: When there is a recursive
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4679 * reference. Example:
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4680 * :let l = [1, 2, 3]
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4681 * :let d = {9: l}
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4682 * :let l[1] = d
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4683 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4684 * Since this is quite unusual we handle this with garbage collection: every
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4685 * once in a while find out which lists and dicts are not referenced from any
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4686 * variable.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4687 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4688 * Here is a good reference text about garbage collection (refers to Python
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4689 * but it applies to all reference-counting mechanisms):
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4690 * http://python.ca/nas/python/gc/
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4691 */
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4692
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4693 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4694 * Do garbage collection for lists and dicts.
9108
d319453f62b3 commit https://github.com/vim/vim/commit/574860b5ee9da281c875dad07a607454e135eaee
Christian Brabandt <cb@256bit.org>
parents: 9104
diff changeset
4695 * When "testing" is TRUE this is called from test_garbagecollect_now().
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4696 * Return TRUE if some memory was freed.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4697 */
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4698 int
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4699 garbage_collect(int testing)
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4700 {
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4701 int copyID;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4702 int abort = FALSE;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4703 buf_T *buf;
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4704 win_T *wp;
6588
1ffe91b5e514 updated for version 7.4.620
Bram Moolenaar <bram@vim.org>
parents: 6577
diff changeset
4705 int did_free = FALSE;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
4706 tabpage_T *tp;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4707
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4708 if (!testing)
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4709 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4710 // Only do this once.
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4711 want_garbage_collect = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4712 may_garbage_collect = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4713 garbage_collect_at_exit = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4714 }
958
e88950f0d4f6 updated for version 7.0-084
vimboss
parents: 956
diff changeset
4715
19001
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4716 // The execution stack can grow big, limit the size.
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4717 if (exestack.ga_maxlen - exestack.ga_len > 500)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4718 {
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4719 size_t new_len;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4720 char_u *pp;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4721 int n;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4722
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4723 // Keep 150% of the current size, with a minimum of the growth size.
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4724 n = exestack.ga_len / 2;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4725 if (n < exestack.ga_growsize)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4726 n = exestack.ga_growsize;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4727
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4728 // Don't make it bigger though.
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4729 if (exestack.ga_len + n < exestack.ga_maxlen)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4730 {
27453
c7f614c9ceb3 patch 8.2.4255: theoretical computation overflow
Bram Moolenaar <Bram@vim.org>
parents: 27396
diff changeset
4731 new_len = (size_t)exestack.ga_itemsize * (exestack.ga_len + n);
19001
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4732 pp = vim_realloc(exestack.ga_data, new_len);
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4733 if (pp == NULL)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4734 return FAIL;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4735 exestack.ga_maxlen = exestack.ga_len + n;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4736 exestack.ga_data = pp;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4737 }
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4738 }
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
4739
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4740 // We advance by two because we add one for items referenced through
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4741 // previous_funccal.
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4742 copyID = get_copyID();
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4743
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4744 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4745 * 1. Go through all accessible variables and mark all lists and dicts
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4746 * with copyID.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4747 */
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4748
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4749 // Don't free variables in the previous_funccal list unless they are only
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4750 // referenced through previous_funccal. This must be first, because if
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4751 // the item is referenced elsewhere the funccal must not be freed.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4752 abort = abort || set_ref_in_previous_funccal(copyID);
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4753
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4754 // script-local variables
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
4755 abort = abort || garbage_collect_scriptvars(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4756
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4757 // buffer-local variables
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9636
diff changeset
4758 FOR_ALL_BUFFERS(buf)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4759 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4760 NULL, NULL);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4761
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4762 // window-local variables
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
4763 FOR_ALL_TAB_WINDOWS(tp, wp)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4764 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4765 NULL, NULL);
4309
bdab73bf24a8 updated for version 7.3.904
Bram Moolenaar <bram@vim.org>
parents: 4297
diff changeset
4766 if (aucmd_win != NULL)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4767 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4768 NULL, NULL);
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
4769 #ifdef FEAT_PROP_POPUP
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19874
diff changeset
4770 FOR_ALL_POPUPWINS(wp)
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
4771 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
4772 NULL, NULL);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
4773 FOR_ALL_TABPAGES(tp)
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19874
diff changeset
4774 FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
4775 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
4776 NULL, NULL);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
4777 #endif
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4778
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4779 // tabpage-local variables
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9636
diff changeset
4780 FOR_ALL_TABPAGES(tp)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4781 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4782 NULL, NULL);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4783 // global variables
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
4784 abort = abort || garbage_collect_globvars(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4785
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4786 // function-local variables
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4787 abort = abort || set_ref_in_call_stack(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4788
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4789 // named functions (matters for closures)
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
4790 abort = abort || set_ref_in_functions(copyID);
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
4791
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4792 // function call arguments, if v:testing is set.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4793 abort = abort || set_ref_in_func_args(copyID);
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
4794
26560
454a1c9ef797 patch 8.2.3809: Vim9: crash when garbage collecting a nested partial
Bram Moolenaar <Bram@vim.org>
parents: 26556
diff changeset
4795 // funcstacks keep variables for closures
454a1c9ef797 patch 8.2.3809: Vim9: crash when garbage collecting a nested partial
Bram Moolenaar <Bram@vim.org>
parents: 26556
diff changeset
4796 abort = abort || set_ref_in_funcstacks(copyID);
454a1c9ef797 patch 8.2.3809: Vim9: crash when garbage collecting a nested partial
Bram Moolenaar <Bram@vim.org>
parents: 26556
diff changeset
4797
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4798 // v: vars
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
4799 abort = abort || garbage_collect_vimvars(copyID);
1733
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1730
diff changeset
4800
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4801 // callbacks in buffers
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4802 abort = abort || set_ref_in_buffers(copyID);
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4803
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4804 // 'completefunc', 'omnifunc' and 'thesaurusfunc' callbacks
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4805 abort = abort || set_ref_in_insexpand_funcs(copyID);
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4806
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4807 // 'operatorfunc' callback
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4808 abort = abort || set_ref_in_opfunc(copyID);
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4809
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4810 // 'tagfunc' callback
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4811 abort = abort || set_ref_in_tagfunc(copyID);
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4812
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4813 // 'imactivatefunc' and 'imstatusfunc' callbacks
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4814 abort = abort || set_ref_in_im_funcs(copyID);
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
4815
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
4816 #ifdef FEAT_LUA
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4817 abort = abort || set_ref_in_lua(copyID);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
4818 #endif
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
4819
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4820 #ifdef FEAT_PYTHON
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4821 abort = abort || set_ref_in_python(copyID);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4822 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4823
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4824 #ifdef FEAT_PYTHON3
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4825 abort = abort || set_ref_in_python3(copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4826 #endif
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4827
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
4828 #ifdef FEAT_JOB_CHANNEL
8877
50e40f322e78 commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents: 8870
diff changeset
4829 abort = abort || set_ref_in_channel(copyID);
9058
87c2e43a4a12 commit https://github.com/vim/vim/commit/b8d4905592fc26fcd09180d7d6bfefd899f2f6c6
Christian Brabandt <cb@256bit.org>
parents: 9052
diff changeset
4830 abort = abort || set_ref_in_job(copyID);
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7895
diff changeset
4831 #endif
9052
3a6b66c02d6d commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents: 9027
diff changeset
4832 #ifdef FEAT_NETBEANS_INTG
3a6b66c02d6d commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents: 9027
diff changeset
4833 abort = abort || set_ref_in_nb_channel(copyID);
3a6b66c02d6d commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents: 9027
diff changeset
4834 #endif
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7895
diff changeset
4835
9153
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
4836 #ifdef FEAT_TIMERS
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
4837 abort = abort || set_ref_in_timer(copyID);
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
4838 #endif
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
4839
11412
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
4840 #ifdef FEAT_QUICKFIX
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
4841 abort = abort || set_ref_in_quickfix(copyID);
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
4842 #endif
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
4843
11804
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
4844 #ifdef FEAT_TERMINAL
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
4845 abort = abort || set_ref_in_term(copyID);
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
4846 #endif
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
4847
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
4848 #ifdef FEAT_PROP_POPUP
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4849 abort = abort || set_ref_in_popups(copyID);
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4850 #endif
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4851
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4852 if (!abort)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4853 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4854 /*
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4855 * 2. Free lists and dictionaries that are not referenced.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4856 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4857 did_free = free_unref_items(copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4858
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4859 /*
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4860 * 3. Check if any funccal can be freed now.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4861 * This may call us back recursively.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4862 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4863 free_unref_funccal(copyID, testing);
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4864 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4865 else if (p_verbose > 0)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4866 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
4867 verb_msg(_("Not enough memory to set references, garbage collection aborted!"));
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4868 }
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4869
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4870 return did_free;
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4871 }
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4872
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4873 /*
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4874 * Free lists, dictionaries, channels and jobs that are no longer referenced.
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4875 */
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4876 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4877 free_unref_items(int copyID)
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4878 {
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4879 int did_free = FALSE;
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4880
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4881 // Let all "free" functions know that we are here. This means no
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4882 // dictionaries, lists, channels or jobs are to be freed, because we will
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4883 // do that here.
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4884 in_free_unref_items = TRUE;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4885
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4886 /*
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4887 * PASS 1: free the contents of the items. We don't free the items
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4888 * themselves yet, so that it is possible to decrement refcount counters
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4889 */
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4890
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4891 // Go through the list of dicts and free items without the copyID.
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
4892 did_free |= dict_free_nonref(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4893
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4894 // Go through the list of lists and free items without the copyID.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents: 9556
diff changeset
4895 did_free |= list_free_nonref(copyID);
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4896
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4897 #ifdef FEAT_JOB_CHANNEL
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4898 // Go through the list of jobs and free items without the copyID. This
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4899 // must happen before doing channels, because jobs refer to channels, but
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4900 // the reference from the channel to the job isn't tracked.
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4901 did_free |= free_unused_jobs_contents(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4902
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4903 // Go through the list of channels and free items without the copyID.
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4904 did_free |= free_unused_channels_contents(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4905 #endif
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4906
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4907 /*
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4908 * PASS 2: free the items themselves.
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4909 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
4910 dict_free_items(copyID);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents: 9556
diff changeset
4911 list_free_items(copyID);
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4912
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4913 #ifdef FEAT_JOB_CHANNEL
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4914 // Go through the list of jobs and free items without the copyID. This
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4915 // must happen before doing channels, because jobs refer to channels, but
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4916 // the reference from the channel to the job isn't tracked.
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4917 free_unused_jobs(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4918
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4919 // Go through the list of channels and free items without the copyID.
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4920 free_unused_channels(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4921 #endif
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4922
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4923 in_free_unref_items = FALSE;
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
4924
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4925 return did_free;
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4926 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4927
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4928 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4929 * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4930 * "list_stack" is used to add lists to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4931 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4932 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4933 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4934 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4935 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack)
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4936 {
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4937 int todo;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4938 int abort = FALSE;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4939 hashitem_T *hi;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4940 hashtab_T *cur_ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4941 ht_stack_T *ht_stack = NULL;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4942 ht_stack_T *tempitem;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4943
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4944 cur_ht = ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4945 for (;;)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4946 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4947 if (!abort)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4948 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4949 // Mark each item in the hashtab. If the item contains a hashtab
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4950 // it is added to ht_stack, if it contains a list it is added to
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4951 // list_stack.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4952 todo = (int)cur_ht->ht_used;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4953 for (hi = cur_ht->ht_array; todo > 0; ++hi)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4954 if (!HASHITEM_EMPTY(hi))
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4955 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4956 --todo;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4957 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4958 &ht_stack, list_stack);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4959 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4960 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4961
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4962 if (ht_stack == NULL)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4963 break;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4964
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4965 // take an item from the stack
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4966 cur_ht = ht_stack->ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4967 tempitem = ht_stack;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4968 ht_stack = ht_stack->prev;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4969 free(tempitem);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4970 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4971
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4972 return abort;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4973 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4974
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26990
diff changeset
4975 #if defined(FEAT_LUA) || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26990
diff changeset
4976 || defined(PROTO)
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4977 /*
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4978 * Mark a dict and its items with "copyID".
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4979 * Returns TRUE if setting references failed somehow.
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4980 */
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4981 int
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4982 set_ref_in_dict(dict_T *d, int copyID)
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4983 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4984 if (d != NULL && d->dv_copyID != copyID)
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4985 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4986 d->dv_copyID = copyID;
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4987 return set_ref_in_ht(&d->dv_hashtab, copyID, NULL);
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4988 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4989 return FALSE;
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4990 }
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26990
diff changeset
4991 #endif
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4992
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4993 /*
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4994 * Mark a list and its items with "copyID".
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4995 * Returns TRUE if setting references failed somehow.
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4996 */
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4997 int
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4998 set_ref_in_list(list_T *ll, int copyID)
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4999 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5000 if (ll != NULL && ll->lv_copyID != copyID)
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5001 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5002 ll->lv_copyID = copyID;
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5003 return set_ref_in_list_items(ll, copyID, NULL);
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5004 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5005 return FALSE;
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5006 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5007
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5008 /*
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
5009 * Mark all lists and dicts referenced through list "l" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5010 * "ht_stack" is used to add hashtabs to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5011 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5012 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5013 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5014 int
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5015 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5016 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5017 listitem_T *li;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5018 int abort = FALSE;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5019 list_T *cur_l;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5020 list_stack_T *list_stack = NULL;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5021 list_stack_T *tempitem;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5022
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5023 cur_l = l;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5024 for (;;)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5025 {
19201
e7b4fff348dd patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
5026 if (!abort && cur_l->lv_first != &range_list_item)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5027 // Mark each item in the list. If the item contains a hashtab
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5028 // it is added to ht_stack, if it contains a list it is added to
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5029 // list_stack.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5030 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5031 abort = abort || set_ref_in_item(&li->li_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5032 ht_stack, &list_stack);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5033 if (list_stack == NULL)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5034 break;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5035
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5036 // take an item from the stack
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5037 cur_l = list_stack->list;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5038 tempitem = list_stack;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5039 list_stack = list_stack->prev;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5040 free(tempitem);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5041 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5042
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5043 return abort;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
5044 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
5045
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
5046 /*
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5047 * Mark the partial in callback 'cb' with "copyID".
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5048 */
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5049 int
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5050 set_ref_in_callback(callback_T *cb, int copyID)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5051 {
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5052 typval_T tv;
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5053
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5054 if (cb->cb_name == NULL || *cb->cb_name == NUL || cb->cb_partial == NULL)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5055 return FALSE;
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5056
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5057 tv.v_type = VAR_PARTIAL;
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5058 tv.vval.v_partial = cb->cb_partial;
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5059 return set_ref_in_item(&tv, copyID, NULL, NULL);
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5060 }
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5061
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26506
diff changeset
5062 /*
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
5063 * Mark all lists and dicts referenced through typval "tv" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5064 * "list_stack" is used to add lists to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5065 * "ht_stack" is used to add hashtabs to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5066 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5067 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5068 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5069 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5070 set_ref_in_item(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5071 typval_T *tv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5072 int copyID,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5073 ht_stack_T **ht_stack,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5074 list_stack_T **list_stack)
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
5075 {
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5076 int abort = FALSE;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
5077
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5078 if (tv->v_type == VAR_DICT)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5079 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5080 dict_T *dd = tv->vval.v_dict;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5081
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5082 if (dd != NULL && dd->dv_copyID != copyID)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5083 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5084 // Didn't see this dict yet.
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5085 dd->dv_copyID = copyID;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5086 if (ht_stack == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5087 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5088 abort = set_ref_in_ht(&dd->dv_hashtab, copyID, list_stack);
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5089 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5090 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5091 {
21915
2559dc02bd64 patch 8.2.1507: using malloc() directly
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
5092 ht_stack_T *newitem = ALLOC_ONE(ht_stack_T);
2559dc02bd64 patch 8.2.1507: using malloc() directly
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
5093
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5094 if (newitem == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5095 abort = TRUE;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5096 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5097 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5098 newitem->ht = &dd->dv_hashtab;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5099 newitem->prev = *ht_stack;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5100 *ht_stack = newitem;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5101 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5102 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5103 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5104 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5105 else if (tv->v_type == VAR_LIST)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5106 {
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5107 list_T *ll = tv->vval.v_list;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5108
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5109 if (ll != NULL && ll->lv_copyID != copyID)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5110 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5111 // Didn't see this list yet.
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5112 ll->lv_copyID = copyID;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5113 if (list_stack == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5114 {
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5115 abort = set_ref_in_list_items(ll, copyID, ht_stack);
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5116 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5117 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5118 {
21915
2559dc02bd64 patch 8.2.1507: using malloc() directly
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
5119 list_stack_T *newitem = ALLOC_ONE(list_stack_T);
2559dc02bd64 patch 8.2.1507: using malloc() directly
Bram Moolenaar <Bram@vim.org>
parents: 21899
diff changeset
5120
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5121 if (newitem == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5122 abort = TRUE;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5123 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5124 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5125 newitem->list = ll;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5126 newitem->prev = *list_stack;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5127 *list_stack = newitem;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5128 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5129 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5130 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5131 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5132 else if (tv->v_type == VAR_FUNC)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5133 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
5134 abort = set_ref_in_func(tv->vval.v_string, NULL, copyID);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5135 }
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5136 else if (tv->v_type == VAR_PARTIAL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5137 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5138 partial_T *pt = tv->vval.v_partial;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5139 int i;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5140
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
5141 if (pt != NULL && pt->pt_copyID != copyID)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5142 {
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
5143 // Didn't see this partial yet.
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
5144 pt->pt_copyID = copyID;
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
5145
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
5146 abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5147
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5148 if (pt->pt_dict != NULL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5149 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5150 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5151
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5152 dtv.v_type = VAR_DICT;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5153 dtv.vval.v_dict = pt->pt_dict;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5154 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5155 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5156
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5157 for (i = 0; i < pt->pt_argc; ++i)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5158 abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID,
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5159 ht_stack, list_stack);
26560
454a1c9ef797 patch 8.2.3809: Vim9: crash when garbage collecting a nested partial
Bram Moolenaar <Bram@vim.org>
parents: 26556
diff changeset
5160 // pt_funcstack is handled in set_ref_in_funcstacks()
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5161 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5162 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5163 #ifdef FEAT_JOB_CHANNEL
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5164 else if (tv->v_type == VAR_JOB)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5165 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5166 job_T *job = tv->vval.v_job;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5167 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5168
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5169 if (job != NULL && job->jv_copyID != copyID)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5170 {
8870
30988ffb7498 commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
5171 job->jv_copyID = copyID;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5172 if (job->jv_channel != NULL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5173 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5174 dtv.v_type = VAR_CHANNEL;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5175 dtv.vval.v_channel = job->jv_channel;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5176 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5177 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5178 if (job->jv_exit_cb.cb_partial != NULL)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5179 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5180 dtv.v_type = VAR_PARTIAL;
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5181 dtv.vval.v_partial = job->jv_exit_cb.cb_partial;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5182 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5183 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5184 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5185 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5186 else if (tv->v_type == VAR_CHANNEL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5187 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5188 channel_T *ch =tv->vval.v_channel;
10259
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10235
diff changeset
5189 ch_part_T part;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5190 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5191 jsonq_T *jq;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5192 cbq_T *cq;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5193
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5194 if (ch != NULL && ch->ch_copyID != copyID)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5195 {
8870
30988ffb7498 commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
5196 ch->ch_copyID = copyID;
10259
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10235
diff changeset
5197 for (part = PART_SOCK; part < PART_COUNT; ++part)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5198 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5199 for (jq = ch->ch_part[part].ch_json_head.jq_next; jq != NULL;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5200 jq = jq->jq_next)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5201 set_ref_in_item(jq->jq_value, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5202 for (cq = ch->ch_part[part].ch_cb_head.cq_next; cq != NULL;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5203 cq = cq->cq_next)
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5204 if (cq->cq_callback.cb_partial != NULL)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5205 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5206 dtv.v_type = VAR_PARTIAL;
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5207 dtv.vval.v_partial = cq->cq_callback.cb_partial;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5208 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5209 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5210 if (ch->ch_part[part].ch_callback.cb_partial != NULL)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5211 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5212 dtv.v_type = VAR_PARTIAL;
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5213 dtv.vval.v_partial =
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5214 ch->ch_part[part].ch_callback.cb_partial;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5215 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5216 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5217 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5218 if (ch->ch_callback.cb_partial != NULL)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5219 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5220 dtv.v_type = VAR_PARTIAL;
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5221 dtv.vval.v_partial = ch->ch_callback.cb_partial;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5222 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5223 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5224 if (ch->ch_close_cb.cb_partial != NULL)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5225 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5226 dtv.v_type = VAR_PARTIAL;
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5227 dtv.vval.v_partial = ch->ch_close_cb.cb_partial;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5228 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5229 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5230 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5231 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
5232 #endif
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
5233 return abort;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
5234 }
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
5235
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5236 /*
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5237 * Return a string with the string representation of a variable.
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5238 * If the memory is allocated "tofree" is set to it, otherwise NULL.
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
5239 * "numbuf" is used for a number.
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5240 * When "copyID" is not NULL replace recursive lists and dicts with "...".
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5241 * When both "echo_style" and "composite_val" are FALSE, put quotes around
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23191
diff changeset
5242 * strings as "string()", otherwise does not put quotes around strings, as
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5243 * ":echo" displays values.
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5244 * When "restore_copyID" is FALSE, repeated items in dictionaries and lists
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5245 * are replaced with "...".
1360
8d09c1eed8a5 updated for version 7.1-074
vimboss
parents: 1341
diff changeset
5246 * May return NULL.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5247 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
5248 char_u *
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5249 echo_string_core(
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5250 typval_T *tv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5251 char_u **tofree,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5252 char_u *numbuf,
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5253 int copyID,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5254 int echo_style,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5255 int restore_copyID,
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5256 int composite_val)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5257 {
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5258 static int recurse = 0;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5259 char_u *r = NULL;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5260
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5261 if (recurse >= DICT_MAXNEST)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5262 {
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
5263 if (!did_echo_string_emsg)
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
5264 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5265 // Only give this message once for a recursive call to avoid
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5266 // flooding the user with errors. And stop iterating over lists
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5267 // and dicts.
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
5268 did_echo_string_emsg = TRUE;
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26925
diff changeset
5269 emsg(_(e_variable_nested_too_deep_for_displaying));
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
5270 }
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5271 *tofree = NULL;
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
5272 return (char_u *)"{E724}";
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5273 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5274 ++recurse;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5275
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5276 switch (tv->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5277 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5278 case VAR_STRING:
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5279 if (echo_style && !composite_val)
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5280 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5281 *tofree = NULL;
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5282 r = tv->vval.v_string;
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5283 if (r == NULL)
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5284 r = (char_u *)"";
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5285 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5286 else
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5287 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5288 *tofree = string_quote(tv->vval.v_string, FALSE);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5289 r = *tofree;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5290 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5291 break;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5292
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5293 case VAR_FUNC:
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5294 if (echo_style)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5295 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5296 *tofree = NULL;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5297 r = tv->vval.v_string;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5298 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5299 else
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5300 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5301 *tofree = string_quote(tv->vval.v_string, TRUE);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5302 r = *tofree;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5303 }
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5304 break;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5305
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5306 case VAR_PARTIAL:
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5307 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5308 partial_T *pt = tv->vval.v_partial;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5309 char_u *fname = string_quote(pt == NULL ? NULL
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
5310 : partial_name(pt), FALSE);
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5311 garray_T ga;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5312 int i;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5313 char_u *tf;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5314
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5315 ga_init2(&ga, 1, 100);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5316 ga_concat(&ga, (char_u *)"function(");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5317 if (fname != NULL)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5318 {
26472
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5319 // When using uf_name prepend "g:" for a global function.
26474
9c84f7c6082d patch 8.2.3767: crash when using NULL partial
Bram Moolenaar <Bram@vim.org>
parents: 26472
diff changeset
5320 if (pt != NULL && pt->pt_name == NULL && fname[0] == '\''
26472
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5321 && vim_isupper(fname[1]))
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5322 {
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5323 ga_concat(&ga, (char_u *)"'g:");
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5324 ga_concat(&ga, fname + 1);
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5325 }
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5326 else
cc95e10e1cf2 patch 8.2.3766: converting a funcref to a string leaves out "g:"
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
5327 ga_concat(&ga, fname);
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5328 vim_free(fname);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5329 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5330 if (pt != NULL && pt->pt_argc > 0)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5331 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5332 ga_concat(&ga, (char_u *)", [");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5333 for (i = 0; i < pt->pt_argc; ++i)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5334 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5335 if (i > 0)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5336 ga_concat(&ga, (char_u *)", ");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5337 ga_concat(&ga,
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5338 tv2string(&pt->pt_argv[i], &tf, numbuf, copyID));
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5339 vim_free(tf);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5340 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5341 ga_concat(&ga, (char_u *)"]");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5342 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5343 if (pt != NULL && pt->pt_dict != NULL)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5344 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5345 typval_T dtv;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5346
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5347 ga_concat(&ga, (char_u *)", ");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5348 dtv.v_type = VAR_DICT;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5349 dtv.vval.v_dict = pt->pt_dict;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5350 ga_concat(&ga, tv2string(&dtv, &tf, numbuf, copyID));
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5351 vim_free(tf);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5352 }
26642
7fe649a64777 patch 8.2.3850: illegal memory access when displaying a partial
Bram Moolenaar <Bram@vim.org>
parents: 26636
diff changeset
5353 // terminate with ')' and a NUL
7fe649a64777 patch 8.2.3850: illegal memory access when displaying a partial
Bram Moolenaar <Bram@vim.org>
parents: 26636
diff changeset
5354 ga_concat_len(&ga, (char_u *)")", 2);
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5355
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5356 *tofree = ga.ga_data;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5357 r = *tofree;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5358 break;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
5359 }
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5360
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5361 case VAR_BLOB:
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15464
diff changeset
5362 r = blob2string(tv->vval.v_blob, tofree, numbuf);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5363 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5364
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5365 case VAR_LIST:
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5366 if (tv->vval.v_list == NULL)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5367 {
20126
831b1ea43020 patch 8.2.0618: echoing a null list results in no output
Bram Moolenaar <Bram@vim.org>
parents: 20111
diff changeset
5368 // NULL list is equivalent to empty list.
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5369 *tofree = NULL;
20126
831b1ea43020 patch 8.2.0618: echoing a null list results in no output
Bram Moolenaar <Bram@vim.org>
parents: 20111
diff changeset
5370 r = (char_u *)"[]";
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5371 }
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5372 else if (copyID != 0 && tv->vval.v_list->lv_copyID == copyID
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5373 && tv->vval.v_list->lv_len > 0)
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5374 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5375 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5376 r = (char_u *)"[...]";
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5377 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5378 else
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5379 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5380 int old_copyID = tv->vval.v_list->lv_copyID;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5381
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5382 tv->vval.v_list->lv_copyID = copyID;
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5383 *tofree = list2string(tv, copyID, restore_copyID);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5384 if (restore_copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5385 tv->vval.v_list->lv_copyID = old_copyID;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5386 r = *tofree;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5387 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5388 break;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5389
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5390 case VAR_DICT:
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5391 if (tv->vval.v_dict == NULL)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5392 {
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
5393 // NULL dict is equivalent to empty dict.
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5394 *tofree = NULL;
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
5395 r = (char_u *)"{}";
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5396 }
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5397 else if (copyID != 0 && tv->vval.v_dict->dv_copyID == copyID
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5398 && tv->vval.v_dict->dv_hashtab.ht_used != 0)
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5399 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5400 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5401 r = (char_u *)"{...}";
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5402 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5403 else
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5404 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5405 int old_copyID = tv->vval.v_dict->dv_copyID;
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
5406
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5407 tv->vval.v_dict->dv_copyID = copyID;
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5408 *tofree = dict2string(tv, copyID, restore_copyID);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5409 if (restore_copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5410 tv->vval.v_dict->dv_copyID = old_copyID;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5411 r = *tofree;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5412 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5413 break;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5414
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5415 case VAR_NUMBER:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5416 case VAR_UNKNOWN:
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
5417 case VAR_ANY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5418 case VAR_VOID:
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5419 *tofree = NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5420 r = tv_get_string_buf(tv, numbuf);
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5421 break;
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5422
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5423 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5424 case VAR_CHANNEL:
24818
fcab26a7fd4d patch 8.2.2947: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
5425 #ifdef FEAT_JOB_CHANNEL
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5426 *tofree = NULL;
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24780
diff changeset
5427 r = tv->v_type == VAR_JOB ? job_to_string_buf(tv, numbuf)
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24780
diff changeset
5428 : channel_to_string_buf(tv, numbuf);
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5429 if (composite_val)
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5430 {
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5431 *tofree = string_quote(r, FALSE);
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5432 r = *tofree;
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
5433 }
24818
fcab26a7fd4d patch 8.2.2947: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
5434 #endif
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5435 break;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
5436
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
5437 case VAR_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
5438 *tofree = NULL;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
5439 r = (char_u *)"instructions";
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
5440 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
5441
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5442 case VAR_FLOAT:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5443 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5444 *tofree = NULL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5445 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5446 r = numbuf;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5447 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5448 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5449
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5450 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
5451 case VAR_SPECIAL:
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
5452 *tofree = NULL;
7730
80ce794827c4 commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents: 7720
diff changeset
5453 r = (char_u *)get_var_special_name(tv->vval.v_number);
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
5454 break;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5455 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5456
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
5457 if (--recurse == 0)
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
5458 did_echo_string_emsg = FALSE;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5459 return r;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5460 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5461
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5462 /*
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5463 * Return a string with the string representation of a variable.
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5464 * If the memory is allocated "tofree" is set to it, otherwise NULL.
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5465 * "numbuf" is used for a number.
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5466 * Does not put quotes around strings, as ":echo" displays values.
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5467 * When "copyID" is not NULL replace recursive lists and dicts with "...".
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5468 * May return NULL.
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5469 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
5470 char_u *
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5471 echo_string(
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5472 typval_T *tv,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5473 char_u **tofree,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5474 char_u *numbuf,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5475 int copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5476 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5477 return echo_string_core(tv, tofree, numbuf, copyID, TRUE, FALSE, FALSE);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5478 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5479
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
5480 /*
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5481 * Convert the specified byte index of line 'lnum' in buffer 'buf' to a
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5482 * character index. Works only for loaded buffers. Returns -1 on failure.
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5483 * The index of the first byte and the first character is zero.
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5484 */
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5485 int
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5486 buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5487 {
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5488 char_u *str;
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5489 char_u *t;
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5490 int count;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5491
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5492 if (buf == NULL || buf->b_ml.ml_mfp == NULL)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5493 return -1;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5494
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5495 if (lnum > buf->b_ml.ml_line_count)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5496 lnum = buf->b_ml.ml_line_count;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5497
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5498 str = ml_get_buf(buf, lnum, FALSE);
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5499 if (str == NULL)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5500 return -1;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5501
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5502 if (*str == NUL)
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5503 return 0;
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5504
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5505 // count the number of characters
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5506 t = str;
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5507 for (count = 0; *t != NUL && t <= str + byteidx; count++)
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5508 t += mb_ptr2len(t);
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5509
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5510 // In insert mode, when the cursor is at the end of a non-empty line,
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5511 // byteidx points to the NUL character immediately past the end of the
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5512 // string. In this case, add one to the character count.
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5513 if (*t == NUL && byteidx != 0 && t == str + byteidx)
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5514 count++;
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5515
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5516 return count - 1;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5517 }
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5518
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5519 /*
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5520 * Convert the specified character index of line 'lnum' in buffer 'buf' to a
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5521 * byte index. Works only for loaded buffers. Returns -1 on failure.
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5522 * The index of the first byte and the first character is zero.
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5523 */
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5524 int
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5525 buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5526 {
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5527 char_u *str;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5528 char_u *t;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5529
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5530 if (buf == NULL || buf->b_ml.ml_mfp == NULL)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5531 return -1;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5532
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5533 if (lnum > buf->b_ml.ml_line_count)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5534 lnum = buf->b_ml.ml_line_count;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5535
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5536 str = ml_get_buf(buf, lnum, FALSE);
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5537 if (str == NULL)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5538 return -1;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5539
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5540 // Convert the character offset to a byte offset
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5541 t = str;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5542 while (*t != NUL && --charidx > 0)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5543 t += mb_ptr2len(t);
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5544
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5545 return t - str;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5546 }
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5547
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5548 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 * Translate a String variable into a position.
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5550 * Returns NULL when there is an error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5551 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
5552 pos_T *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5553 var2fpos(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5554 typval_T *varp,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5555 int dollar_lnum, // TRUE when $ is last line
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5556 int *fnum, // set to fnum for '0, 'A, etc.
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5557 int charcol) // return character column
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5558 {
700
c78d973dce9e updated for version 7.0211
vimboss
parents: 697
diff changeset
5559 char_u *name;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 static pos_T pos;
700
c78d973dce9e updated for version 7.0211
vimboss
parents: 697
diff changeset
5561 pos_T *pp;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5563 // Argument can be [lnum, col, coladd].
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5564 if (varp->v_type == VAR_LIST)
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5565 {
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5566 list_T *l;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5567 int len;
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5568 int error = FALSE;
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5569 listitem_T *li;
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5570
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5571 l = varp->vval.v_list;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5572 if (l == NULL)
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5573 return NULL;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5574
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5575 // Get the line number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5576 pos.lnum = list_find_nr(l, 0L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5577 if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5578 return NULL; // invalid line number
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5579 if (charcol)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5580 len = (long)mb_charlen(ml_get(pos.lnum));
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5581 else
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5582 len = (long)STRLEN(ml_get(pos.lnum));
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5583
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5584 // Get the column number
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5585 // We accept "$" for the column number: last column.
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5586 li = list_find(l, 1L);
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5587 if (li != NULL && li->li_tv.v_type == VAR_STRING
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5588 && li->li_tv.vval.v_string != NULL
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5589 && STRCMP(li->li_tv.vval.v_string, "$") == 0)
21899
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5590 {
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5591 pos.col = len + 1;
21899
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5592 }
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5593 else
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5594 {
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5595 pos.col = list_find_nr(l, 1L, &error);
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5596 if (error)
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5597 return NULL;
8fe86125dcba patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents: 21889
diff changeset
5598 }
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5599
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5600 // Accept a position up to the NUL after the line.
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
5601 if (pos.col == 0 || (int)pos.col > len + 1)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5602 return NULL; // invalid column number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5603 --pos.col;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5604
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5605 // Get the virtual offset. Defaults to zero.
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5606 pos.coladd = list_find_nr(l, 2L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5607 if (error)
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5608 pos.coladd = 0;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5609
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5610 return &pos;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5611 }
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
5612
24250
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24240
diff changeset
5613 if (in_vim9script() && check_for_string_arg(varp, 0) == FAIL)
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24240
diff changeset
5614 return NULL;
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24240
diff changeset
5615
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5616 name = tv_get_string_chk(varp);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5617 if (name == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5618 return NULL;
26775
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 26646
diff changeset
5619 if (name[0] == '.' && (!in_vim9script() || name[1] == NUL))
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5620 {
26775
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 26646
diff changeset
5621 // cursor
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5622 pos = curwin->w_cursor;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5623 if (charcol)
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5624 pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5625 return &pos;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5626 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5627 if (name[0] == 'v' && name[1] == NUL) // Visual start
1609
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
5628 {
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
5629 if (VIsual_active)
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5630 pos = VIsual;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5631 else
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5632 pos = curwin->w_cursor;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5633 if (charcol)
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5634 pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5635 return &pos;
1609
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
5636 }
26775
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 26646
diff changeset
5637 if (name[0] == '\'' && (!in_vim9script()
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 26646
diff changeset
5638 || (name[1] != NUL && name[2] == NUL)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5639 {
26775
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 26646
diff changeset
5640 // mark
4043
80b041b994d1 updated for version 7.3.776
Bram Moolenaar <bram@vim.org>
parents: 3986
diff changeset
5641 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5642 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5643 return NULL;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5644 if (charcol)
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5645 pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5646 return pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 }
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5648
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5649 pos.coladd = 0;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
5650
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5651 if (name[0] == 'w' && dollar_lnum)
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5652 {
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5653 pos.col = 0;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5654 if (name[1] == '0') // "w0": first visible line
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5655 {
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
5656 update_topline();
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5657 // In silent Ex mode topline is zero, but that's not a valid line
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5658 // number; use one instead.
11313
327a04a762f6 patch 8.0.0542: getpos() can return a negative line number
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
5659 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1;
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5660 return &pos;
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5661 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5662 else if (name[1] == '$') // "w$": last visible line
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5663 {
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
5664 validate_botline();
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5665 // In silent Ex mode botline is zero, return zero then.
11313
327a04a762f6 patch 8.0.0542: getpos() can return a negative line number
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
5666 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0;
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5667 return &pos;
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5668 }
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
5669 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5670 else if (name[0] == '$') // last column or line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5671 {
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
5672 if (dollar_lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5674 pos.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5675 pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5676 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5677 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5678 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5679 pos.lnum = curwin->w_cursor.lnum;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5680 if (charcol)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5681 pos.col = (colnr_T)mb_charlen(ml_get_curline());
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5682 else
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5683 pos.col = (colnr_T)STRLEN(ml_get_curline());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5684 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5685 return &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5686 }
25216
9ead67e3c696 patch 8.2.3144: Vim9: no error when using an invalid value for a line number
Bram Moolenaar <Bram@vim.org>
parents: 25206
diff changeset
5687 if (in_vim9script())
9ead67e3c696 patch 8.2.3144: Vim9: no error when using an invalid value for a line number
Bram Moolenaar <Bram@vim.org>
parents: 25206
diff changeset
5688 semsg(_(e_invalid_value_for_line_number_str), name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5689 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5690 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5691
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5692 /*
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5693 * Convert list in "arg" into a position and optional file number.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5694 * When "fnump" is NULL there is no file number, only 3 items.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5695 * Note that the column is passed on as-is, the caller may want to decrement
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5696 * it to use 1 for the first column.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5697 * Return FAIL when conversion is not possible, doesn't check the position for
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5698 * validity.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5699 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
5700 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5701 list2fpos(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5702 typval_T *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5703 pos_T *posp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5704 int *fnump,
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5705 colnr_T *curswantp,
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5706 int charcol)
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5707 {
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5708 list_T *l = arg->vval.v_list;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5709 long i = 0;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5710 long n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5711
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5712 // List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5713 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional.
915
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
5714 if (arg->v_type != VAR_LIST
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
5715 || l == NULL
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
5716 || l->lv_len < (fnump == NULL ? 2 : 3)
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
5717 || l->lv_len > (fnump == NULL ? 4 : 5))
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5718 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5719
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5720 if (fnump != NULL)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5721 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5722 n = list_find_nr(l, i++, NULL); // fnum
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5723 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5724 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5725 if (n == 0)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5726 n = curbuf->b_fnum; // current buffer
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5727 *fnump = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5728 }
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5729
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5730 n = list_find_nr(l, i++, NULL); // lnum
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5731 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5732 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5733 posp->lnum = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5734
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5735 n = list_find_nr(l, i++, NULL); // col
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5736 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5737 return FAIL;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5738 // If character position is specified, then convert to byte position
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5739 if (charcol)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5740 {
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5741 buf_T *buf;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5742
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5743 // Get the text for the specified line in a loaded buffer
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5744 buf = buflist_findnr(fnump == NULL ? curbuf->b_fnum : *fnump);
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5745 if (buf == NULL || buf->b_ml.ml_mfp == NULL)
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5746 return FAIL;
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5747
23600
f4347a61ed38 patch 8.2.2342: "char" functions may return wrong column in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
5748 n = buf_charidx_to_byteidx(buf, posp->lnum, n) + 1;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5749 }
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5750 posp->col = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5751
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5752 n = list_find_nr(l, i, NULL); // off
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5753 if (n < 0)
915
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
5754 posp->coladd = 0;
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
5755 else
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
5756 posp->coladd = n;
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5757
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
5758 if (curswantp != NULL)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5759 *curswantp = list_find_nr(l, i + 1, NULL); // curswant
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
5760
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5761 return OK;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5762 }
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5763
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
5764 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5765 * Get the length of an environment variable name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5766 * Advance "arg" to the first character after the name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5767 * Return 0 for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5768 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
5769 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5770 get_env_len(char_u **arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5771 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5772 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5773 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5775 for (p = *arg; vim_isIDc(*p); ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5776 ;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5777 if (p == *arg) // no name found
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5778 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5779
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5780 len = (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5781 *arg = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5782 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5783 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5785 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5786 * Get the length of the name of a function or internal variable.
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
5787 * "arg" is advanced to after the name.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5788 * Return 0 if something is wrong.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5789 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
5790 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5791 get_id_len(char_u **arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5792 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5793 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5794 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5795
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5796 // Find the end of the name.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5797 for (p = *arg; eval_isnamec(*p); ++p)
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5798 {
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5799 if (*p == ':')
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5800 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5801 // "s:" is start of "s:var", but "n:" is not and can be used in
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5802 // slice "[n:]". Also "xx:" is not a namespace.
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5803 len = (int)(p - *arg);
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5804 if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL)
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5805 || len > 1)
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5806 break;
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5807 }
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5808 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5809 if (p == *arg) // no name found
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5810 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5811
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5812 len = (int)(p - *arg);
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
5813 *arg = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5814
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5815 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5817
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5818 /*
124
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
5819 * Get the length of the name of a variable or function.
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
5820 * Only the name is recognized, does not handle ".key" or "[idx]".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5821 * "arg" is advanced to the first non-white character after the name.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5822 * Return -1 if curly braces expansion failed.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5823 * Return 0 if something else is wrong.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5824 * If the name contains 'magic' {}'s, expand them and return the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5825 * expanded name in an allocated string via 'alias' - caller must free.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5826 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
5827 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5828 get_name_len(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5829 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5830 char_u **alias,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5831 int evaluate,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5832 int verbose)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5833 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5834 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5835 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5836 char_u *expr_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5837 char_u *expr_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5838
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5839 *alias = NULL; // default to no alias
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5841 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5842 && (*arg)[2] == (int)KE_SNR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5843 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5844 // hard coded <SNR>, already translated
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5845 *arg += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5846 return get_id_len(arg) + 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5847 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5848 len = eval_fname_script(*arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5849 if (len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5850 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5851 // literal "<SID>", "s:" or "<SNR>"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5852 *arg += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5853 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5854
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5855 /*
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5856 * Find the end of the name; check for {} construction.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5857 */
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5858 p = find_name_end(*arg, &expr_start, &expr_end,
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5859 len > 0 ? 0 : FNE_CHECK_START);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5860 if (expr_start != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5861 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5862 char_u *temp_string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5863
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5864 if (!evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5865 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5866 len += (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5867 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5868 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5870
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5871 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5872 * Include any <SID> etc in the expanded string:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5873 * Thus the -len here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5874 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5875 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5876 if (temp_string == NULL)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5877 return -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5878 *alias = temp_string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5879 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5880 return (int)STRLEN(temp_string);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5881 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5882
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5883 len += get_id_len(arg);
15464
3faa7cc8207c patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 15460
diff changeset
5884 // Only give an error when there is something, otherwise it will be
3faa7cc8207c patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 15460
diff changeset
5885 // reported at a higher level.
3faa7cc8207c patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 15460
diff changeset
5886 if (len == 0 && verbose && **arg != NUL)
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
5887 semsg(_(e_invalid_expression_str), *arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5888
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5889 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5891
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5892 /*
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5893 * Find the end of a variable or function name, taking care of magic braces.
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5894 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5895 * start and end of the first magic braces item.
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5896 * "flags" can have FNE_INCL_BR and FNE_CHECK_START.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5897 * Return a pointer to just after the name. Equal to "arg" if there is no
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5898 * valid name.
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5899 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
5900 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5901 find_name_end(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5902 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5903 char_u **expr_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5904 char_u **expr_end,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5905 int flags)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5906 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5907 int mb_nest = 0;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5908 int br_nest = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5909 char_u *p;
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5910 int len;
21279
8d1d11afd8c8 patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents: 21277
diff changeset
5911 int vim9script = in_vim9script();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5912
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5913 if (expr_start != NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5914 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5915 *expr_start = NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5916 *expr_end = NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5917 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5918
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5919 // Quick check for valid starting character.
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20061
diff changeset
5920 if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20061
diff changeset
5921 && (*arg != '{' || vim9script))
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5922 return arg;
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5923
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5924 for (p = arg; *p != NUL
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5925 && (eval_isnamec(*p)
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20061
diff changeset
5926 || (*p == '{' && !vim9script)
21447
369cde0d5771 patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
5927 || ((flags & FNE_INCL_BR) && (*p == '['
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
5928 || (*p == '.' && eval_isdictc(p[1]))))
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5929 || mb_nest != 0
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
5930 || br_nest != 0); MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5931 {
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5932 if (*p == '\'')
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5933 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5934 // skip over 'string' to avoid counting [ and ] inside it.
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
5935 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5936 ;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5937 if (*p == NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5938 break;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5939 }
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5940 else if (*p == '"')
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5941 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5942 // skip over "str\"ing" to avoid counting [ and ] inside it.
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
5943 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5944 if (*p == '\\' && p[1] != NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5945 ++p;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5946 if (*p == NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5947 break;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5948 }
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5949 else if (br_nest == 0 && mb_nest == 0 && *p == ':')
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5950 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5951 // "s:" is start of "s:var", but "n:" is not and can be used in
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5952 // slice "[n:]". Also "xx:" is not a namespace. But {ns}: is.
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5953 len = (int)(p - arg);
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5954 if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL)
7627
d9ec7d22494d commit https://github.com/vim/vim/commit/4119cf80e1e534057680f9543e73edf7967c2440
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
5955 || (len > 1 && p[-1] != '}'))
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5956 break;
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5957 }
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5958
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5959 if (mb_nest == 0)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5960 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5961 if (*p == '[')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5962 ++br_nest;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5963 else if (*p == ']')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5964 --br_nest;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5965 }
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5966
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20061
diff changeset
5967 if (br_nest == 0 && !vim9script)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5968 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5969 if (*p == '{')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5970 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5971 mb_nest++;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5972 if (expr_start != NULL && *expr_start == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5973 *expr_start = p;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5974 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5975 else if (*p == '}')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5976 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5977 mb_nest--;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5978 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5979 *expr_end = p;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5980 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5981 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5984 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5985 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5987 /*
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5988 * Expands out the 'magic' {}'s in a variable/function name.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5989 * Note that this can call itself recursively, to deal with
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5990 * constructs like foo{bar}{baz}{bam}
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5991 * The four pointer arguments point to "foo{expre}ss{ion}bar"
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5992 * "in_start" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5993 * "expr_start" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5994 * "expr_end" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5995 * "in_end" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5996 *
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5997 * Returns a new allocated string, which the caller must free.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5998 * Returns NULL for failure.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5999 */
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6000 static char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6001 make_expanded_name(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6002 char_u *in_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6003 char_u *expr_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6004 char_u *expr_end,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6005 char_u *in_end)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6006 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6007 char_u c1;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6008 char_u *retval = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6009 char_u *temp_result;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6010
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6011 if (expr_end == NULL || in_end == NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6012 return NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6013 *expr_start = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6014 *expr_end = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6015 c1 = *in_end;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6016 *in_end = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6017
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
6018 temp_result = eval_to_string(expr_start + 1, FALSE);
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
6019 if (temp_result != NULL)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6020 {
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
6021 retval = alloc(STRLEN(temp_result) + (expr_start - in_start)
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
6022 + (in_end - expr_end) + 1);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6023 if (retval != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6024 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6025 STRCPY(retval, in_start);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6026 STRCAT(retval, temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6027 STRCAT(retval, expr_end + 1);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6028 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6029 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6030 vim_free(temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6031
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6032 *in_end = c1; // put char back for error messages
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6033 *expr_start = '{';
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6034 *expr_end = '}';
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6035
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6036 if (retval != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6037 {
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6038 temp_result = find_name_end(retval, &expr_start, &expr_end, 0);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6039 if (expr_start != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6040 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6041 // Further expansion!
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6042 temp_result = make_expanded_name(retval, expr_start,
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6043 expr_end, temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6044 vim_free(retval);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6045 retval = temp_result;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6046 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6047 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6048
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6049 return retval;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6050 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6051
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6052 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 * Return TRUE if character "c" can be used in a variable or function name.
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6054 * Does not include '{' or '}' for magic braces.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
6056 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6057 eval_isnamec(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 {
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6059 return ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR;
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6060 }
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6061
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6062 /*
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6063 * Return TRUE if character "c" can be used as the first character in a
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6064 * variable or function name (excluding '{' and '}').
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6065 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
6066 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6067 eval_isnamec1(int c)
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
6068 {
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6069 return ASCII_ISALPHA(c) || c == '_';
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6070 }
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6071
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6072 /*
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6073 * Return TRUE if character "c" can be used as the first character of a
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6074 * dictionary key.
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6075 */
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6076 int
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6077 eval_isdictc(int c)
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6078 {
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6079 return ASCII_ISALNUM(c) || c == '_';
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082 /*
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6083 * Handle:
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6084 * - expr[expr], expr[expr:expr] subscript
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6085 * - ".name" lookup
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6086 * - function call with Funcref variable: func(expr)
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6087 * - method call: var->method()
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6088 *
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6089 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len()
26990
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
6090 * "name_start" points to a variable before the subscript or is NULL.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6091 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
6092 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6093 handle_subscript(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6094 char_u **arg,
26990
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
6095 char_u *name_start,
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6096 typval_T *rettv,
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
6097 evalarg_T *evalarg,
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
6098 int verbose) // give error messages
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6099 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
6100 int evaluate = evalarg != NULL
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
6101 && (evalarg->eval_flags & EVAL_EVALUATE);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6102 int ret = OK;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6103 dict_T *selfdict = NULL;
21142
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
6104 int check_white = TRUE;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6105 int getnext;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6106 char_u *p;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6107
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6108 while (ret == OK)
21142
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
6109 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6110 // When at the end of the line and ".name" or "->{" or "->X" follows in
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6111 // the next line then consume the line break.
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6112 p = eval_next_non_blank(*arg, evalarg, &getnext);
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6113 if (getnext
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21461
diff changeset
6114 && ((rettv->v_type == VAR_DICT && *p == '.' && eval_isdictc(p[1]))
24852
3c8bd1d392d1 patch 8.2.2964: Vim9: hang when using space after ->
Bram Moolenaar <Bram@vim.org>
parents: 24818
diff changeset
6115 || (p[0] == '-' && p[1] == '>' && (p[2] == '{'
3c8bd1d392d1 patch 8.2.2964: Vim9: hang when using space after ->
Bram Moolenaar <Bram@vim.org>
parents: 24818
diff changeset
6116 || ASCII_ISALPHA(in_vim9script() ? *skipwhite(p + 2)
3c8bd1d392d1 patch 8.2.2964: Vim9: hang when using space after ->
Bram Moolenaar <Bram@vim.org>
parents: 24818
diff changeset
6117 : p[2])))))
21142
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
6118 {
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
6119 *arg = eval_next_line(evalarg);
21865
c16af87df654 patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
6120 p = *arg;
21142
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
6121 check_white = FALSE;
165cea61e974 patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
6122 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6123
24112
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6124 if (rettv->v_type == VAR_ANY)
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6125 {
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6126 char_u *exp_name;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6127 int cc;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6128 int idx;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6129 ufunc_T *ufunc;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6130 type_T *type;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6131
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
6132 // Found script from "import {name} as name", script item name must
27080
9897dd3c6530 patch 8.2.4069: Vim9: import test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 27043
diff changeset
6133 // follow. "rettv->vval.v_number" has the script ID.
24112
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6134 if (**arg != '.')
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6135 {
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6136 if (verbose)
26990
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
6137 semsg(_(e_expected_dot_after_name_str),
4b8d836db103 patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents: 26980
diff changeset
6138 name_start != NULL ? name_start: *arg);
24112
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6139 ret = FAIL;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6140 break;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6141 }
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6142 ++*arg;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6143 if (IS_WHITE_OR_NUL(**arg))
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6144 {
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6145 if (verbose)
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6146 emsg(_(e_no_white_space_allowed_after_dot));
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6147 ret = FAIL;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6148 break;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6149 }
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6150
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6151 // isolate the name
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6152 exp_name = *arg;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6153 while (eval_isnamec(**arg))
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6154 ++*arg;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6155 cc = **arg;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6156 **arg = NUL;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6157
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6158 idx = find_exported(rettv->vval.v_number, exp_name, &ufunc, &type,
27613
42d0279c6e7c patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents: 27591
diff changeset
6159 evalarg->eval_cctx, evalarg->eval_cstack, verbose);
24112
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6160 **arg = cc;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6161
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6162 if (idx < 0 && ufunc == NULL)
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6163 {
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6164 ret = FAIL;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6165 break;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6166 }
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6167 if (idx >= 0)
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6168 {
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6169 scriptitem_T *si = SCRIPT_ITEM(rettv->vval.v_number);
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6170 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6171
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6172 copy_tv(sv->sv_tv, rettv);
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6173 }
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6174 else
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6175 {
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6176 rettv->v_type = VAR_FUNC;
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6177 rettv->vval.v_string = vim_strsave(ufunc->uf_name);
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6178 }
26980
8796f1384750 patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 26954
diff changeset
6179 continue;
24112
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6180 }
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24063
diff changeset
6181
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6182 if ((**arg == '(' && (!evaluate || rettv->v_type == VAR_FUNC
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6183 || rettv->v_type == VAR_PARTIAL))
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6184 && (!check_white || !VIM_ISWHITE(*(*arg - 1))))
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6185 {
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
6186 ret = call_func_rettv(arg, evalarg, rettv, evaluate,
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
6187 selfdict, NULL);
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
6188
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
6189 // Stop the expression evaluation when immediately aborting on
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
6190 // error, or when an interrupt occurred or an exception was thrown
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
6191 // but not caught.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6192 if (aborting())
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6193 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6194 if (ret == OK)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6195 clear_tv(rettv);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6196 ret = FAIL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6197 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6198 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6199 selfdict = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6200 }
21552
cbc570e66d11 patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
6201 else if (p[0] == '-' && p[1] == '>')
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6202 {
24632
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6203 if (in_vim9script())
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6204 *arg = skipwhite(p + 2);
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6205 else
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6206 *arg = p + 2;
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
6207 if (ret == OK)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
6208 {
24632
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6209 if (VIM_ISWHITE(**arg))
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6210 {
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
6211 emsg(_(e_no_white_space_allowed_before_parenthesis));
24632
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6212 ret = FAIL;
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6213 }
9e72076e31f8 patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
6214 else if ((**arg == '{' && !in_vim9script()) || **arg == '(')
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23416
diff changeset
6215 // expr->{lambda}() or expr->(lambda)()
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
6216 ret = eval_lambda(arg, rettv, evalarg, verbose);
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
6217 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
6218 // expr->name()
21118
b0baa80cb53f patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents: 21104
diff changeset
6219 ret = eval_method(arg, rettv, evalarg, verbose);
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
6220 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
6221 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6222 // "." is ".name" lookup when we found a dict or when evaluating and
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6223 // scriptversion is at least 2, where string concatenation is "..".
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6224 else if (**arg == '['
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6225 || (**arg == '.' && (rettv->v_type == VAR_DICT
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6226 || (!evaluate
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6227 && (*arg)[1] != '.'
25622
15b54e0a576b patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 25620
diff changeset
6228 && !in_old_script(2)))))
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6229 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6230 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6231 if (rettv->v_type == VAR_DICT)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6232 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6233 selfdict = rettv->vval.v_dict;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6234 if (selfdict != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6235 ++selfdict->dv_refcount;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6236 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6237 else
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6238 selfdict = NULL;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
6239 if (eval_index(arg, rettv, evalarg, verbose) == FAIL)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6240 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6241 clear_tv(rettv);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6242 ret = FAIL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6243 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6244 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6245 else
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21148
diff changeset
6246 break;
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6247 }
8575
b5209a4e5baf commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
6248
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6249 // Turn "dict.Func" into a partial for "Func" bound to "dict".
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6250 // Don't do this when "Func" is already a partial that was bound
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6251 // explicitly (pt_auto is FALSE).
9104
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
6252 if (selfdict != NULL
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
6253 && (rettv->v_type == VAR_FUNC
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
6254 || (rettv->v_type == VAR_PARTIAL
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
6255 && (rettv->vval.v_partial->pt_auto
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
6256 || rettv->vval.v_partial->pt_dict == NULL))))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
6257 selfdict = make_partial(selfdict, rettv);
8575
b5209a4e5baf commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
6258
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6259 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6260 return ret;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6261 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6262
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
6263 /*
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6264 * Make a copy of an item.
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6265 * Lists and Dictionaries are also copied. A deep copy if "deep" is set.
27517
f00a7a2bee21 patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
6266 * "top" is TRUE for the toplevel of copy().
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6267 * For deepcopy() "copyID" is zero for a full copy or the ID for when a
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6268 * reference to an already copied list/dict can be used.
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6269 * Returns FAIL or OK.
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6270 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
6271 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6272 item_copy(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6273 typval_T *from,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6274 typval_T *to,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6275 int deep,
27517
f00a7a2bee21 patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
6276 int top,
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6277 int copyID)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6278 {
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6279 static int recurse = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6280 int ret = OK;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6281
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
6282 if (recurse >= DICT_MAXNEST)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6283 {
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26925
diff changeset
6284 emsg(_(e_variable_nested_too_deep_for_making_copy));
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6285 return FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6286 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6287 ++recurse;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6288
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6289 switch (from->v_type)
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6290 {
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6291 case VAR_NUMBER:
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6292 case VAR_FLOAT:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6293 case VAR_STRING:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6294 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
6295 case VAR_PARTIAL:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
6296 case VAR_BOOL:
7862
d4fec9208e7e commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents: 7856
diff changeset
6297 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
6298 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
6299 case VAR_CHANNEL:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24553
diff changeset
6300 case VAR_INSTR:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6301 copy_tv(from, to);
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6302 break;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6303 case VAR_LIST:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6304 to->v_type = VAR_LIST;
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
6305 to->v_lock = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6306 if (from->vval.v_list == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6307 to->vval.v_list = NULL;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6308 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6309 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6310 // use the copy made earlier
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6311 to->vval.v_list = from->vval.v_list->lv_copylist;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6312 ++to->vval.v_list->lv_refcount;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6313 }
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6314 else
27517
f00a7a2bee21 patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
6315 to->vval.v_list = list_copy(from->vval.v_list,
f00a7a2bee21 patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
6316 deep, top, copyID);
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6317 if (to->vval.v_list == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6318 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6319 break;
15496
f1c33409e908 patch 8.1.0756: copy() does not make a copy of a Blob
Bram Moolenaar <Bram@vim.org>
parents: 15490
diff changeset
6320 case VAR_BLOB:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6321 ret = blob_copy(from->vval.v_blob, to);
15496
f1c33409e908 patch 8.1.0756: copy() does not make a copy of a Blob
Bram Moolenaar <Bram@vim.org>
parents: 15490
diff changeset
6322 break;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6323 case VAR_DICT:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6324 to->v_type = VAR_DICT;
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
6325 to->v_lock = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6326 if (from->vval.v_dict == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6327 to->vval.v_dict = NULL;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6328 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6329 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6330 // use the copy made earlier
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6331 to->vval.v_dict = from->vval.v_dict->dv_copydict;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6332 ++to->vval.v_dict->dv_refcount;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6333 }
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6334 else
27517
f00a7a2bee21 patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
6335 to->vval.v_dict = dict_copy(from->vval.v_dict,
f00a7a2bee21 patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
6336 deep, top, copyID);
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6337 if (to->vval.v_dict == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6338 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6339 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
6340 case VAR_UNKNOWN:
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
6341 case VAR_ANY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6342 case VAR_VOID:
19554
b38d73f36467 patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
6343 internal_error_no_abort("item_copy(UNKNOWN)");
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6344 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6345 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6346 --recurse;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
6347 return ret;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6348 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6349
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6350 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6351 echo_one(typval_T *rettv, int with_space, int *atstart, int *needclr)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6352 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6353 char_u *tofree;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6354 char_u numbuf[NUMBUFLEN];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6355 char_u *p = echo_string(rettv, &tofree, numbuf, get_copyID());
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6356
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6357 if (*atstart)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6358 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6359 *atstart = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6360 // Call msg_start() after eval1(), evaluating the expression
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6361 // may cause a message to appear.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6362 if (with_space)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6363 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6364 // Mark the saved text as finishing the line, so that what
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6365 // follows is displayed on a new line when scrolling back
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6366 // at the more prompt.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6367 msg_sb_eol();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6368 msg_start();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6369 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6370 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6371 else if (with_space)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6372 msg_puts_attr(" ", echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6373
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6374 if (p != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6375 for ( ; *p != NUL && !got_int; ++p)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6376 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6377 if (*p == '\n' || *p == '\r' || *p == TAB)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6378 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6379 if (*p != TAB && *needclr)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6380 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6381 // remove any text still there from the command
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6382 msg_clr_eos();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6383 *needclr = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6384 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6385 msg_putchar_attr(*p, echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6386 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6387 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6388 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6389 if (has_mbyte)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6390 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6391 int i = (*mb_ptr2len)(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6392
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6393 (void)msg_outtrans_len_attr(p, i, echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6394 p += i - 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6395 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6396 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6397 (void)msg_outtrans_len_attr(p, 1, echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6398 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6399 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6400 vim_free(tofree);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6401 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6402
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6403 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6404 * ":echo expr1 ..." print each argument separated with a space, add a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6405 * newline at the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6406 * ":echon expr1 ..." print each argument plain.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6407 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6408 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6409 ex_echo(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6410 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6411 char_u *arg = eap->arg;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
6412 typval_T rettv;
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6413 char_u *arg_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6414 int needclr = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6415 int atstart = TRUE;
15079
a527110d5f56 patch 8.1.0550: expression evaluation may repeat an error message
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
6416 int did_emsg_before = did_emsg;
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6417 int called_emsg_before = called_emsg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
6418 evalarg_T evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
6419
21104
f8ec5a7a9cf6 patch 8.2.1103: Coverity reports an unnecessary NULL check
Bram Moolenaar <Bram@vim.org>
parents: 21098
diff changeset
6420 fill_evalarg_from_eap(&evalarg, eap, eap->skip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6422 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6423 ++emsg_skip;
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
6424 while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6425 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6426 // If eval1() causes an error message the text from the command may
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6427 // still need to be cleared. E.g., "echo 22,44".
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6428 need_clr_eos = needclr;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6429
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6430 arg_start = arg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
6431 if (eval1(&arg, &rettv, &evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6432 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6433 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6434 * Report the invalid expression unless the expression evaluation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6435 * has been cancelled due to an aborting error, an interrupt, or an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6436 * exception.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6437 */
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6438 if (!aborting() && did_emsg == did_emsg_before
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6439 && called_emsg == called_emsg_before)
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
6440 semsg(_(e_invalid_expression_str), arg_start);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6441 need_clr_eos = FALSE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6442 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6443 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6444 need_clr_eos = FALSE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6445
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6446 if (!eap->skip)
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6447 {
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6448 if (rettv.v_type == VAR_VOID)
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6449 {
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6450 semsg(_(e_expression_does_not_result_in_value_str), arg_start);
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6451 break;
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6452 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6453 echo_one(&rettv, eap->cmdidx == CMD_echo, &atstart, &needclr);
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6454 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6455
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
6456 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6457 arg = skipwhite(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6458 }
25521
2063b858cad9 patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
6459 set_nextcmd(eap, arg);
21050
7a9daf73a724 patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents: 21048
diff changeset
6460 clear_evalarg(&evalarg, eap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6461
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6462 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6463 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6464 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6465 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6466 // remove text that may still be there from the command
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6467 if (needclr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6468 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6469 if (eap->cmdidx == CMD_echo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6470 msg_end();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6474 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6475 * ":echohl {name}".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6476 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6477 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6478 ex_echohl(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6479 {
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
6480 echo_attr = syn_name2attr(eap->arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6483 /*
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6484 * Returns the :echo attribute
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6485 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6486 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6487 get_echo_attr(void)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6488 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6489 return echo_attr;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6490 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6491
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6492 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6493 * ":execute expr1 ..." execute the result of an expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6494 * ":echomsg expr1 ..." Print a message
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6495 * ":echoerr expr1 ..." Print an error
24194
9f64c420f280 patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
6496 * ":echoconsole expr1 ..." Print a message on stdout
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6497 * Each gets spaces around each argument and a newline at the end for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6498 * echo commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6499 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6500 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6501 ex_execute(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6502 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6503 char_u *arg = eap->arg;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
6504 typval_T rettv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6505 int ret = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6506 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6507 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6508 int len;
25220
89b39ce243e2 patch 8.2.3146: Vim9: line number wrong for :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 25216
diff changeset
6509 long start_lnum = SOURCING_LNUM;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6511 ga_init2(&ga, 1, 80);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6513 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6514 ++emsg_skip;
20061
6e6a75800884 patch 8.2.0586: Vim9: # comment not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20059
diff changeset
6515 while (!ends_excmd2(eap->cmd, arg) || *arg == '"')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6516 {
21098
e88b0daa2fcb patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 21096
diff changeset
6517 ret = eval1_emsg(&arg, &rettv, eap);
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
6518 if (ret == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6519 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6521 if (!eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6522 {
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6523 char_u buf[NUMBUFLEN];
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6524
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6525 if (eap->cmdidx == CMD_execute)
19087
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6526 {
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6527 if (rettv.v_type == VAR_CHANNEL || rettv.v_type == VAR_JOB)
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6528 {
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6529 semsg(_(e_using_invalid_value_as_string_str),
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
6530 vartype_name(rettv.v_type));
19087
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6531 p = NULL;
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6532 }
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6533 else
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6534 p = tv_get_string_buf(&rettv, buf);
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6535 }
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6536 else
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6537 p = tv_stringify(&rettv, buf);
19081
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6538 if (p == NULL)
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6539 {
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6540 clear_tv(&rettv);
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6541 ret = FAIL;
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6542 break;
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6543 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6544 len = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545 if (ga_grow(&ga, len + 2) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
6547 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6551 if (ga.ga_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 ga.ga_len += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
6557 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558 arg = skipwhite(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561 if (ret != FAIL && ga.ga_data != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6562 {
25220
89b39ce243e2 patch 8.2.3146: Vim9: line number wrong for :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 25216
diff changeset
6563 // use the first line of continuation lines for messages
89b39ce243e2 patch 8.2.3146: Vim9: line number wrong for :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 25216
diff changeset
6564 SOURCING_LNUM = start_lnum;
89b39ce243e2 patch 8.2.3146: Vim9: line number wrong for :execute argument
Bram Moolenaar <Bram@vim.org>
parents: 25216
diff changeset
6565
11161
404e98047f0b patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
6566 if (eap->cmdidx == CMD_echomsg || eap->cmdidx == CMD_echoerr)
404e98047f0b patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
6567 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6568 // Mark the already saved text as finishing the line, so that what
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6569 // follows is displayed on a new line when scrolling back at the
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6570 // more prompt.
11161
404e98047f0b patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
6571 msg_sb_eol();
404e98047f0b patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
6572 }
404e98047f0b patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
6573
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6574 if (eap->cmdidx == CMD_echomsg)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
6575 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
6576 msg_attr(ga.ga_data, echo_attr);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
6577 out_flush();
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
6578 }
24194
9f64c420f280 patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
6579 else if (eap->cmdidx == CMD_echoconsole)
9f64c420f280 patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
6580 {
9f64c420f280 patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
6581 ui_write(ga.ga_data, (int)STRLEN(ga.ga_data), TRUE);
9f64c420f280 patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
6582 ui_write((char_u *)"\r\n", 2, TRUE);
9f64c420f280 patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
6583 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6584 else if (eap->cmdidx == CMD_echoerr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6585 {
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
6586 int save_did_emsg = did_emsg;
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
6587
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6588 // We don't want to abort following commands, restore did_emsg.
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
6589 emsg(ga.ga_data);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6590 if (!force_abort)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6591 did_emsg = save_did_emsg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6593 else if (eap->cmdidx == CMD_execute)
27645
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6594 {
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6595 int save_sticky_cmdmod_flags = sticky_cmdmod_flags;
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6596
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6597 // "legacy exe cmd" and "vim9cmd exe cmd" applies to "cmd".
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6598 sticky_cmdmod_flags = cmdmod.cmod_flags
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6599 & (CMOD_LEGACY | CMOD_VIM9CMD);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6600 do_cmdline((char_u *)ga.ga_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6601 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE);
27645
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6602 sticky_cmdmod_flags = save_sticky_cmdmod_flags;
1712b102d642 patch 8.2.4348: "legacy exe cmd" does not do what one would expect
Bram Moolenaar <Bram@vim.org>
parents: 27613
diff changeset
6603 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6604 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6606 ga_clear(&ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6607
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6608 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6609 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610
25521
2063b858cad9 patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
6611 set_nextcmd(eap, arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6613
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6614 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6615 * Skip over the name of an option: "&option", "&g:option" or "&l:option".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6616 * "arg" points to the "&" or '+' when called, to "option" when returning.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6617 * Returns NULL when no option name found. Otherwise pointer to the char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6618 * after the option name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6619 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
6620 char_u *
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26329
diff changeset
6621 find_option_end(char_u **arg, int *scope)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6622 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6623 char_u *p = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6625 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6626 if (*p == 'g' && p[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6627 {
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26329
diff changeset
6628 *scope = OPT_GLOBAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6629 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6631 else if (*p == 'l' && p[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6632 {
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26329
diff changeset
6633 *scope = OPT_LOCAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6634 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6635 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6636 else
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26329
diff changeset
6637 *scope = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6639 if (!ASCII_ISALPHA(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6640 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6641 *arg = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6643 if (p[0] == 't' && p[1] == '_' && p[2] != NUL && p[3] != NUL)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6644 p += 4; // termcap option
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6645 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6646 while (ASCII_ISALPHA(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6647 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6648 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6649 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6650
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6651 /*
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6652 * Display script name where an item was last set.
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6653 * Should only be invoked when 'verbose' is non-zero.
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6654 */
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6655 void
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6656 last_set_msg(sctx_T script_ctx)
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6657 {
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6658 char_u *p;
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6659
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6660 if (script_ctx.sc_sid != 0)
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6661 {
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6662 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid));
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6663 if (p != NULL)
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6664 {
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6665 verbose_enter();
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
6666 msg_puts(_("\n\tLast set from "));
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
6667 msg_puts((char *)p);
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6668 if (script_ctx.sc_lnum > 0)
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6669 {
18939
25ebc35e104f patch 8.2.0030: "gF" does not work on output of "verbose command"
Bram Moolenaar <Bram@vim.org>
parents: 18851
diff changeset
6670 msg_puts(_(line_msg));
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6671 msg_outnum((long)script_ctx.sc_lnum);
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6672 }
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6673 verbose_leave();
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6674 vim_free(p);
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6675 }
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6676 }
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6677 }
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6678
17966
46f95606b9ec patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
6679 #endif // FEAT_EVAL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6680
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6681 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6682 * Perform a substitution on "str" with pattern "pat" and substitute "sub".
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
6683 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6684 * "flags" can be "g" to do a global substitute.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6685 * Returns an allocated string, NULL for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6686 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6687 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6688 do_string_sub(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6689 char_u *str,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6690 char_u *pat,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6691 char_u *sub,
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
6692 typval_T *expr,
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6693 char_u *flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6694 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6695 int sublen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6696 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6697 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6698 int do_all;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6699 char_u *tail;
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
6700 char_u *end;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6701 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6702 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6703 char_u *save_cpo;
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6704 char_u *zero_width = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6705
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6706 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6707 save_cpo = p_cpo;
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6708 p_cpo = empty_option;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6709
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6710 ga_init2(&ga, 1, 200);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6711
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6712 do_all = (flags[0] == 'g');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6714 regmatch.rm_ic = p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6715 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6716 if (regmatch.regprog != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6717 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6718 tail = str;
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
6719 end = str + STRLEN(str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6720 while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6721 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6722 // Skip empty match except for first match.
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6723 if (regmatch.startp[0] == regmatch.endp[0])
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6724 {
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6725 if (zero_width == regmatch.startp[0])
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6726 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6727 // avoid getting stuck on a match with an empty string
18251
c8a53c0daeed patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18225
diff changeset
6728 i = mb_ptr2len(tail);
5964
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6729 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail,
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6730 (size_t)i);
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6731 ga.ga_len += i;
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6732 tail += i;
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6733 continue;
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6734 }
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6735 zero_width = regmatch.startp[0];
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6736 }
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6737
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6738 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6739 * Get some space for a temporary buffer to do the substitution
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6740 * into. It will contain:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6741 * - The text up to where the match is.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6742 * - The substituted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6743 * - The text after the match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6744 */
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
6745 sublen = vim_regsub(&regmatch, sub, expr, tail, FALSE, TRUE, FALSE);
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
6746 if (ga_grow(&ga, (int)((end - tail) + sublen -
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6747 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6748 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6749 ga_clear(&ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6750 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6752
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6753 // copy the text up to where the match is
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6754 i = (int)(regmatch.startp[0] - tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6755 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6756 // add the substituted text
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
6757 (void)vim_regsub(&regmatch, sub, expr, (char_u *)ga.ga_data
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6758 + ga.ga_len + i, TRUE, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6759 ga.ga_len += i + sublen - 1;
5388
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
6760 tail = regmatch.endp[0];
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
6761 if (*tail == NUL)
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
6762 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6763 if (!do_all)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6764 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6765 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6766
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6767 if (ga.ga_data != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6768 STRCPY((char *)ga.ga_data + ga.ga_len, tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6769
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4778
diff changeset
6770 vim_regfree(regmatch.regprog);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6773 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6774 ga_clear(&ga);
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6775 if (p_cpo == empty_option)
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6776 p_cpo = save_cpo;
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6777 else
23493
f8382c4e6551 patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6778 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6779 // Darn, evaluating {sub} expression or {expr} changed the value.
23493
f8382c4e6551 patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6780 // If it's still empty it was changed and restored, need to restore in
f8382c4e6551 patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6781 // the complicated way.
f8382c4e6551 patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6782 if (*p_cpo == NUL)
f8382c4e6551 patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6783 set_option_value((char_u *)"cpo", 0L, save_cpo, 0);
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6784 free_string_option(save_cpo);
23493
f8382c4e6551 patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6785 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6786
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6787 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6788 }