Mercurial > vim
annotate src/eval.c @ 22272:eb1f5f618c75 v8.2.1685
patch 8.2.1685: Vim9: cannot declare a constant value
Commit: https://github.com/vim/vim/commit/0b4c66c67a083f25816b9cdb8e76a41e02d9f560
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 14 21:39:44 2020 +0200
patch 8.2.1685: Vim9: cannot declare a constant value
Problem: Vim9: cannot declare a constant value.
Solution: Introduce ":const!".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 14 Sep 2020 21:45:04 +0200 |
parents | 6f83d2adee74 |
children | 07e48ee8c3bb |
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 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * eval.c: Expression evaluation. | |
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 | 14 |
15 #include "vim.h" | |
16 | |
1624 | 17 #if defined(FEAT_EVAL) || defined(PROTO) |
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 | 25 /* |
364 | 26 * When recursively copying lists and dicts we need to remember which ones we |
27 * have done to avoid endless recursiveness. This unique ID is used for that. | |
1891 | 28 * The last bit is used for previous_funccal, ignored when comparing. |
364 | 29 */ |
30 static int current_copyID = 0; | |
5973 | 31 |
7 | 32 /* |
76 | 33 * Info used by a ":for" loop. |
34 */ | |
137 | 35 typedef struct |
76 | 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 |
137 | 44 } forinfo_T; |
76 | 45 |
7720
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
46 static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op); |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 static int eval6(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int want_string); |
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 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
|
53 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
|
54 |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
55 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
|
56 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
|
57 |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
58 /* |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
59 * Return "n1" divided by "n2", taking care of dividing by zero. |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
60 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
61 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
62 num_divide(varnumber_T n1, varnumber_T n2) |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
63 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
64 varnumber_T result; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
65 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
66 if (n2 == 0) // give an error message? |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
67 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
68 if (n1 == 0) |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
69 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
|
70 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
|
71 result = -VARNUM_MAX; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
72 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
73 result = VARNUM_MAX; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
74 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
75 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
76 result = n1 / n2; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
77 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
78 return result; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
79 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
80 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
81 /* |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
82 * Return "n1" modulus "n2", taking care of dividing by zero. |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
83 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
84 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
85 num_modulus(varnumber_T n1, varnumber_T 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 // Give an error when n2 is 0? |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
88 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
|
89 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
90 |
10567
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
91 #if defined(EBCDIC) || defined(PROTO) |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
92 /* |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
93 * Compare struct fst by function name. |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
94 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
95 static int |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
96 compare_func_name(const void *s1, const void *s2) |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
97 { |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
98 struct fst *p1 = (struct fst *)s1; |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
99 struct fst *p2 = (struct fst *)s2; |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
100 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
101 return STRCMP(p1->f_name, p2->f_name); |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
102 } |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
103 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
104 /* |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
105 * Sort the function table by function name. |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15482
diff
changeset
|
106 * The sorting of the table above is ASCII dependent. |
10567
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
107 * On machines using EBCDIC we have to sort it. |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
108 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
109 static void |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
110 sortFunctions(void) |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
111 { |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
112 int funcCnt = (int)(sizeof(functions) / sizeof(struct fst)) - 1; |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
113 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
114 qsort(functions, (size_t)funcCnt, sizeof(struct fst), compare_func_name); |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
115 } |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
116 #endif |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
117 |
137 | 118 /* |
119 * Initialize the global and v: variables. | |
120 */ | |
121 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
122 eval_init(void) |
137 | 123 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
124 evalvars_init(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
125 func_init(); |
137 | 126 |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
127 #ifdef EBCDIC |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
128 /* |
3178 | 129 * Sort the function table, to enable binary search. |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
130 */ |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
131 sortFunctions(); |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
132 #endif |
137 | 133 } |
134 | |
357 | 135 #if defined(EXITFREE) || defined(PROTO) |
136 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
137 eval_clear(void) |
357 | 138 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
139 evalvars_clear(); |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
140 free_scriptnames(); // must come after evalvars_clear(). |
2849 | 141 free_locales(); |
357 | 142 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
143 // 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
|
144 free_autoload_scriptnames(); |
855 | 145 |
16967
586d625e21b4
patch 8.1.1484: some tests are slow
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
146 // unreferenced lists and dicts |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
147 (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
|
148 |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16967
diff
changeset
|
149 // 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
|
150 free_all_functions(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
151 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
152 #endif |
137 | 153 |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
154 void |
21096
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
155 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
|
156 { |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
157 CLEAR_FIELD(*evalarg); |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
158 evalarg->eval_flags = skip ? 0 : EVAL_EVALUATE; |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
159 if (eap != NULL && getline_equal(eap->getline, eap->cookie, getsourceline)) |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
160 { |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
161 evalarg->eval_getline = eap->getline; |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
162 evalarg->eval_cookie = eap->cookie; |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
163 } |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
164 } |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
165 |
7 | 166 /* |
167 * Top level evaluation function, returning a boolean. | |
168 * Sets "error" to TRUE if there was an error. | |
169 * Return TRUE or FALSE. | |
170 */ | |
171 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
172 eval_to_bool( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
173 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
174 int *error, |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
175 exarg_T *eap, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
176 int skip) // only parse, don't execute |
7 | 177 { |
137 | 178 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
179 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
|
180 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
|
181 |
21096
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
182 fill_evalarg_from_eap(&evalarg, eap, skip); |
7 | 183 |
184 if (skip) | |
185 ++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
|
186 if (eval0(arg, &tv, eap, &evalarg) == FAIL) |
7 | 187 *error = TRUE; |
188 else | |
189 { | |
190 *error = FALSE; | |
191 if (!skip) | |
192 { | |
21733
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
193 if (in_vim9script()) |
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
194 retval = tv2bool(&tv); |
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
195 else |
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
196 retval = (tv_get_number_chk(&tv, error) != 0); |
71 | 197 clear_tv(&tv); |
7 | 198 } |
199 } | |
200 if (skip) | |
201 --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
|
202 clear_evalarg(&evalarg, eap); |
7 | 203 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
204 return (int)retval; |
7 | 205 } |
206 | |
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 /* |
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 * 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
|
209 */ |
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 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
|
211 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
|
212 { |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 |
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
219 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
|
220 |
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
221 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
|
222 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
|
223 { |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
224 // 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
|
225 // 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
|
226 // 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
|
227 // 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
|
228 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
|
229 && called_emsg == called_emsg_before) |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
230 semsg(_(e_invexpr2), 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
|
231 } |
21098
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
232 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
|
233 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
|
234 } |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
235 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
236 /* |
20731
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
237 * 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
|
238 * 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
|
239 */ |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
240 int |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
241 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
|
242 { |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
243 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
|
244 && (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
|
245 || (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
|
246 } |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
247 |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
248 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
249 * 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
|
250 * 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
|
251 * 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
|
252 */ |
16231
0761a4c111a7
patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
253 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
|
254 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
|
255 { |
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 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
|
257 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
|
258 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
|
259 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
260 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
|
261 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
262 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
|
263 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
|
264 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
265 CLEAR_FIELD(funcexe); |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
266 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
267 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
|
268 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
|
269 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
270 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
|
271 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
272 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
|
273 |
20156
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
274 if (partial == NULL) |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
275 return FAIL; |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
276 |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20526
diff
changeset
|
277 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
|
278 && 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
|
279 { |
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
|
280 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
|
281 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
|
282 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
283 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
284 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
285 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
286 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
|
287 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
|
288 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
289 CLEAR_FIELD(funcexe); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
290 funcexe.evaluate = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
291 funcexe.partial = partial; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
292 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
|
293 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
294 } |
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
|
295 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
296 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
|
297 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
298 s = tv_get_string_buf_chk(expr, buf); |
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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 return FAIL; |
21620
46956b6811a1
patch 8.2.1360: stray error for white space after expression
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
304 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
|
305 { |
14331
f8280e1bfc84
patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
306 clear_tv(rettv); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
307 semsg(_(e_invexpr2), 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
|
308 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
|
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 } |
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 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
|
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 |
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 * 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
|
316 * 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
|
317 */ |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
318 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
|
319 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
|
320 { |
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 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
|
322 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
|
323 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
324 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
|
325 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
326 *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
|
327 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
|
328 } |
21861
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
333 |
7 | 334 /* |
335 * Top level evaluation function, returning a string. If "skip" is TRUE, | |
336 * only parsing to "nextcmd" is done, without reporting errors. Return | |
337 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE. | |
338 */ | |
339 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
340 eval_to_string_skip( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
341 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
|
342 exarg_T *eap, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
343 int skip) // only parse, don't execute |
7 | 344 { |
137 | 345 typval_T tv; |
7 | 346 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
|
347 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
|
348 |
21096
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
349 fill_evalarg_from_eap(&evalarg, eap, skip); |
7 | 350 if (skip) |
351 ++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
|
352 if (eval0(arg, &tv, eap, &evalarg) == FAIL || skip) |
7 | 353 retval = NULL; |
354 else | |
355 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
356 retval = vim_strsave(tv_get_string(&tv)); |
71 | 357 clear_tv(&tv); |
7 | 358 } |
359 if (skip) | |
360 --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
|
361 clear_evalarg(&evalarg, eap); |
7 | 362 |
363 return retval; | |
364 } | |
365 | |
366 /* | |
9 | 367 * Skip over an expression at "*pp". |
368 * Return FAIL for an error, OK otherwise. | |
369 */ | |
370 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
371 skip_expr(char_u **pp) |
9 | 372 { |
137 | 373 typval_T rettv; |
9 | 374 |
375 *pp = skipwhite(*pp); | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
376 return eval1(pp, &rettv, NULL); |
9 | 377 } |
378 | |
379 /* | |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
380 * Skip over an expression at "*pp". |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
381 * 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
|
382 * 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
|
383 * "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
|
384 * "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
|
385 * 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
|
386 * 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
|
387 */ |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
388 int |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
389 skip_expr_concatenate( |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
390 char_u **arg, |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
391 char_u **start, |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
392 char_u **end, |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
393 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
|
394 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 garray_T *gap = evalarg == NULL ? NULL : &evalarg->eval_ga; |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
399 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
|
400 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
|
401 ? 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
|
402 |
c16af87df654
patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
403 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
|
404 && (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
|
405 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
406 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
|
407 // 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
|
408 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
|
409 ++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
|
410 } |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
411 *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
|
412 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
413 // 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
|
414 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
|
415 evalarg->eval_flags &= ~EVAL_EVALUATE; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
416 *arg = skipwhite(*arg); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
417 res = eval1(arg, &rettv, evalarg); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
418 *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
|
419 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
|
420 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
|
421 |
21865
c16af87df654
patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
422 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
|
423 && (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
|
424 { |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
425 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
|
426 { |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
427 // just one line, no need to concatenate |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
428 ga_clear(gap); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
429 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
|
430 } |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
431 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
432 { |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
433 char_u *p; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
434 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
|
435 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
436 // 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
|
437 *((char_u **)gap->ga_data) = *start; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
438 p = ga_concat_strings(gap, ""); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
439 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
440 // 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
|
441 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
|
442 { |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
443 // 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
|
444 *((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
|
445 // 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
|
446 // later. |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
447 vim_free(evalarg->eval_tofree); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
448 evalarg->eval_tofree = |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
449 ((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
|
450 ((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
|
451 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
|
452 } |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
453 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
454 ga_clear(gap); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
455 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
|
456 if (p == NULL) |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
457 return FAIL; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
458 *start = p; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
459 vim_free(evalarg->eval_tofree_lambda); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
460 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
|
461 // 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
|
462 *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
|
463 } |
21040
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 return res; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
467 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
468 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
469 /* |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
470 * 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
|
471 * breaks. |
1713 | 472 * When "convert" is TRUE convert a List into a sequence of lines and convert |
473 * a Float to a String. | |
7 | 474 * Return pointer to allocated memory, or NULL for failure. |
475 */ | |
476 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
477 eval_to_string( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
478 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
479 int convert) |
7 | 480 { |
137 | 481 typval_T tv; |
7 | 482 char_u *retval; |
714 | 483 garray_T ga; |
1851 | 484 #ifdef FEAT_FLOAT |
1713 | 485 char_u numbuf[NUMBUFLEN]; |
1851 | 486 #endif |
7 | 487 |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
488 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) |
7 | 489 retval = NULL; |
490 else | |
491 { | |
1713 | 492 if (convert && tv.v_type == VAR_LIST) |
714 | 493 { |
494 ga_init2(&ga, (int)sizeof(char), 80); | |
1690 | 495 if (tv.vval.v_list != NULL) |
3000 | 496 { |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
497 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0); |
3000 | 498 if (tv.vval.v_list->lv_len > 0) |
499 ga_append(&ga, NL); | |
500 } | |
714 | 501 ga_append(&ga, NUL); |
502 retval = (char_u *)ga.ga_data; | |
503 } | |
1713 | 504 #ifdef FEAT_FLOAT |
505 else if (convert && tv.v_type == VAR_FLOAT) | |
506 { | |
507 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float); | |
508 retval = vim_strsave(numbuf); | |
509 } | |
510 #endif | |
714 | 511 else |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
512 retval = vim_strsave(tv_get_string(&tv)); |
71 | 513 clear_tv(&tv); |
7 | 514 } |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
515 clear_evalarg(&EVALARG_EVALUATE, NULL); |
7 | 516 |
517 return retval; | |
518 } | |
519 | |
520 /* | |
634 | 521 * 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
|
522 * 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
|
523 * Use legacy Vim script syntax. |
7 | 524 */ |
525 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
526 eval_to_string_safe( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
527 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
528 int use_sandbox) |
7 | 529 { |
530 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
|
531 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
|
532 int save_sc_version = current_sctx.sc_version; |
6922d78b4d52
patch 8.2.1437: Vim9: 'statusline' is evaluated using Vim9 script syntax
Bram Moolenaar <Bram@vim.org>
parents:
21771
diff
changeset
|
533 |
6922d78b4d52
patch 8.2.1437: Vim9: 'statusline' is evaluated using Vim9 script syntax
Bram Moolenaar <Bram@vim.org>
parents:
21771
diff
changeset
|
534 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
|
535 save_funccal(&funccal_entry); |
634 | 536 if (use_sandbox) |
537 ++sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
538 ++textwinlock; |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
539 retval = eval_to_string(arg, FALSE); |
634 | 540 if (use_sandbox) |
541 --sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
542 --textwinlock; |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
543 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
|
544 current_sctx.sc_version = save_sc_version; |
7 | 545 return retval; |
546 } | |
547 | |
548 /* | |
549 * Top level evaluation function, returning a number. | |
550 * Evaluates "expr" silently. | |
551 * Returns -1 for an error. | |
552 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
553 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
554 eval_to_number(char_u *expr) |
7 | 555 { |
137 | 556 typval_T rettv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
557 varnumber_T retval; |
97 | 558 char_u *p = skipwhite(expr); |
7 | 559 |
560 ++emsg_off; | |
561 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
562 if (eval1(&p, &rettv, &EVALARG_EVALUATE) == FAIL) |
7 | 563 retval = -1; |
564 else | |
565 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
566 retval = tv_get_number_chk(&rettv, NULL); |
71 | 567 clear_tv(&rettv); |
7 | 568 } |
569 --emsg_off; | |
570 | |
571 return retval; | |
572 } | |
573 | |
446 | 574 /* |
625 | 575 * Top level evaluation function. |
576 * Returns an allocated typval_T with the result. | |
577 * Returns NULL when there is an error. | |
446 | 578 */ |
579 typval_T * | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
580 eval_expr(char_u *arg, exarg_T *eap) |
446 | 581 { |
582 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
|
583 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
|
584 |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
585 fill_evalarg_from_eap(&evalarg, eap, eap != NULL && eap->skip); |
446 | 586 |
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
|
587 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
|
588 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
|
589 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
|
590 |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
591 clear_evalarg(&evalarg, eap); |
446 | 592 return tv; |
593 } | |
594 | |
7 | 595 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
596 * 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
|
597 * 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
|
598 * should have type VAR_UNKNOWN. |
408 | 599 * Returns OK or FAIL. |
600 */ | |
3078 | 601 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
602 call_vim_function( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
603 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
604 int argc, |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
605 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
|
606 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
|
607 { |
408 | 608 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
609 funcexe_T funcexe; |
7 | 610 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
611 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
|
612 CLEAR_FIELD(funcexe); |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
613 funcexe.firstline = curwin->w_cursor.lnum; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
614 funcexe.lastline = curwin->w_cursor.lnum; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
615 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
616 ret = call_func(func, -1, rettv, argc, argv, &funcexe); |
408 | 617 if (ret == FAIL) |
618 clear_tv(rettv); | |
619 | |
620 return ret; | |
621 } | |
622 | |
4133 | 623 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
624 * Call Vim script function "func" and return the result as a number. |
4133 | 625 * Returns -1 when calling the function fails. |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
626 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
627 * have type VAR_UNKNOWN. |
4133 | 628 */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
629 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
630 call_func_retnr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
631 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
632 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
|
633 typval_T *argv) |
4133 | 634 { |
635 typval_T rettv; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
636 varnumber_T retval; |
4133 | 637 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
638 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
4133 | 639 return -1; |
640 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
641 retval = tv_get_number_chk(&rettv, NULL); |
4133 | 642 clear_tv(&rettv); |
643 return retval; | |
644 } | |
645 | |
408 | 646 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
647 * Call Vim script function "func" and return the result as a string. |
453 | 648 * Returns NULL when calling the function fails. |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
649 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
650 * have type VAR_UNKNOWN. |
408 | 651 */ |
652 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
653 call_func_retstr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
654 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
655 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
|
656 typval_T *argv) |
408 | 657 { |
658 typval_T rettv; | |
453 | 659 char_u *retval; |
408 | 660 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
661 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 662 return NULL; |
663 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
664 retval = vim_strsave(tv_get_string(&rettv)); |
408 | 665 clear_tv(&rettv); |
7 | 666 return retval; |
667 } | |
1322 | 668 |
453 | 669 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
670 * Call Vim script function "func" and return the result as a List. |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
671 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
672 * have type VAR_UNKNOWN. |
1690 | 673 * Returns NULL when there is something wrong. |
408 | 674 */ |
675 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
676 call_func_retlist( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
677 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
678 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
|
679 typval_T *argv) |
408 | 680 { |
681 typval_T rettv; | |
682 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
683 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 684 return NULL; |
685 | |
686 if (rettv.v_type != VAR_LIST) | |
687 { | |
688 clear_tv(&rettv); | |
689 return NULL; | |
690 } | |
691 | |
692 return rettv.vval.v_list; | |
693 } | |
1322 | 694 |
7 | 695 #ifdef FEAT_FOLDING |
696 /* | |
697 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding | |
698 * it in "*cp". Doesn't give error messages. | |
699 */ | |
700 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
701 eval_foldexpr(char_u *arg, int *cp) |
7 | 702 { |
137 | 703 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
704 varnumber_T retval; |
7 | 705 char_u *s; |
681 | 706 int use_sandbox = was_set_insecurely((char_u *)"foldexpr", |
707 OPT_LOCAL); | |
7 | 708 |
709 ++emsg_off; | |
634 | 710 if (use_sandbox) |
711 ++sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
712 ++textwinlock; |
7 | 713 *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
|
714 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) |
7 | 715 retval = 0; |
716 else | |
717 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
718 // If the result is a number, just return the number. |
71 | 719 if (tv.v_type == VAR_NUMBER) |
720 retval = tv.vval.v_number; | |
156 | 721 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL) |
7 | 722 retval = 0; |
723 else | |
724 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
725 // 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
|
726 // the number. |
71 | 727 s = tv.vval.v_string; |
7 | 728 if (!VIM_ISDIGIT(*s) && *s != '-') |
729 *cp = *s++; | |
730 retval = atol((char *)s); | |
731 } | |
71 | 732 clear_tv(&tv); |
7 | 733 } |
734 --emsg_off; | |
634 | 735 if (use_sandbox) |
736 --sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
737 --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
|
738 clear_evalarg(&EVALARG_EVALUATE, NULL); |
7 | 739 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
740 return (int)retval; |
7 | 741 } |
742 #endif | |
743 | |
744 /* | |
110 | 745 * Get an lval: variable, Dict item or List item that can be assigned a value |
746 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]", | |
747 * "name.key", "name.key[expr]" etc. | |
748 * Indexing only works if "name" is an existing List or Dictionary. | |
749 * "name" points to the start of the name. | |
750 * If "rettv" is not NULL it points to the value to be assigned. | |
751 * "unlet" is TRUE for ":unlet": slightly different behavior when something is | |
752 * wrong; must end in space or cmd separator. | |
753 * | |
5604 | 754 * flags: |
755 * 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
|
756 * GLV_READ_ONLY: will not change the variable |
5604 | 757 * GLV_NO_AUTOLOAD: do not use script autoloading |
758 * | |
110 | 759 * Returns a pointer to just after the name, including indexes. |
124 | 760 * When an evaluation error occurs "lp->ll_name" is NULL; |
110 | 761 * Returns NULL for a parsing error. Still need to free items in "lp"! |
71 | 762 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
763 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
764 get_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
765 char_u *name, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
766 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
767 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
768 int unlet, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
769 int skip, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
770 int flags, // GLV_ values |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
771 int fne_flags) // flags for find_name_end() |
110 | 772 { |
773 char_u *p; | |
774 char_u *expr_start, *expr_end; | |
775 int cc; | |
137 | 776 dictitem_T *v; |
777 typval_T var1; | |
778 typval_T var2; | |
110 | 779 int empty1 = FALSE; |
137 | 780 listitem_T *ni; |
100 | 781 char_u *key = NULL; |
782 int len; | |
137 | 783 hashtab_T *ht; |
5604 | 784 int quiet = flags & GLV_QUIET; |
71 | 785 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
786 // Clear everything in "lp". |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
787 CLEAR_POINTER(lp); |
110 | 788 |
789 if (skip) | |
790 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
791 // When skipping just find the end of the name. |
110 | 792 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
|
793 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
|
794 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
|
795 return lp->ll_name_end; |
110 | 796 } |
797 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
798 // Find the end of the name. |
271 | 799 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
|
800 lp->ll_name_end = p; |
110 | 801 if (expr_start != NULL) |
802 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
803 // 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
|
804 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p) |
110 | 805 && *p != '[' && *p != '.') |
806 { | |
21461
4dfd00f481fb
patch 8.2.1281: the "trailing characters" error can be hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
21447
diff
changeset
|
807 semsg(_(e_trailing_arg), p); |
110 | 808 return NULL; |
809 } | |
810 | |
811 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); | |
812 if (lp->ll_exp_name == NULL) | |
813 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
814 // 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
|
815 // 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
|
816 // aborting error, an interrupt, or an exception. |
110 | 817 if (!aborting() && !quiet) |
818 { | |
121 | 819 emsg_severe = TRUE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
820 semsg(_(e_invarg2), name); |
110 | 821 return NULL; |
822 } | |
823 } | |
824 lp->ll_name = lp->ll_exp_name; | |
825 } | |
826 else | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
827 { |
110 | 828 lp->ll_name = name; |
829 | |
21674
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
830 if (in_vim9script()) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
831 { |
21674
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
832 // "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
|
833 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
|
834 { |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
835 --p; |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
836 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
|
837 } |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
838 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
|
839 { |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
840 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
841 char_u *tp = skipwhite(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
|
842 |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
843 // parse the type after the name |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
844 lp->ll_type = parse_type(&tp, &si->sn_type_list); |
f303d6a01a3e
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Bram Moolenaar <Bram@vim.org>
parents:
21656
diff
changeset
|
845 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
|
846 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
847 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
848 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
849 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
850 // Without [idx] or .key we are done. |
110 | 851 if ((*p != '[' && *p != '.') || lp->ll_name == NULL) |
852 return p; | |
853 | |
854 cc = *p; | |
855 *p = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
856 // Only pass &ht when we would write to the variable, it prevents autoload |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
857 // as well. |
13002
f7b2ecaeb79c
patch 8.0.1377: cannot call a dict function in autoloaded dict
Christian Brabandt <cb@256bit.org>
parents:
12728
diff
changeset
|
858 v = find_var(lp->ll_name, (flags & GLV_READ_ONLY) ? NULL : &ht, |
f7b2ecaeb79c
patch 8.0.1377: cannot call a dict function in autoloaded dict
Christian Brabandt <cb@256bit.org>
parents:
12728
diff
changeset
|
859 flags & GLV_NO_AUTOLOAD); |
110 | 860 if (v == NULL && !quiet) |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21775
diff
changeset
|
861 semsg(_(e_undefined_variable_str), lp->ll_name); |
110 | 862 *p = cc; |
71 | 863 if (v == NULL) |
864 return NULL; | |
865 | |
110 | 866 /* |
867 * Loop until no more [idx] or .key is following. | |
868 */ | |
137 | 869 lp->ll_tv = &v->di_tv; |
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
|
870 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
|
871 var2.v_type = VAR_UNKNOWN; |
110 | 872 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) |
873 { | |
874 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) | |
875 && !(lp->ll_tv->v_type == VAR_DICT | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
876 && lp->ll_tv->vval.v_dict != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
877 && !(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
|
878 && lp->ll_tv->vval.v_blob != NULL)) |
110 | 879 { |
880 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
881 emsg(_("E689: Can only index a List, Dictionary or Blob")); |
110 | 882 return NULL; |
883 } | |
884 if (lp->ll_range) | |
885 { | |
886 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
887 emsg(_("E708: [:] must come last")); |
110 | 888 return NULL; |
71 | 889 } |
88 | 890 |
100 | 891 len = -1; |
892 if (*p == '.') | |
893 { | |
894 key = p + 1; | |
895 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
896 ; | |
897 if (len == 0) | |
898 { | |
110 | 899 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
900 emsg(_(e_emptykey)); |
110 | 901 return NULL; |
88 | 902 } |
100 | 903 p = key + len; |
904 } | |
905 else | |
906 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
907 // Get the index [expr] or the first index [expr: ]. |
88 | 908 p = skipwhite(p + 1); |
100 | 909 if (*p == ':') |
910 empty1 = TRUE; | |
88 | 911 else |
912 { | |
100 | 913 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
|
914 if (eval1(&p, &var1, &EVALARG_EVALUATE) == FAIL) // recursive! |
110 | 915 return NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
916 if (tv_get_string_chk(&var1) == NULL) |
323 | 917 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
918 // not a number or string |
323 | 919 clear_tv(&var1); |
920 return NULL; | |
921 } | |
21622
1f2066e3975a
patch 8.2.1361: error for white space after expression in assignment
Bram Moolenaar <Bram@vim.org>
parents:
21620
diff
changeset
|
922 p = skipwhite(p); |
100 | 923 } |
924 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
925 // Optionally get the second index [ :expr]. |
100 | 926 if (*p == ':') |
927 { | |
110 | 928 if (lp->ll_tv->v_type == VAR_DICT) |
929 { | |
930 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
|
931 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
|
932 clear_tv(&var1); |
110 | 933 return NULL; |
934 } | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
935 if (rettv != NULL |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
936 && !(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
|
937 && rettv->vval.v_list != NULL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
938 && !(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
|
939 && rettv->vval.v_blob != NULL)) |
110 | 940 { |
941 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
942 emsg(_("E709: [:] requires a 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
|
943 clear_tv(&var1); |
110 | 944 return NULL; |
88 | 945 } |
100 | 946 p = skipwhite(p + 1); |
947 if (*p == ']') | |
110 | 948 lp->ll_empty2 = TRUE; |
100 | 949 else |
950 { | |
110 | 951 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
|
952 // 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
|
953 if (eval1(&p, &var2, &EVALARG_EVALUATE) == FAIL) |
100 | 954 { |
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
|
955 clear_tv(&var1); |
110 | 956 return NULL; |
100 | 957 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
958 if (tv_get_string_chk(&var2) == NULL) |
323 | 959 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
960 // 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
|
961 clear_tv(&var1); |
323 | 962 clear_tv(&var2); |
963 return NULL; | |
964 } | |
100 | 965 } |
110 | 966 lp->ll_range = TRUE; |
100 | 967 } |
968 else | |
110 | 969 lp->ll_range = FALSE; |
100 | 970 |
971 if (*p != ']') | |
972 { | |
110 | 973 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
974 emsg(_(e_missbrac)); |
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
|
975 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
|
976 clear_tv(&var2); |
110 | 977 return NULL; |
100 | 978 } |
979 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
980 // Skip to past ']'. |
100 | 981 ++p; |
982 } | |
983 | |
110 | 984 if (lp->ll_tv->v_type == VAR_DICT) |
100 | 985 { |
986 if (len == -1) | |
987 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
988 // "[key]": get key from "var1" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
989 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
|
990 if (key == NULL) |
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
991 { |
100 | 992 clear_tv(&var1); |
110 | 993 return NULL; |
994 } | |
995 } | |
117 | 996 lp->ll_list = NULL; |
997 lp->ll_dict = lp->ll_tv->vval.v_dict; | |
121 | 998 lp->ll_di = dict_find(lp->ll_dict, key, len); |
2739 | 999 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1000 // 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
|
1001 // 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
|
1002 // g: dictionary). Disallow overwriting a builtin function. |
3687 | 1003 if (rettv != NULL && lp->ll_dict->dv_scope != 0) |
1004 { | |
1005 int prevval; | |
1006 int wrong; | |
1007 | |
1008 if (len != -1) | |
1009 { | |
1010 prevval = key[len]; | |
1011 key[len] = NUL; | |
1012 } | |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1013 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1014 prevval = 0; // avoid compiler warning |
3687 | 1015 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE |
1016 && 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
|
1017 && var_wrong_func_name(key, lp->ll_di == NULL)) |
3687 | 1018 || !valid_varname(key); |
1019 if (len != -1) | |
1020 key[len] = prevval; | |
1021 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
|
1022 { |
0b35a7ffceb2
patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents:
20126
diff
changeset
|
1023 clear_tv(&var1); |
2739 | 1024 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
|
1025 } |
2739 | 1026 } |
1027 | |
110 | 1028 if (lp->ll_di == NULL) |
100 | 1029 { |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
1030 // 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
|
1031 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
|
1032 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht()) |
2739 | 1033 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1034 semsg(_(e_illvar), name); |
16013
93b08b92a049
patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents:
15969
diff
changeset
|
1035 clear_tv(&var1); |
2739 | 1036 return NULL; |
1037 } | |
1038 | |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
1039 // Key does not exist in dict: may need to add it. |
110 | 1040 if (*p == '[' || *p == '.' || unlet) |
1041 { | |
1042 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1043 semsg(_(e_dictkey), 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
|
1044 clear_tv(&var1); |
110 | 1045 return NULL; |
100 | 1046 } |
1047 if (len == -1) | |
110 | 1048 lp->ll_newkey = vim_strsave(key); |
100 | 1049 else |
110 | 1050 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
|
1051 clear_tv(&var1); |
110 | 1052 if (lp->ll_newkey == NULL) |
100 | 1053 p = NULL; |
1054 break; | |
1055 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1056 // 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
|
1057 else if ((flags & GLV_READ_ONLY) == 0 |
fd1760f8c215
patch 8.0.0345: islocked('d.changedtick') does not work
Christian Brabandt <cb@256bit.org>
parents:
10910
diff
changeset
|
1058 && var_check_ro(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
|
1059 { |
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
1060 clear_tv(&var1); |
2739 | 1061 return NULL; |
10910
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
1062 } |
2739 | 1063 |
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
|
1064 clear_tv(&var1); |
110 | 1065 lp->ll_tv = &lp->ll_di->di_tv; |
100 | 1066 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1067 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
|
1068 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1069 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
|
1070 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1071 /* |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1072 * 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
|
1073 */ |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1074 if (empty1) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1075 lp->ll_n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1076 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1077 // is number or string |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1078 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
|
1079 clear_tv(&var1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1080 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1081 if (lp->ll_n1 < 0 |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1082 || lp->ll_n1 > bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1083 || (lp->ll_range && lp->ll_n1 == bloblen)) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1084 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1085 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1086 semsg(_(e_blobidx), lp->ll_n1); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1087 clear_tv(&var2); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1088 return NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1089 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1090 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
|
1091 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1092 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
|
1093 clear_tv(&var2); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1094 if (lp->ll_n2 < 0 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1095 || lp->ll_n2 >= bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1096 || lp->ll_n2 < lp->ll_n1) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1097 { |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1098 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1099 semsg(_(e_blobidx), lp->ll_n2); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1100 return NULL; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1101 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1102 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1103 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
|
1104 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
|
1105 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1106 } |
100 | 1107 else |
1108 { | |
1109 /* | |
1110 * Get the number and item for the only or first index of the List. | |
1111 */ | |
1112 if (empty1) | |
110 | 1113 lp->ll_n1 = 0; |
100 | 1114 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1115 // 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
|
1116 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
|
1117 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
|
1118 |
117 | 1119 lp->ll_dict = NULL; |
110 | 1120 lp->ll_list = lp->ll_tv->vval.v_list; |
1121 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
1122 if (lp->ll_li == NULL) | |
1123 { | |
842 | 1124 if (lp->ll_n1 < 0) |
1125 { | |
1126 lp->ll_n1 = 0; | |
1127 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
1128 } | |
1129 } | |
1130 if (lp->ll_li == NULL) | |
1131 { | |
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
|
1132 clear_tv(&var2); |
2772 | 1133 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1134 semsg(_(e_listidx), lp->ll_n1); |
110 | 1135 return NULL; |
100 | 1136 } |
1137 | |
1138 /* | |
1139 * May need to find the item or absolute index for the second | |
1140 * index of a range. | |
110 | 1141 * When no index given: "lp->ll_empty2" is TRUE. |
1142 * Otherwise "lp->ll_n2" is set to the second index. | |
100 | 1143 */ |
110 | 1144 if (lp->ll_range && !lp->ll_empty2) |
1145 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1146 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
|
1147 // is number or string |
88 | 1148 clear_tv(&var2); |
110 | 1149 if (lp->ll_n2 < 0) |
1150 { | |
1151 ni = list_find(lp->ll_list, lp->ll_n2); | |
100 | 1152 if (ni == NULL) |
2772 | 1153 { |
1154 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1155 semsg(_(e_listidx), lp->ll_n2); |
110 | 1156 return NULL; |
2772 | 1157 } |
110 | 1158 lp->ll_n2 = list_idx_of_item(lp->ll_list, ni); |
1159 } | |
1160 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1161 // Check that lp->ll_n2 isn't before lp->ll_n1. |
110 | 1162 if (lp->ll_n1 < 0) |
1163 lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li); | |
1164 if (lp->ll_n2 < lp->ll_n1) | |
2772 | 1165 { |
1166 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1167 semsg(_(e_listidx), lp->ll_n2); |
110 | 1168 return NULL; |
2772 | 1169 } |
110 | 1170 } |
1171 | |
1172 lp->ll_tv = &lp->ll_li->li_tv; | |
1173 } | |
1174 } | |
1175 | |
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
|
1176 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
|
1177 lp->ll_name_end = p; |
110 | 1178 return p; |
1179 } | |
1180 | |
1181 /* | |
137 | 1182 * Clear lval "lp" that was filled by get_lval(). |
110 | 1183 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1184 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1185 clear_lval(lval_T *lp) |
110 | 1186 { |
1187 vim_free(lp->ll_exp_name); | |
1188 vim_free(lp->ll_newkey); | |
1189 } | |
1190 | |
1191 /* | |
151 | 1192 * Set a variable that was parsed by get_lval() to "rettv". |
110 | 1193 * "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
|
1194 * "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
|
1195 * "%" for "%=", "." for ".=" or "=" for "=". |
117 | 1196 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
1197 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1198 set_var_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1199 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1200 char_u *endp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1201 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1202 int copy, |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22246
diff
changeset
|
1203 int flags, // LET_IS_CONST, LET_FORCEIT, LET_NO_COMMAND |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1204 char_u *op) |
110 | 1205 { |
1206 int cc; | |
137 | 1207 listitem_T *ri; |
1208 dictitem_T *di; | |
110 | 1209 |
1210 if (lp->ll_tv == NULL) | |
1211 { | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1212 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
|
1213 *endp = NUL; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1214 if (lp->ll_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1215 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1216 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
|
1217 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1218 if (op != NULL && *op != '=') |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1219 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1220 semsg(_(e_letwrong), op); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1221 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1222 } |
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
|
1223 if (var_check_lock(lp->ll_blob->bv_lock, lp->ll_name, FALSE)) |
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
|
1224 return; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1225 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1226 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
|
1227 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1228 int il, ir; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1229 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1230 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1231 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
|
1232 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1233 if (lp->ll_n2 - lp->ll_n1 + 1 != blob_len(rettv->vval.v_blob)) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1234 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1235 emsg(_("E972: Blob value does not have the right number of bytes")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1236 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1237 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1238 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1239 lp->ll_n2 = blob_len(lp->ll_blob); |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1240 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1241 ir = 0; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1242 for (il = lp->ll_n1; il <= lp->ll_n2; il++) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1243 blob_set(lp->ll_blob, il, |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1244 blob_get(rettv->vval.v_blob, ir++)); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1245 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1246 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1247 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1248 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
|
1249 if (!error) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1250 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1251 garray_T *gap = &lp->ll_blob->bv_ga; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1252 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1253 // Allow for appending a byte. Setting a byte beyond |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1254 // the end is an error otherwise. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1255 if (lp->ll_n1 < gap->ga_len |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1256 || (lp->ll_n1 == gap->ga_len |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1257 && ga_grow(&lp->ll_blob->bv_ga, 1) == OK)) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1258 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1259 blob_set(lp->ll_blob, lp->ll_n1, val); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1260 if (lp->ll_n1 == gap->ga_len) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1261 ++gap->ga_len; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1262 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1263 // error for invalid range was already given in get_lval() |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1264 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1265 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1266 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1267 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
|
1268 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1269 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
|
1270 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1271 if (flags & LET_IS_CONST) |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1272 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1273 emsg(_(e_cannot_mod)); |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1274 *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
|
1275 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1276 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1277 |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1278 // 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
|
1279 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
|
1280 if (eval_variable(lp->ll_name, (int)STRLEN(lp->ll_name), |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1281 &tv, &di, TRUE, FALSE) == OK) |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1282 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1283 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
|
1284 || (!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
|
1285 && !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
|
1286 && tv_op(&tv, rettv, op) == OK) |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1287 set_var(lp->ll_name, &tv, FALSE); |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1288 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
|
1289 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1290 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1291 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
|
1292 { |
66386ca8a69f
patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
1293 if (lp->ll_type != NULL |
22004
a9e60176dcd3
patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents:
21965
diff
changeset
|
1294 && check_typval_type(lp->ll_type, rettv, 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
|
1295 return; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1296 set_var_const(lp->ll_name, lp->ll_type, rettv, copy, flags); |
21443
66386ca8a69f
patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
1297 } |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1298 *endp = cc; |
110 | 1299 } |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1300 else if (var_check_lock(lp->ll_newkey == NULL |
151 | 1301 ? lp->ll_tv->v_lock |
6773 | 1302 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE)) |
151 | 1303 ; |
110 | 1304 else if (lp->ll_range) |
1305 { | |
6166 | 1306 listitem_T *ll_li = lp->ll_li; |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1307 int ll_n1 = lp->ll_n1; |
6166 | 1308 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1309 if (flags & LET_IS_CONST) |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1310 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1311 emsg(_("E996: Cannot lock a range")); |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1312 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1313 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1314 |
6166 | 1315 /* |
1316 * Check whether any of the list items is locked | |
1317 */ | |
6422 | 1318 for (ri = rettv->vval.v_list->lv_first; ri != NULL && ll_li != NULL; ) |
6166 | 1319 { |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1320 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE)) |
6166 | 1321 return; |
1322 ri = ri->li_next; | |
1323 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == ll_n1)) | |
1324 break; | |
1325 ll_li = ll_li->li_next; | |
1326 ++ll_n1; | |
1327 } | |
1328 | |
110 | 1329 /* |
1330 * Assign the List values to the list items. | |
1331 */ | |
1332 for (ri = rettv->vval.v_list->lv_first; ri != NULL; ) | |
1333 { | |
117 | 1334 if (op != NULL && *op != '=') |
1335 tv_op(&lp->ll_li->li_tv, &ri->li_tv, op); | |
1336 else | |
1337 { | |
1338 clear_tv(&lp->ll_li->li_tv); | |
1339 copy_tv(&ri->li_tv, &lp->ll_li->li_tv); | |
1340 } | |
110 | 1341 ri = ri->li_next; |
1342 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1)) | |
1343 break; | |
1344 if (lp->ll_li->li_next == NULL) | |
1345 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1346 // Need to add an empty item. |
533 | 1347 if (list_append_number(lp->ll_list, 0) == FAIL) |
110 | 1348 { |
1349 ri = NULL; | |
88 | 1350 break; |
110 | 1351 } |
1352 } | |
1353 lp->ll_li = lp->ll_li->li_next; | |
1354 ++lp->ll_n1; | |
1355 } | |
1356 if (ri != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1357 emsg(_("E710: List value has more items than target")); |
117 | 1358 else if (lp->ll_empty2 |
1359 ? (lp->ll_li != NULL && lp->ll_li->li_next != NULL) | |
110 | 1360 : lp->ll_n1 != lp->ll_n2) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1361 emsg(_("E711: List value has not enough items")); |
110 | 1362 } |
1363 else | |
1364 { | |
1365 /* | |
1366 * Assign to a List or Dictionary item. | |
1367 */ | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1368 if (flags & LET_IS_CONST) |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1369 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1370 emsg(_("E996: Cannot lock a list or dict")); |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1371 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1372 } |
110 | 1373 if (lp->ll_newkey != NULL) |
1374 { | |
117 | 1375 if (op != NULL && *op != '=') |
1376 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1377 semsg(_(e_letwrong), op); |
117 | 1378 return; |
1379 } | |
1380 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1381 // Need to add an item to the Dictionary. |
121 | 1382 di = dictitem_alloc(lp->ll_newkey); |
110 | 1383 if (di == NULL) |
1384 return; | |
121 | 1385 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL) |
1386 { | |
1387 vim_free(di); | |
1388 return; | |
1389 } | |
110 | 1390 lp->ll_tv = &di->di_tv; |
1391 } | |
117 | 1392 else if (op != NULL && *op != '=') |
1393 { | |
1394 tv_op(lp->ll_tv, rettv, op); | |
1395 return; | |
1396 } | |
110 | 1397 else |
1398 clear_tv(lp->ll_tv); | |
1399 | |
1400 /* | |
1401 * Assign the value to the variable or list item. | |
1402 */ | |
1403 if (copy) | |
1404 copy_tv(rettv, lp->ll_tv); | |
1405 else | |
1406 { | |
1407 *lp->ll_tv = *rettv; | |
156 | 1408 lp->ll_tv->v_lock = 0; |
110 | 1409 init_tv(rettv); |
1410 } | |
1411 } | |
7 | 1412 } |
1413 | |
76 | 1414 /* |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1415 * 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
|
1416 * and "tv1 .= tv2" |
117 | 1417 * Returns OK or FAIL. |
1418 */ | |
1419 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1420 tv_op(typval_T *tv1, typval_T *tv2, char_u *op) |
117 | 1421 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1422 varnumber_T n; |
117 | 1423 char_u numbuf[NUMBUFLEN]; |
1424 char_u *s; | |
1425 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1426 // Can't do anything with a Funcref, Dict, v:true on the right. |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1427 if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
1428 && tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL) |
117 | 1429 { |
1430 switch (tv1->v_type) | |
1431 { | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1432 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
|
1433 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
|
1434 case VAR_VOID: |
117 | 1435 case VAR_DICT: |
1436 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1437 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
|
1438 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1439 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1440 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
1441 case VAR_CHANNEL: |
117 | 1442 break; |
1443 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1444 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1445 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
|
1446 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1447 // BLOB += BLOB |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1448 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
|
1449 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1450 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
|
1451 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
|
1452 int i, len = blob_len(b2); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1453 for (i = 0; i < len; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1454 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
|
1455 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1456 return OK; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1457 |
117 | 1458 case VAR_LIST: |
1459 if (*op != '+' || tv2->v_type != VAR_LIST) | |
1460 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1461 // List += List |
117 | 1462 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL) |
1463 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL); | |
1464 return OK; | |
1465 | |
1466 case VAR_NUMBER: | |
1467 case VAR_STRING: | |
1468 if (tv2->v_type == VAR_LIST) | |
1469 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1470 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
|
1471 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1472 // 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
|
1473 n = tv_get_number(tv1); |
1624 | 1474 #ifdef FEAT_FLOAT |
1475 if (tv2->v_type == VAR_FLOAT) | |
1476 { | |
1477 float_T f = n; | |
1478 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1479 if (*op == '%') |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1480 break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1481 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1482 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1483 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
|
1484 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
|
1485 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
|
1486 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
|
1487 } |
1624 | 1488 clear_tv(tv1); |
1489 tv1->v_type = VAR_FLOAT; | |
1490 tv1->vval.v_float = f; | |
1491 } | |
117 | 1492 else |
1624 | 1493 #endif |
1494 { | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1495 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1496 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1497 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
|
1498 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
|
1499 case '*': n *= tv_get_number(tv2); break; |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
1500 case '/': n = num_divide(n, tv_get_number(tv2)); break; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
1501 case '%': n = num_modulus(n, tv_get_number(tv2)); break; |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1502 } |
1624 | 1503 clear_tv(tv1); |
1504 tv1->v_type = VAR_NUMBER; | |
1505 tv1->vval.v_number = n; | |
1506 } | |
1507 } | |
1508 else | |
1509 { | |
1510 if (tv2->v_type == VAR_FLOAT) | |
1511 break; | |
1512 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1513 // str .= str |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1514 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
|
1515 s = concat_str(s, tv_get_string_buf(tv2, numbuf)); |
117 | 1516 clear_tv(tv1); |
1517 tv1->v_type = VAR_STRING; | |
1518 tv1->vval.v_string = s; | |
1519 } | |
1520 return OK; | |
1624 | 1521 |
1522 case VAR_FLOAT: | |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1523 #ifdef FEAT_FLOAT |
1624 | 1524 { |
1525 float_T f; | |
1526 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1527 if (*op == '%' || *op == '.' |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1528 || (tv2->v_type != VAR_FLOAT |
1624 | 1529 && tv2->v_type != VAR_NUMBER |
1530 && tv2->v_type != VAR_STRING)) | |
1531 break; | |
1532 if (tv2->v_type == VAR_FLOAT) | |
1533 f = tv2->vval.v_float; | |
1534 else | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1535 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
|
1536 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1537 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1538 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
|
1539 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
|
1540 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
|
1541 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
|
1542 } |
1624 | 1543 } |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1544 #endif |
1624 | 1545 return OK; |
117 | 1546 } |
1547 } | |
1548 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1549 semsg(_(e_letwrong), op); |
117 | 1550 return FAIL; |
1551 } | |
1552 | |
1553 /* | |
76 | 1554 * Evaluate the expression used in a ":for var in expr" command. |
1555 * "arg" points to "var". | |
1556 * Set "*errp" to TRUE for an error, FALSE otherwise; | |
1557 * Return a pointer that holds the info. Null when there is an error. | |
1558 */ | |
1559 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1560 eval_for_line( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1561 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1562 int *errp, |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1563 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
|
1564 evalarg_T *evalarg) |
76 | 1565 { |
137 | 1566 forinfo_T *fi; |
76 | 1567 char_u *expr; |
137 | 1568 typval_T tv; |
1569 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
|
1570 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
|
1571 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1572 *errp = TRUE; // default: there is an error |
76 | 1573 |
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
|
1574 fi = ALLOC_CLEAR_ONE(forinfo_T); |
76 | 1575 if (fi == NULL) |
1576 return NULL; | |
1577 | |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
1578 expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon, FALSE); |
76 | 1579 if (expr == NULL) |
1580 return fi; | |
1581 | |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1582 expr = skipwhite_and_linebreak(expr, evalarg); |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1583 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
|
1584 || !(expr[2] == NUL || VIM_ISWHITE(expr[2]))) |
76 | 1585 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1586 emsg(_(e_missing_in)); |
76 | 1587 return fi; |
1588 } | |
1589 | |
1590 if (skip) | |
1591 ++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
|
1592 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
|
1593 if (eval0(expr, &tv, eap, evalarg) == OK) |
76 | 1594 { |
1595 *errp = FALSE; | |
1596 if (!skip) | |
1597 { | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1598 if (tv.v_type == VAR_LIST) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1599 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1600 l = tv.vval.v_list; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1601 if (l == NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1602 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1603 // 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
|
1604 clear_tv(&tv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1605 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1606 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1607 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1608 // 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
|
1609 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
|
1610 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1611 // 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
|
1612 // the list being used in "tv". |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1613 fi->fi_list = l; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1614 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
|
1615 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
|
1616 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1617 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1618 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
|
1619 { |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1620 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
|
1621 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
|
1622 { |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1623 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
|
1624 |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1625 // 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
|
1626 // 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
|
1627 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
|
1628 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
|
1629 } |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1630 clear_tv(&tv); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1631 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1632 else |
359 | 1633 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1634 emsg(_(e_listreq)); |
359 | 1635 clear_tv(&tv); |
1636 } | |
76 | 1637 } |
1638 } | |
1639 if (skip) | |
1640 --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
|
1641 fi->fi_break_count = evalarg->eval_break_count; |
76 | 1642 |
1643 return fi; | |
1644 } | |
1645 | |
1646 /* | |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1647 * 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
|
1648 */ |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1649 void |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1650 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
|
1651 { |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1652 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
|
1653 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
|
1654 |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1655 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
|
1656 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
|
1657 } |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1658 |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1659 /* |
76 | 1660 * Use the first item in a ":for" list. Advance to the next. |
1661 * Assign the values to the variable (list). "arg" points to the first one. | |
1662 * Return TRUE when a valid item was found, FALSE when at end of list or | |
1663 * something wrong. | |
1664 */ | |
1665 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1666 next_for_item(void *fi_void, char_u *arg) |
76 | 1667 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
1668 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1669 int result; |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21277
diff
changeset
|
1670 int flag = in_vim9script() ? LET_NO_COMMAND : 0; |
137 | 1671 listitem_T *item; |
76 | 1672 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1673 if (fi->fi_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1674 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1675 typval_T tv; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1676 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1677 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
|
1678 return FALSE; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1679 tv.v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1680 tv.v_lock = VAR_FIXED; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1681 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
|
1682 ++fi->fi_bi; |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1683 return ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon, |
19568
c0749ad6c699
patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
1684 fi->fi_varcount, flag, NULL) == OK; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1685 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1686 |
76 | 1687 item = fi->fi_lw.lw_item; |
1688 if (item == NULL) | |
1689 result = FALSE; | |
1690 else | |
1691 { | |
1692 fi->fi_lw.lw_item = item->li_next; | |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1693 result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon, |
19568
c0749ad6c699
patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
1694 fi->fi_varcount, flag, NULL) == OK); |
76 | 1695 } |
1696 return result; | |
1697 } | |
1698 | |
1699 /* | |
1700 * Free the structure used to store info used by ":for". | |
1701 */ | |
1702 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1703 free_for_info(void *fi_void) |
76 | 1704 { |
137 | 1705 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1706 |
92 | 1707 if (fi != NULL && fi->fi_list != NULL) |
359 | 1708 { |
76 | 1709 list_rem_watch(fi->fi_list, &fi->fi_lw); |
359 | 1710 list_unref(fi->fi_list); |
1711 } | |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
1712 if (fi != NULL && fi->fi_blob != NULL) |
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
1713 blob_unref(fi->fi_blob); |
76 | 1714 vim_free(fi); |
1715 } | |
1716 | |
7 | 1717 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1718 set_context_for_expression( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1719 expand_T *xp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1720 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1721 cmdidx_T cmdidx) |
7 | 1722 { |
1723 int got_eq = FALSE; | |
1724 int c; | |
76 | 1725 char_u *p; |
1726 | |
18713
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1727 if (cmdidx == CMD_let || cmdidx == CMD_const) |
76 | 1728 { |
1729 xp->xp_context = EXPAND_USER_VARS; | |
159 | 1730 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) |
76 | 1731 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1732 // ":let var1 var2 ...": find last space. |
159 | 1733 for (p = arg + STRLEN(arg); p >= arg; ) |
76 | 1734 { |
1735 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
|
1736 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
|
1737 if (VIM_ISWHITE(*p)) |
76 | 1738 break; |
1739 } | |
1740 return; | |
1741 } | |
1742 } | |
1743 else | |
1744 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS | |
1745 : EXPAND_EXPRESSION; | |
7 | 1746 while ((xp->xp_pattern = vim_strpbrk(arg, |
1747 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) | |
1748 { | |
1749 c = *xp->xp_pattern; | |
1750 if (c == '&') | |
1751 { | |
1752 c = xp->xp_pattern[1]; | |
1753 if (c == '&') | |
1754 { | |
1755 ++xp->xp_pattern; | |
1756 xp->xp_context = cmdidx != CMD_let || got_eq | |
1757 ? EXPAND_EXPRESSION : EXPAND_NOTHING; | |
1758 } | |
1759 else if (c != ' ') | |
201 | 1760 { |
7 | 1761 xp->xp_context = EXPAND_SETTINGS; |
201 | 1762 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') |
1763 xp->xp_pattern += 2; | |
1764 | |
1765 } | |
7 | 1766 } |
1767 else if (c == '$') | |
1768 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1769 // environment variable |
7 | 1770 xp->xp_context = EXPAND_ENV_VARS; |
1771 } | |
1772 else if (c == '=') | |
1773 { | |
1774 got_eq = TRUE; | |
1775 xp->xp_context = EXPAND_EXPRESSION; | |
1776 } | |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1777 else if (c == '#' |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1778 && xp->xp_context == EXPAND_EXPRESSION) |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1779 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1780 // Autoload function/variable contains '#'. |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1781 break; |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1782 } |
6367 | 1783 else if ((c == '<' || c == '#') |
7 | 1784 && xp->xp_context == EXPAND_FUNCTIONS |
1785 && vim_strchr(xp->xp_pattern, '(') == NULL) | |
1786 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1787 // Function name can start with "<SNR>" and contain '#'. |
7 | 1788 break; |
1789 } | |
1790 else if (cmdidx != CMD_let || got_eq) | |
1791 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1792 if (c == '"') // string |
7 | 1793 { |
1794 while ((c = *++xp->xp_pattern) != NUL && c != '"') | |
1795 if (c == '\\' && xp->xp_pattern[1] != NUL) | |
1796 ++xp->xp_pattern; | |
1797 xp->xp_context = EXPAND_NOTHING; | |
1798 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1799 else if (c == '\'') // literal string |
7 | 1800 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1801 // Trick: '' is like stopping and starting a literal string. |
7 | 1802 while ((c = *++xp->xp_pattern) != NUL && c != '\'') |
1803 /* skip */ ; | |
1804 xp->xp_context = EXPAND_NOTHING; | |
1805 } | |
1806 else if (c == '|') | |
1807 { | |
1808 if (xp->xp_pattern[1] == '|') | |
1809 { | |
1810 ++xp->xp_pattern; | |
1811 xp->xp_context = EXPAND_EXPRESSION; | |
1812 } | |
1813 else | |
1814 xp->xp_context = EXPAND_COMMANDS; | |
1815 } | |
1816 else | |
1817 xp->xp_context = EXPAND_EXPRESSION; | |
1818 } | |
1819 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1820 // 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
|
1821 // anyway. |
76 | 1822 xp->xp_context = EXPAND_EXPRESSION; |
7 | 1823 arg = xp->xp_pattern; |
1824 if (*arg != NUL) | |
1825 while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) | |
1826 /* skip */ ; | |
1827 } | |
1828 xp->xp_pattern = arg; | |
1829 } | |
1830 | |
1831 /* | |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1832 * Return TRUE if "pat" matches "text". |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1833 * 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
|
1834 */ |
17377
cb008de2a6ec
patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17375
diff
changeset
|
1835 int |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1836 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
|
1837 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1838 int matches = FALSE; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1839 char_u *save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1840 regmatch_T regmatch; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1841 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1842 // avoid 'l' flag in 'cpoptions' |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1843 save_cpo = p_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1844 p_cpo = (char_u *)""; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1845 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
|
1846 if (regmatch.regprog != NULL) |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1847 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1848 regmatch.rm_ic = ic; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1849 matches = vim_regexec_nl(®match, text, (colnr_T)0); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1850 vim_regfree(regmatch.regprog); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1851 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1852 p_cpo = save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1853 return matches; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1854 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1855 |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1856 /* |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1857 * 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
|
1858 * "expr->name(arg)". |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1859 * Returns OK or FAIL. |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1860 */ |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1861 static int |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1862 eval_func( |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1863 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
|
1864 evalarg_T *evalarg, |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1865 char_u *name, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1866 int name_len, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1867 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
|
1868 int flags, |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1869 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
|
1870 { |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1871 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
|
1872 char_u *s = name; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1873 int len = name_len; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1874 partial_T *partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1875 int ret = OK; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1876 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1877 if (!evaluate) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1878 check_vars(s, len); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1879 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1880 // 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
|
1881 // use its contents. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1882 s = deref_func_name(s, &len, &partial, !evaluate); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1883 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1884 // 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
|
1885 // the name invalid. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1886 s = vim_strsave(s); |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1887 if (s == NULL || (flags & EVAL_CONSTANT)) |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1888 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1889 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1890 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1891 funcexe_T funcexe; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1892 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1893 // Invoke the function. |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1894 CLEAR_FIELD(funcexe); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1895 funcexe.firstline = curwin->w_cursor.lnum; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1896 funcexe.lastline = curwin->w_cursor.lnum; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1897 funcexe.evaluate = evaluate; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1898 funcexe.partial = partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1899 funcexe.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
|
1900 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
|
1901 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1902 vim_free(s); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1903 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1904 // 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
|
1905 // 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
|
1906 // 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
|
1907 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
|
1908 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1909 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
|
1910 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
|
1911 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1912 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1913 // 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
|
1914 // 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
|
1915 // 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
|
1916 if (evaluate && aborting()) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1917 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1918 if (ret == OK) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1919 clear_tv(rettv); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1920 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1921 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1922 return ret; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1923 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1924 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1925 /* |
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
|
1926 * 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
|
1927 * 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
|
1928 * and set "getnext". |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1929 * Otherwise just return "arg" unmodified and set "getnext" to FALSE. |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1930 * "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
|
1931 */ |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21026
diff
changeset
|
1932 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
|
1933 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
|
1934 { |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1935 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
|
1936 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1937 *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
|
1938 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
|
1939 && evalarg != NULL |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1940 && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL) |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1941 && (*p == NUL || (VIM_ISWHITE(p[-1]) && vim9_comment_start(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
|
1942 { |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1943 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
|
1944 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1945 if (evalarg->eval_cookie != NULL) |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1946 next = getline_peek(evalarg->eval_getline, evalarg->eval_cookie); |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1947 else |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1948 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
|
1949 |
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1950 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
|
1951 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1952 *getnext = TRUE; |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1953 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
|
1954 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1955 } |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1956 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
|
1957 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1958 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1959 /* |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1960 * To be called after eval_next_non_blank() sets "getnext" to TRUE. |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1961 */ |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21026
diff
changeset
|
1962 char_u * |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1963 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
|
1964 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1965 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
|
1966 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
|
1967 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1968 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
|
1969 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
|
1970 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
|
1971 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1972 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
|
1973 ++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
|
1974 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
|
1975 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1976 // Going to concatenate the lines after parsing. |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1977 ((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
|
1978 ++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
|
1979 } |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
1980 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
|
1981 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1982 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
|
1983 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
|
1984 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1985 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
|
1986 } |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1987 |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
1988 /* |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
1989 * 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
|
1990 */ |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1991 char_u * |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1992 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
|
1993 { |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1994 int getnext; |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1995 char_u *p = skipwhite(arg); |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1996 |
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
|
1997 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
|
1998 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
|
1999 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
|
2000 if (getnext) |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2001 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
|
2002 return p; |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2003 } |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2004 |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2005 /* |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2006 * 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
|
2007 */ |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
2008 void |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
2009 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
|
2010 { |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2011 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
|
2012 { |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2013 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
|
2014 { |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2015 if (eap != NULL) |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2016 { |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2017 // 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
|
2018 // ":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
|
2019 // 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
|
2020 vim_free(eap->cmdline_tofree); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2021 eap->cmdline_tofree = *eap->cmdlinep; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2022 *eap->cmdlinep = evalarg->eval_tofree; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2023 } |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2024 else |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2025 vim_free(evalarg->eval_tofree); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2026 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
|
2027 } |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2028 |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2029 vim_free(evalarg->eval_tofree_lambda); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
2030 evalarg->eval_tofree_lambda = NULL; |
21050
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
2031 } |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
2032 } |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
2033 |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
2034 /* |
7 | 2035 * The "evaluate" argument: When FALSE, the argument is only parsed but not |
71 | 2036 * executed. The function may return OK, but the rettv will be of type |
7 | 2037 * VAR_UNKNOWN. The function still returns FAIL for a syntax error. |
2038 */ | |
2039 | |
2040 /* | |
2041 * Handle zero level expression. | |
2042 * This calls eval1() and handles error message and nextcmd. | |
71 | 2043 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. |
533 | 2044 * 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
|
2045 * "evalarg" can be NULL, EVALARG_EVALUATE or a pointer. |
7 | 2046 * Return OK or FAIL. |
2047 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
2048 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2049 eval0( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2050 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2051 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
|
2052 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
|
2053 evalarg_T *evalarg) |
7 | 2054 { |
2055 int ret; | |
2056 char_u *p; | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
2057 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
|
2058 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
|
2059 int flags = evalarg == NULL ? 0 : evalarg->eval_flags; |
7 | 2060 |
2061 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
|
2062 ret = eval1(&p, rettv, evalarg); |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2063 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
|
2064 |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2065 if (ret == FAIL || !ends_excmd2(arg, p)) |
7 | 2066 { |
2067 if (ret != FAIL) | |
71 | 2068 clear_tv(rettv); |
7 | 2069 /* |
2070 * Report the invalid expression unless the expression evaluation has | |
2071 * 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
|
2072 * 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
|
2073 * Also check called_emsg for when using assert_fails(). |
7 | 2074 */ |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2075 if (!aborting() |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2076 && 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
|
2077 && called_emsg == called_emsg_before |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2078 && (flags & EVAL_CONSTANT) == 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
2079 semsg(_(e_invexpr2), arg); |
7 | 2080 ret = FAIL; |
2081 } | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2082 |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2083 if (eap != NULL) |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2084 eap->nextcmd = check_nextcmd(p); |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2085 |
7 | 2086 return ret; |
2087 } | |
2088 | |
2089 /* | |
2090 * Handle top level expression: | |
1800 | 2091 * expr2 ? expr1 : expr1 |
7 | 2092 * |
2093 * "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
|
2094 * "arg" is advanced to just after the recognized expression. |
7 | 2095 * |
533 | 2096 * Note: "rettv.v_lock" is not set. |
2097 * | |
7 | 2098 * Return OK or FAIL. |
2099 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
2100 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
|
2101 eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2102 { |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2103 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
|
2104 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
|
2105 |
22246
6f83d2adee74
patch 8.2.1672: v_lock is used when it is not initialized
Bram Moolenaar <Bram@vim.org>
parents:
22244
diff
changeset
|
2106 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
|
2107 |
7 | 2108 /* |
2109 * Get the first variable. | |
2110 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2111 if (eval2(arg, rettv, evalarg) == FAIL) |
7 | 2112 return FAIL; |
2113 | |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2114 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
|
2115 if (*p == '?') |
7 | 2116 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2117 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
|
2118 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
|
2119 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
|
2120 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
|
2121 int orig_flags; |
21002
4852db420162
patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2122 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
|
2123 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2124 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
|
2125 { |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2126 CLEAR_FIELD(local_evalarg); |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2127 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
|
2128 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2129 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
|
2130 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
|
2131 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2132 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
|
2133 *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
|
2134 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
|
2135 { |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2136 if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1])) |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2137 { |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2138 error_white_both(p, 1); |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2139 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
|
2140 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
|
2141 } |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2142 *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
|
2143 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2144 |
7 | 2145 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
|
2146 if (evaluate) |
7 | 2147 { |
323 | 2148 int error = FALSE; |
2149 | |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21828
diff
changeset
|
2150 if (in_vim9script()) |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21828
diff
changeset
|
2151 result = tv2bool(rettv); |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21828
diff
changeset
|
2152 else if (tv_get_number_chk(rettv, &error) != 0) |
7 | 2153 result = TRUE; |
71 | 2154 clear_tv(rettv); |
323 | 2155 if (error) |
2156 return FAIL; | |
7 | 2157 } |
2158 | |
2159 /* | |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2160 * Get the second variable. Recursive! |
7 | 2161 */ |
21644
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2162 if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1])) |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2163 { |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2164 error_white_both(p, 1); |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2165 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
|
2166 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
|
2167 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2168 *arg = skipwhite_and_linebreak(*arg + 1, 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
|
2169 evalarg_used->eval_flags = result ? orig_flags |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2170 : orig_flags & ~EVAL_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
|
2171 if (eval1(arg, rettv, evalarg_used) == FAIL) |
21925
51d591dbb8df
patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents:
21915
diff
changeset
|
2172 { |
51d591dbb8df
patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents:
21915
diff
changeset
|
2173 evalarg_used->eval_flags = orig_flags; |
7 | 2174 return FAIL; |
21925
51d591dbb8df
patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents:
21915
diff
changeset
|
2175 } |
7 | 2176 |
2177 /* | |
2178 * Check for the ":". | |
2179 */ | |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2180 p = eval_next_non_blank(*arg, evalarg_used, &getnext); |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2181 if (*p != ':') |
7 | 2182 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2183 emsg(_(e_missing_colon)); |
7 | 2184 if (evaluate && result) |
71 | 2185 clear_tv(rettv); |
21925
51d591dbb8df
patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents:
21915
diff
changeset
|
2186 evalarg_used->eval_flags = orig_flags; |
7 | 2187 return FAIL; |
2188 } | |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2189 if (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
|
2190 *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
|
2191 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
|
2192 { |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2193 if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1])) |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2194 { |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2195 error_white_both(p, 1); |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2196 clear_tv(rettv); |
21925
51d591dbb8df
patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents:
21915
diff
changeset
|
2197 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
|
2198 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
|
2199 } |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2200 *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
|
2201 } |
7 | 2202 |
2203 /* | |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2204 * Get the third variable. Recursive! |
7 | 2205 */ |
21644
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2206 if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1])) |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2207 { |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2208 error_white_both(p, 1); |
7d3ba70a03f1
patch 8.2.1372: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21642
diff
changeset
|
2209 clear_tv(rettv); |
21925
51d591dbb8df
patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents:
21915
diff
changeset
|
2210 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
|
2211 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
|
2212 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2213 *arg = skipwhite_and_linebreak(*arg + 1, 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
|
2214 evalarg_used->eval_flags = !result ? orig_flags |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2215 : orig_flags & ~EVAL_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
|
2216 if (eval1(arg, &var2, evalarg_used) == FAIL) |
7 | 2217 { |
2218 if (evaluate && result) | |
71 | 2219 clear_tv(rettv); |
21925
51d591dbb8df
patch 8.2.1512: failure after trinary expression fails
Bram Moolenaar <Bram@vim.org>
parents:
21915
diff
changeset
|
2220 evalarg_used->eval_flags = orig_flags; |
7 | 2221 return FAIL; |
2222 } | |
2223 if (evaluate && !result) | |
71 | 2224 *rettv = 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
|
2225 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2226 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
|
2227 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
|
2228 else |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2229 evalarg->eval_flags = orig_flags; |
7 | 2230 } |
2231 | |
2232 return OK; | |
2233 } | |
2234 | |
2235 /* | |
2236 * Handle first level expression: | |
2237 * expr2 || expr2 || expr2 logical OR | |
2238 * | |
2239 * "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
|
2240 * "arg" is advanced to just after the recognized expression. |
7 | 2241 * |
2242 * Return OK or FAIL. | |
2243 */ | |
2244 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
|
2245 eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2246 { |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2247 char_u *p; |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2248 int getnext; |
7 | 2249 |
2250 /* | |
2251 * Get the first variable. | |
2252 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2253 if (eval3(arg, rettv, evalarg) == FAIL) |
7 | 2254 return FAIL; |
2255 | |
2256 /* | |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2257 * Handle the "||" operator. |
7 | 2258 */ |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2259 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
|
2260 if (p[0] == '|' && p[1] == '|') |
7 | 2261 { |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2262 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
|
2263 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
|
2264 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
|
2265 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
|
2266 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
|
2267 typval_T var2; |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2268 int error; |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2269 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
|
2270 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2271 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
|
2272 { |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2273 CLEAR_FIELD(local_evalarg); |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2274 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
|
2275 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2276 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
|
2277 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
|
2278 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
|
2279 { |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2280 if (vim9script) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2281 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2282 result = tv2bool(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2283 } |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2284 else |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2285 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2286 error = FALSE; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2287 if (tv_get_number_chk(rettv, &error) != 0) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2288 result = TRUE; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2289 clear_tv(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2290 if (error) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2291 return FAIL; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2292 } |
7 | 2293 } |
2294 | |
2295 /* | |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2296 * Repeat until there is no following "||". |
7 | 2297 */ |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2298 while (p[0] == '|' && p[1] == '|') |
7 | 2299 { |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2300 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
|
2301 *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
|
2302 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
|
2303 { |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2304 if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1])) |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2305 { |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2306 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
|
2307 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
|
2308 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
|
2309 } |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2310 *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
|
2311 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2312 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2313 /* |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2314 * 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
|
2315 */ |
21642
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2316 if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2])) |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2317 { |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2318 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
|
2319 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
|
2320 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
|
2321 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2322 *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
|
2323 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
|
2324 : 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
|
2325 if (eval3(arg, &var2, evalarg_used) == FAIL) |
323 | 2326 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
|
2327 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2328 /* |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2329 * 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
|
2330 */ |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2331 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
|
2332 { |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2333 if (vim9script) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2334 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2335 clear_tv(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2336 *rettv = var2; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2337 result = tv2bool(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2338 } |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2339 else |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2340 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2341 if (tv_get_number_chk(&var2, &error) != 0) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2342 result = TRUE; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2343 clear_tv(&var2); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2344 if (error) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2345 return FAIL; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2346 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2347 } |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2348 if (evaluate && !vim9script) |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2349 { |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2350 rettv->v_type = VAR_NUMBER; |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2351 rettv->vval.v_number = result; |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2352 } |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2353 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2354 p = eval_next_non_blank(*arg, evalarg_used, &getnext); |
7 | 2355 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2356 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2357 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
|
2358 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
|
2359 else |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2360 evalarg->eval_flags = orig_flags; |
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
|
2361 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
2362 // Resulting value can be assigned to a bool. |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
2363 rettv->v_lock |= VAR_BOOL_OK; |
7 | 2364 } |
2365 | |
2366 return OK; | |
2367 } | |
2368 | |
2369 /* | |
2370 * Handle second level expression: | |
2371 * expr3 && expr3 && expr3 logical AND | |
2372 * | |
2373 * "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
|
2374 * "arg" is advanced to just after the recognized expression. |
7 | 2375 * |
2376 * Return OK or FAIL. | |
2377 */ | |
2378 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
|
2379 eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2380 { |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2381 char_u *p; |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2382 int getnext; |
7 | 2383 |
2384 /* | |
2385 * Get the first variable. | |
2386 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2387 if (eval4(arg, rettv, evalarg) == FAIL) |
7 | 2388 return FAIL; |
2389 | |
2390 /* | |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2391 * Handle the "&&" operator. |
7 | 2392 */ |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2393 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
|
2394 if (p[0] == '&' && p[1] == '&') |
7 | 2395 { |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2396 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
|
2397 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
|
2398 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
|
2399 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
|
2400 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
|
2401 typval_T var2; |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2402 int error; |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2403 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
|
2404 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2405 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
|
2406 { |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2407 CLEAR_FIELD(local_evalarg); |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2408 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
|
2409 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2410 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
|
2411 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
|
2412 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
|
2413 { |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2414 if (vim9script) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2415 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2416 result = tv2bool(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2417 } |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2418 else |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2419 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2420 error = FALSE; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2421 if (tv_get_number_chk(rettv, &error) == 0) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2422 result = FALSE; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2423 clear_tv(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2424 if (error) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2425 return FAIL; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2426 } |
7 | 2427 } |
2428 | |
2429 /* | |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2430 * Repeat until there is no following "&&". |
7 | 2431 */ |
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 while (p[0] == '&' && p[1] == '&') |
7 | 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 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
|
2435 *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
|
2436 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
|
2437 { |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2438 if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1])) |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2439 { |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2440 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
|
2441 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
|
2442 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
|
2443 } |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2444 *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
|
2445 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2446 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2447 /* |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2448 * 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
|
2449 */ |
21642
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2450 if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2])) |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2451 { |
5ae89c8633ae
patch 8.2.1371: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21636
diff
changeset
|
2452 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
|
2453 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
|
2454 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
|
2455 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2456 *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
|
2457 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
|
2458 : 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
|
2459 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
|
2460 if (eval4(arg, &var2, evalarg_used) == FAIL) |
323 | 2461 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
|
2462 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2463 /* |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2464 * 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
|
2465 */ |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2466 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
|
2467 { |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2468 if (vim9script) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2469 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2470 clear_tv(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2471 *rettv = var2; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2472 result = tv2bool(rettv); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2473 } |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2474 else |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2475 { |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2476 if (tv_get_number_chk(&var2, &error) == 0) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2477 result = FALSE; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2478 clear_tv(&var2); |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2479 if (error) |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2480 return FAIL; |
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2481 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2482 } |
21309
31a3f4d408b9
patch 8.2.1205: Vim9: && and || work different when not compiled
Bram Moolenaar <Bram@vim.org>
parents:
21307
diff
changeset
|
2483 if (evaluate && !vim9script) |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2484 { |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2485 rettv->v_type = VAR_NUMBER; |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2486 rettv->vval.v_number = result; |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2487 } |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2488 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2489 p = eval_next_non_blank(*arg, evalarg_used, &getnext); |
7 | 2490 } |
21277
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2491 |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2492 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
|
2493 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
|
2494 else |
1e5c29d4e5b3
patch 8.2.1189: Vim9: line continuation in lambda doesn't always work
Bram Moolenaar <Bram@vim.org>
parents:
21251
diff
changeset
|
2495 evalarg->eval_flags = orig_flags; |
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
|
2496 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
2497 // Resulting value can be assigned to a bool. |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
2498 rettv->v_lock |= VAR_BOOL_OK; |
7 | 2499 } |
2500 | |
2501 return OK; | |
2502 } | |
2503 | |
2504 /* | |
2505 * Handle third level expression: | |
2506 * var1 == var2 | |
2507 * var1 =~ var2 | |
2508 * var1 != var2 | |
2509 * var1 !~ var2 | |
2510 * var1 > var2 | |
2511 * var1 >= var2 | |
2512 * var1 < var2 | |
2513 * var1 <= var2 | |
80 | 2514 * var1 is var2 |
2515 * var1 isnot var2 | |
7 | 2516 * |
2517 * "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
|
2518 * "arg" is advanced to just after the recognized expression. |
7 | 2519 * |
2520 * Return OK or FAIL. | |
2521 */ | |
2522 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
|
2523 eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2524 { |
2525 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
|
2526 int getnext; |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2527 exptype_T type = EXPR_UNKNOWN; |
7 | 2528 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
|
2529 int type_is = FALSE; |
7 | 2530 |
2531 /* | |
2532 * Get the first variable. | |
2533 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2534 if (eval5(arg, rettv, evalarg) == FAIL) |
7 | 2535 return FAIL; |
2536 | |
21026
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2537 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
|
2538 type = get_compare_type(p, &len, &type_is); |
7 | 2539 |
2540 /* | |
1624 | 2541 * If there is a comparative operator, use it. |
7 | 2542 */ |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2543 if (type != EXPR_UNKNOWN) |
7 | 2544 { |
21425
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
2545 typval_T var2; |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
2546 int ic; |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
2547 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
|
2548 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
|
2549 ? 0 : (evalarg->eval_flags & EVAL_EVALUATE); |
21425
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
2550 |
21026
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2551 if (getnext) |
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2552 *arg = eval_next_line(evalarg); |
21636
dcfcb6163f3d
patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21634
diff
changeset
|
2553 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
|
2554 { |
dcfcb6163f3d
patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21634
diff
changeset
|
2555 error_white_both(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
|
2556 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
|
2557 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
|
2558 } |
21026
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2559 |
21546
4d3e983313dc
patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
2560 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
|
2561 { |
4d3e983313dc
patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
2562 semsg(_(e_invexpr2), p); |
4d3e983313dc
patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
2563 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
|
2564 return FAIL; |
4d3e983313dc
patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
2565 } |
4d3e983313dc
patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
2566 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2567 // extra question mark appended: ignore case |
7 | 2568 if (p[len] == '?') |
2569 { | |
2570 ic = TRUE; | |
2571 ++len; | |
2572 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2573 // extra '#' appended: match case |
7 | 2574 else if (p[len] == '#') |
2575 { | |
2576 ic = FALSE; | |
2577 ++len; | |
2578 } | |
21425
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
2579 // nothing appended: use 'ignorecase' if not in Vim script |
7 | 2580 else |
21425
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
2581 ic = vim9script ? FALSE : p_ic; |
7 | 2582 |
2583 /* | |
2584 * Get the second variable. | |
2585 */ | |
21636
dcfcb6163f3d
patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21634
diff
changeset
|
2586 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
|
2587 { |
dcfcb6163f3d
patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21634
diff
changeset
|
2588 error_white_both(p, 1); |
dcfcb6163f3d
patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21634
diff
changeset
|
2589 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
|
2590 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
|
2591 } |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2592 *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
|
2593 if (eval5(arg, &var2, evalarg) == FAIL) |
7 | 2594 { |
71 | 2595 clear_tv(rettv); |
7 | 2596 return FAIL; |
2597 } | |
21636
dcfcb6163f3d
patch 8.2.1368: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21634
diff
changeset
|
2598 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
|
2599 { |
21251
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
2600 int ret; |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
2601 |
21425
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
2602 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
|
2603 { |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
2604 ret = FAIL; |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
2605 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
|
2606 } |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
2607 else |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
2608 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
|
2609 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
|
2610 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
|
2611 } |
7 | 2612 } |
2613 | |
2614 return OK; | |
2615 } | |
2616 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2617 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2618 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
|
2619 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2620 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
|
2621 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
|
2622 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
|
2623 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2624 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2625 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
|
2626 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2627 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
|
2628 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
|
2629 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
|
2630 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
|
2631 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2632 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
|
2633 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
|
2634 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2635 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2636 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2637 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2638 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
|
2639 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2640 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
|
2641 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2642 // concatenate Lists |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2643 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
|
2644 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2645 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
|
2646 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
|
2647 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2648 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2649 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
|
2650 *tv1 = var3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2651 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2652 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2653 |
7 | 2654 /* |
2655 * Handle fourth level expression: | |
2656 * + number addition | |
2657 * - number subtraction | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2658 * . 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
|
2659 * .. string concatenation |
7 | 2660 * |
2661 * "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
|
2662 * "arg" is advanced to just after the recognized expression. |
7 | 2663 * |
2664 * Return OK or FAIL. | |
2665 */ | |
2666 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
|
2667 eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2668 { |
2669 /* | |
2670 * Get the first variable. | |
2671 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2672 if (eval6(arg, rettv, evalarg, FALSE) == FAIL) |
7 | 2673 return FAIL; |
2674 | |
2675 /* | |
2676 * Repeat computing, until no '+', '-' or '.' is following. | |
2677 */ | |
2678 for (;;) | |
2679 { | |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2680 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
|
2681 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
|
2682 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
|
2683 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
|
2684 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
|
2685 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
|
2686 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
|
2687 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
|
2688 |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2689 // "." is only string concatenation when scriptversion is 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
|
2690 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
|
2691 op = *p; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2692 concat = op == '.' && (*(p + 1) == '.' || current_sctx.sc_version < 2); |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2693 if (op != '+' && op != '-' && !concat) |
7 | 2694 break; |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2695 |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21622
diff
changeset
|
2696 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
|
2697 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
|
2698 if (getnext) |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2699 *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
|
2700 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
|
2701 { |
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
|
2702 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
|
2703 { |
21634
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2704 error_white_both(p, 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
|
2705 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
|
2706 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
|
2707 } |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2708 *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
|
2709 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2710 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
|
2711 && rettv->v_type != VAR_BLOB)) |
1624 | 2712 #ifdef FEAT_FLOAT |
2713 && (op == '.' || rettv->v_type != VAR_FLOAT) | |
2714 #endif | |
2715 ) | |
323 | 2716 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2717 // 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
|
2718 // 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
|
2719 // 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
|
2720 // 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
|
2721 // 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
|
2722 // 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
|
2723 // side effects after an 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
|
2724 if (evaluate && tv_get_string_chk(rettv) == NULL) |
323 | 2725 { |
2726 clear_tv(rettv); | |
2727 return FAIL; | |
2728 } | |
2729 } | |
2730 | |
7 | 2731 /* |
2732 * Get the second variable. | |
2733 */ | |
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
|
2734 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
|
2735 { |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21622
diff
changeset
|
2736 error_white_both(p, oplen); |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21622
diff
changeset
|
2737 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
|
2738 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
|
2739 } |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21622
diff
changeset
|
2740 *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
|
2741 if (eval6(arg, &var2, evalarg, !vim9script && op == '.') == FAIL) |
7 | 2742 { |
71 | 2743 clear_tv(rettv); |
7 | 2744 return FAIL; |
2745 } | |
2746 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2747 if (evaluate) |
7 | 2748 { |
2749 /* | |
2750 * Compute the result. | |
2751 */ | |
2752 if (op == '.') | |
2753 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2754 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
|
2755 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
|
2756 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
|
2757 |
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
|
2758 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
|
2759 || 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
|
2760 || var2.v_type == VAR_JOB)) |
fcf978444298
patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
21733
diff
changeset
|
2761 emsg(_(e_inval_string)); |
fcf978444298
patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
21733
diff
changeset
|
2762 #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
|
2763 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
|
2764 { |
fcf978444298
patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
21733
diff
changeset
|
2765 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
|
2766 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
|
2767 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
|
2768 } |
fcf978444298
patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
21733
diff
changeset
|
2769 #endif |
fcf978444298
patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
21733
diff
changeset
|
2770 else |
fcf978444298
patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
21733
diff
changeset
|
2771 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
|
2772 if (s2 == NULL) // type error ? |
323 | 2773 { |
2774 clear_tv(rettv); | |
2775 clear_tv(&var2); | |
2776 return FAIL; | |
2777 } | |
117 | 2778 p = concat_str(s1, s2); |
71 | 2779 clear_tv(rettv); |
2780 rettv->v_type = VAR_STRING; | |
2781 rettv->vval.v_string = p; | |
7 | 2782 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2783 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
|
2784 && 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
|
2785 eval_addblob(rettv, &var2); |
104 | 2786 else if (op == '+' && rettv->v_type == VAR_LIST |
2787 && var2.v_type == VAR_LIST) | |
80 | 2788 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2789 if (eval_addlist(rettv, &var2) == FAIL) |
80 | 2790 return FAIL; |
2791 } | |
7 | 2792 else |
2793 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2794 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
|
2795 varnumber_T n1, n2; |
1624 | 2796 #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
|
2797 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
|
2798 |
1624 | 2799 if (rettv->v_type == VAR_FLOAT) |
2800 { | |
2801 f1 = rettv->vval.v_float; | |
2802 n1 = 0; | |
2803 } | |
2804 else | |
2805 #endif | |
2806 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2807 n1 = tv_get_number_chk(rettv, &error); |
1624 | 2808 if (error) |
2809 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2810 // This can only happen for "list + non-list". For |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2811 // "non-list + ..." or "something - ...", we returned |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2812 // before evaluating the 2nd operand. |
1624 | 2813 clear_tv(rettv); |
2814 return FAIL; | |
2815 } | |
2816 #ifdef FEAT_FLOAT | |
2817 if (var2.v_type == VAR_FLOAT) | |
2818 f1 = n1; | |
2819 #endif | |
2820 } | |
2821 #ifdef FEAT_FLOAT | |
2822 if (var2.v_type == VAR_FLOAT) | |
2823 { | |
2824 f2 = var2.vval.v_float; | |
2825 n2 = 0; | |
2826 } | |
2827 else | |
2828 #endif | |
2829 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2830 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2831 if (error) |
2832 { | |
2833 clear_tv(rettv); | |
2834 clear_tv(&var2); | |
2835 return FAIL; | |
2836 } | |
2837 #ifdef FEAT_FLOAT | |
2838 if (rettv->v_type == VAR_FLOAT) | |
2839 f2 = n2; | |
2840 #endif | |
323 | 2841 } |
71 | 2842 clear_tv(rettv); |
1624 | 2843 |
2844 #ifdef FEAT_FLOAT | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2845 // If there is a float on either side the result is a float. |
1624 | 2846 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) |
2847 { | |
2848 if (op == '+') | |
2849 f1 = f1 + f2; | |
2850 else | |
2851 f1 = f1 - f2; | |
2852 rettv->v_type = VAR_FLOAT; | |
2853 rettv->vval.v_float = f1; | |
2854 } | |
2855 else | |
2856 #endif | |
2857 { | |
2858 if (op == '+') | |
2859 n1 = n1 + n2; | |
2860 else | |
2861 n1 = n1 - n2; | |
2862 rettv->v_type = VAR_NUMBER; | |
2863 rettv->vval.v_number = n1; | |
2864 } | |
71 | 2865 } |
2866 clear_tv(&var2); | |
7 | 2867 } |
2868 } | |
2869 return OK; | |
2870 } | |
2871 | |
2872 /* | |
2873 * Handle fifth level expression: | |
2874 * * number multiplication | |
2875 * / number division | |
2876 * % number modulo | |
2877 * | |
2878 * "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
|
2879 * "arg" is advanced to just after the recognized expression. |
7 | 2880 * |
2881 * Return OK or FAIL. | |
2882 */ | |
2883 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2884 eval6( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2885 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2886 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
|
2887 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2888 int want_string) // after "." operator |
7 | 2889 { |
1624 | 2890 #ifdef FEAT_FLOAT |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2891 int use_float = FALSE; |
1624 | 2892 #endif |
7 | 2893 |
2894 /* | |
2895 * Get the first variable. | |
2896 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2897 if (eval7(arg, rettv, evalarg, want_string) == FAIL) |
7 | 2898 return FAIL; |
2899 | |
2900 /* | |
2901 * Repeat computing, until no '*', '/' or '%' is following. | |
2902 */ | |
2903 for (;;) | |
2904 { | |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2905 int evaluate; |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2906 int getnext; |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2907 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
|
2908 char_u *p; |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2909 int op; |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2910 varnumber_T n1, n2; |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2911 #ifdef FEAT_FLOAT |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2912 float_T f1, f2; |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2913 #endif |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2914 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
|
2915 |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2916 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
|
2917 op = *p; |
17387
2558f90045e5
patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents:
17377
diff
changeset
|
2918 if (op != '*' && op != '/' && op != '%') |
7 | 2919 break; |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2920 |
21634
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2921 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
|
2922 if (getnext) |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2923 *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
|
2924 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
|
2925 { |
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2926 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
|
2927 { |
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2928 error_white_both(p, 1); |
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2929 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
|
2930 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
|
2931 } |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
2932 *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
|
2933 } |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2934 |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2935 #ifdef FEAT_FLOAT |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2936 f1 = 0; |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2937 f2 = 0; |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2938 #endif |
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2939 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
|
2940 if (evaluate) |
7 | 2941 { |
1624 | 2942 #ifdef FEAT_FLOAT |
2943 if (rettv->v_type == VAR_FLOAT) | |
2944 { | |
2945 f1 = rettv->vval.v_float; | |
2946 use_float = TRUE; | |
2947 n1 = 0; | |
2948 } | |
2949 else | |
2950 #endif | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2951 n1 = tv_get_number_chk(rettv, &error); |
71 | 2952 clear_tv(rettv); |
323 | 2953 if (error) |
2954 return FAIL; | |
7 | 2955 } |
2956 else | |
2957 n1 = 0; | |
2958 | |
2959 /* | |
2960 * Get the second variable. | |
2961 */ | |
21634
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2962 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
|
2963 { |
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2964 error_white_both(p, 1); |
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2965 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
|
2966 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
|
2967 } |
3a86e41fdffd
patch 8.2.1367: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2968 *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
|
2969 if (eval7(arg, &var2, evalarg, FALSE) == FAIL) |
7 | 2970 return FAIL; |
2971 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2972 if (evaluate) |
7 | 2973 { |
1624 | 2974 #ifdef FEAT_FLOAT |
2975 if (var2.v_type == VAR_FLOAT) | |
2976 { | |
2977 if (!use_float) | |
2978 { | |
2979 f1 = n1; | |
2980 use_float = TRUE; | |
2981 } | |
2982 f2 = var2.vval.v_float; | |
2983 n2 = 0; | |
2984 } | |
2985 else | |
2986 #endif | |
2987 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2988 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2989 clear_tv(&var2); |
2990 if (error) | |
2991 return FAIL; | |
2992 #ifdef FEAT_FLOAT | |
2993 if (use_float) | |
2994 f2 = n2; | |
2995 #endif | |
2996 } | |
7 | 2997 |
2998 /* | |
2999 * Compute the result. | |
1624 | 3000 * When either side is a float the result is a float. |
7 | 3001 */ |
1624 | 3002 #ifdef FEAT_FLOAT |
3003 if (use_float) | |
3004 { | |
3005 if (op == '*') | |
3006 f1 = f1 * f2; | |
3007 else if (op == '/') | |
3008 { | |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3009 # ifdef VMS |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3010 // 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
|
3011 if (f2 == 0.0) |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3012 { |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3013 if (f1 == 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3014 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
|
3015 else if (f1 < 0) |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
3016 f1 = -1 * __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3017 else |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
3018 f1 = __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3019 } |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3020 else |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3021 f1 = f1 / f2; |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3022 # else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3023 // 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
|
3024 // by zero to result in "inf" and not a crash. |
1624 | 3025 f1 = f1 / f2; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
3026 # endif |
1624 | 3027 } |
3028 else | |
3029 { | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3030 emsg(_(e_modulus)); |
1624 | 3031 return FAIL; |
3032 } | |
3033 rettv->v_type = VAR_FLOAT; | |
3034 rettv->vval.v_float = f1; | |
3035 } | |
3036 else | |
3037 #endif | |
3038 { | |
3039 if (op == '*') | |
3040 n1 = n1 * n2; | |
3041 else if (op == '/') | |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
3042 n1 = num_divide(n1, n2); |
1624 | 3043 else |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
3044 n1 = num_modulus(n1, n2); |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
3045 |
1624 | 3046 rettv->v_type = VAR_NUMBER; |
3047 rettv->vval.v_number = n1; | |
3048 } | |
7 | 3049 } |
3050 } | |
3051 | |
3052 return OK; | |
3053 } | |
3054 | |
3055 /* | |
3056 * Handle sixth level expression: | |
3057 * number number constant | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3058 * 0zFFFFFFFF Blob constant |
1228 | 3059 * "string" string constant |
3060 * 'string' literal string constant | |
7 | 3061 * &option-name option value |
3062 * @r register contents | |
3063 * identifier variable value | |
3064 * function() function call | |
3065 * $VAR environment variable | |
3066 * (expression) nested expression | |
151 | 3067 * [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
|
3068 * {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
|
3069 * {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
|
3070 * #{key: val, key: val} Dictionary with literal keys |
7 | 3071 * |
3072 * Also handle: | |
3073 * ! in front logical NOT | |
3074 * - in front unary minus | |
3075 * + in front unary plus (ignored) | |
100 | 3076 * trailing [] subscript in String or List |
3077 * 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
|
3078 * trailing ->name() method call |
7 | 3079 * |
3080 * "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
|
3081 * "arg" is advanced to just after the recognized expression. |
7 | 3082 * |
3083 * Return OK or FAIL. | |
3084 */ | |
3085 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3086 eval7( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3087 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3088 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
|
3089 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
|
3090 int want_string) // after "." operator |
7 | 3091 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3092 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
|
3093 && (evalarg->eval_flags & EVAL_EVALUATE); |
7 | 3094 int len; |
3095 char_u *s; | |
3096 char_u *start_leader, *end_leader; | |
3097 int ret = OK; | |
3098 char_u *alias; | |
3099 | |
3100 /* | |
71 | 3101 * Initialise variable so that clear_tv() can't mistake this for a |
56 | 3102 * string and free a string that isn't there. |
7 | 3103 */ |
71 | 3104 rettv->v_type = VAR_UNKNOWN; |
7 | 3105 |
3106 /* | |
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10000
diff
changeset
|
3107 * Skip '!', '-' and '+' characters. They are handled later. |
7 | 3108 */ |
3109 start_leader = *arg; | |
3110 while (**arg == '!' || **arg == '-' || **arg == '+') | |
3111 *arg = skipwhite(*arg + 1); | |
3112 end_leader = *arg; | |
3113 | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3114 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
|
3115 #ifdef FEAT_FLOAT |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3116 || current_sctx.sc_version < 2 |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3117 #endif |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3118 )) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3119 { |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3120 semsg(_(e_invexpr2), *arg); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3121 ++*arg; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3122 return FAIL; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3123 } |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
3124 |
7 | 3125 switch (**arg) |
3126 { | |
3127 /* | |
3128 * Number constant. | |
3129 */ | |
3130 case '0': | |
3131 case '1': | |
3132 case '2': | |
3133 case '3': | |
3134 case '4': | |
3135 case '5': | |
3136 case '6': | |
3137 case '7': | |
3138 case '8': | |
3139 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
|
3140 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
|
3141 |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3142 // 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
|
3143 // "->" follows. |
21733
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
3144 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
|
3145 && 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
|
3146 ret = eval7_leader(rettv, TRUE, start_leader, &end_leader); |
1624 | 3147 break; |
7 | 3148 |
3149 /* | |
3150 * String constant: "string". | |
3151 */ | |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3152 case '"': ret = eval_string(arg, rettv, evaluate); |
7 | 3153 break; |
3154 | |
3155 /* | |
100 | 3156 * Literal string constant: 'str''ing'. |
7 | 3157 */ |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3158 case '\'': ret = eval_lit_string(arg, rettv, evaluate); |
56 | 3159 break; |
3160 | |
3161 /* | |
3162 * List: [expr, expr] | |
3163 */ | |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3164 case '[': ret = eval_list(arg, rettv, evalarg, TRUE); |
7 | 3165 break; |
3166 | |
3167 /* | |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
3168 * 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
|
3169 */ |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
3170 case '#': 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
|
3171 { |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
3172 ++*arg; |
21034
2f8b0812819f
patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
3173 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
|
3174 } |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
3175 else |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
3176 ret = NOTDONE; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
3177 break; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
3178 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
3179 /* |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
3180 * 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
|
3181 * Dictionary: {'key': val, 'key': val} |
100 | 3182 */ |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3183 case '{': ret = get_lambda_tv(arg, rettv, evalarg); |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
3184 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
|
3185 ret = eval_dict(arg, rettv, evalarg, FALSE); |
100 | 3186 break; |
3187 | |
3188 /* | |
104 | 3189 * Option value: &name |
7 | 3190 */ |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3191 case '&': ret = eval_option(arg, rettv, evaluate); |
7 | 3192 break; |
3193 | |
3194 /* | |
3195 * Environment variable: $VAR. | |
3196 */ | |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3197 case '$': ret = eval_env_var(arg, rettv, evaluate); |
7 | 3198 break; |
3199 | |
3200 /* | |
3201 * Register contents: @r. | |
3202 */ | |
3203 case '@': ++*arg; | |
3204 if (evaluate) | |
3205 { | |
71 | 3206 rettv->v_type = VAR_STRING; |
5796 | 3207 rettv->vval.v_string = get_reg_contents(**arg, |
3208 GREG_EXPR_SRC); | |
7 | 3209 } |
3210 if (**arg != NUL) | |
3211 ++*arg; | |
3212 break; | |
3213 | |
3214 /* | |
3215 * nested expression: (expression). | |
3216 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3217 case '(': { |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
3218 *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
|
3219 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
|
3220 |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
3221 *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
|
3222 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
|
3223 ++*arg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3224 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
|
3225 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3226 emsg(_(e_missing_close)); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3227 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
|
3228 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
|
3229 } |
7 | 3230 } |
3231 break; | |
3232 | |
100 | 3233 default: ret = NOTDONE; |
3234 break; | |
3235 } | |
3236 | |
3237 if (ret == NOTDONE) | |
3238 { | |
3239 /* | |
3240 * Must be a variable or function name. | |
3241 * Can also be a curly-braces kind of name: {expr}. | |
3242 */ | |
3243 s = *arg; | |
159 | 3244 len = get_name_len(arg, &alias, evaluate, TRUE); |
100 | 3245 if (alias != NULL) |
3246 s = alias; | |
3247 | |
159 | 3248 if (len <= 0) |
100 | 3249 ret = FAIL; |
3250 else | |
3251 { | |
21305
91d4af3309e7
patch 8.2.1203: unused assignments in expression evaluation
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3252 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
|
3253 |
21656
c3f6006bf0ba
patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents:
21644
diff
changeset
|
3254 if ((in_vim9script() ? **arg : *skipwhite(*arg)) == '(') |
c3f6006bf0ba
patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents:
21644
diff
changeset
|
3255 { |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3256 // "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
|
3257 *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
|
3258 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
|
3259 } |
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
|
3260 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
|
3261 ret = FAIL; |
100 | 3262 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
|
3263 { |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3264 // get the value of "true", "false" or a variable |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3265 if (len == 4 && in_vim9script() && STRNCMP(s, "true", 4) == 0) |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3266 { |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3267 rettv->v_type = VAR_BOOL; |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3268 rettv->vval.v_number = VVAL_TRUE; |
21725
741c1d58d50f
patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
3269 ret = OK; |
21307
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3270 } |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3271 else if (len == 5 && in_vim9script() |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3272 && STRNCMP(s, "false", 4) == 0) |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3273 { |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3274 rettv->v_type = VAR_BOOL; |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3275 rettv->vval.v_number = VVAL_FALSE; |
21725
741c1d58d50f
patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
3276 ret = OK; |
21307
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3277 } |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3278 else |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3279 ret = eval_variable(s, len, rettv, NULL, TRUE, FALSE); |
b991565745fb
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21305
diff
changeset
|
3280 } |
117 | 3281 else |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3282 { |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3283 // skip the name |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3284 check_vars(s, len); |
117 | 3285 ret = OK; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3286 } |
100 | 3287 } |
2690 | 3288 vim_free(alias); |
100 | 3289 } |
3290 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3291 // 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
|
3292 // expr(expr), expr->name(expr) |
159 | 3293 if (ret == OK) |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3294 ret = handle_subscript(arg, rettv, evalarg, TRUE); |
7 | 3295 |
3296 /* | |
3297 * Apply logical NOT and unary '-', from right to left, ignore '+'. | |
3298 */ | |
3299 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
|
3300 ret = eval7_leader(rettv, FALSE, start_leader, &end_leader); |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3301 return ret; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3302 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3303 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3304 /* |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3305 * 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
|
3306 * 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
|
3307 * 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
|
3308 */ |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3309 static int |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3310 eval7_leader( |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3311 typval_T *rettv, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3312 int numeric_only, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3313 char_u *start_leader, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3314 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
|
3315 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3316 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
|
3317 int ret = OK; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3318 int error = FALSE; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3319 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
|
3320 vartype_T type = rettv->v_type; |
1624 | 3321 #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
|
3322 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
|
3323 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3324 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
|
3325 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
|
3326 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3327 #endif |
21733
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
3328 if (in_vim9script() && end_leader[-1] == '!') |
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
3329 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
|
3330 else |
1bb5adfe5966
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents:
21725
diff
changeset
|
3331 val = tv_get_number_chk(rettv, &error); |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3332 if (error) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3333 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3334 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3335 ret = FAIL; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3336 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3337 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3338 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3339 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
|
3340 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3341 --end_leader; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3342 if (*end_leader == '!') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3343 { |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3344 if (numeric_only) |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3345 { |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3346 ++end_leader; |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3347 break; |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3348 } |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3349 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3350 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
|
3351 f = !f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3352 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3353 #endif |
21725
741c1d58d50f
patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
3354 { |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3355 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
|
3356 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
|
3357 } |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3358 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3359 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
|
3360 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3361 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3362 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
|
3363 f = -f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3364 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3365 #endif |
21725
741c1d58d50f
patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
3366 { |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3367 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
|
3368 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
|
3369 } |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3370 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3371 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3372 #ifdef FEAT_FLOAT |
1624 | 3373 if (rettv->v_type == VAR_FLOAT) |
323 | 3374 { |
3375 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
|
3376 rettv->vval.v_float = f; |
323 | 3377 } |
3378 else | |
1624 | 3379 #endif |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3380 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3381 clear_tv(rettv); |
21725
741c1d58d50f
patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
3382 if (in_vim9script()) |
741c1d58d50f
patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
3383 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
|
3384 else |
741c1d58d50f
patch 8.2.1412: Vim: not operator does not result in boolean
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
3385 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
|
3386 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
|
3387 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3388 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3389 *end_leaderp = end_leader; |
7 | 3390 return ret; |
3391 } | |
3392 | |
3393 /* | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3394 * 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
|
3395 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3396 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3397 call_func_rettv( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3398 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
|
3399 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
|
3400 typval_T *rettv, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3401 int evaluate, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3402 dict_T *selfdict, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3403 typval_T *basetv) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3404 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3405 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
|
3406 funcexe_T funcexe; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3407 typval_T functv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3408 char_u *s; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3409 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3410 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3411 // 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
|
3412 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3413 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3414 functv = *rettv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3415 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
|
3416 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3417 // 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
|
3418 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
|
3419 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3420 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
|
3421 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
|
3422 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3423 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3424 s = functv.vval.v_string; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3425 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3426 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3427 s = (char_u *)""; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3428 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
3429 CLEAR_FIELD(funcexe); |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3430 funcexe.firstline = curwin->w_cursor.lnum; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3431 funcexe.lastline = curwin->w_cursor.lnum; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3432 funcexe.evaluate = evaluate; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3433 funcexe.partial = pt; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3434 funcexe.selfdict = selfdict; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3435 funcexe.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
|
3436 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
|
3437 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3438 // 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
|
3439 // 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
|
3440 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3441 clear_tv(&functv); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3442 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3443 return ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3444 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3445 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3446 /* |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3447 * Evaluate "->method()". |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3448 * "*arg" points to the '-'. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3449 * 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
|
3450 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3451 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3452 eval_lambda( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3453 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3454 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
|
3455 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3456 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
|
3457 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3458 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
|
3459 && (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
|
3460 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
|
3461 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3462 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3463 // Skip over the ->. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3464 *arg += 2; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3465 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
|
3466 |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3467 ret = get_lambda_tv(arg, rettv, evalarg); |
18851
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
3468 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
|
3469 return FAIL; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3470 else if (**arg != '(') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3471 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3472 if (verbose) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3473 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3474 if (*skipwhite(*arg) == '(') |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
3475 emsg(_(e_nowhitespace)); |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3476 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3477 semsg(_(e_missing_paren), "lambda"); |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3478 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3479 clear_tv(rettv); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3480 ret = FAIL; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3481 } |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3482 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
|
3483 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
|
3484 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3485 // 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
|
3486 // 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
|
3487 if (evaluate) |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3488 clear_tv(&base); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3489 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3490 return ret; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3491 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3492 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3493 /* |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3494 * Evaluate "->method()". |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3495 * "*arg" points to the '-'. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3496 * 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
|
3497 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3498 static int |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3499 eval_method( |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3500 char_u **arg, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3501 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
|
3502 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3503 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
|
3504 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3505 char_u *name; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3506 long len; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3507 char_u *alias; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3508 typval_T base = *rettv; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3509 int ret; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
3510 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
|
3511 && (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
|
3512 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3513 // Skip over the ->. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3514 *arg += 2; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3515 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
|
3516 |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3517 name = *arg; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3518 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
|
3519 if (alias != NULL) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3520 name = alias; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3521 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3522 if (len <= 0) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3523 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3524 if (verbose) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3525 emsg(_("E260: Missing name after ->")); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3526 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3527 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3528 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3529 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21622
diff
changeset
|
3530 *arg = skipwhite(*arg); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3531 if (**arg != '(') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3532 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3533 if (verbose) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3534 semsg(_(e_missing_paren), name); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3535 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3536 } |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3537 else if (VIM_ISWHITE((*arg)[-1])) |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3538 { |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3539 if (verbose) |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
3540 emsg(_(e_nowhitespace)); |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3541 ret = FAIL; |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3542 } |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3543 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
|
3544 ret = eval_func(arg, evalarg, name, len, rettv, |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
3545 evaluate ? EVAL_EVALUATE : 0, &base); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3546 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3547 |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3548 // 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
|
3549 // 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
|
3550 if (evaluate) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3551 clear_tv(&base); |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3552 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3553 return ret; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3554 } |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3555 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3556 /* |
829 | 3557 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". |
3558 * "*arg" points to the '[' or '.'. | |
56 | 3559 * Returns FAIL or OK. "*arg" is advanced to after the ']'. |
3560 */ | |
3561 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3562 eval_index( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3563 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3564 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
|
3565 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3566 int verbose) // give error messages |
56 | 3567 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3568 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
|
3569 && (evalarg->eval_flags & EVAL_EVALUATE); |
56 | 3570 int empty1 = FALSE, empty2 = FALSE; |
137 | 3571 typval_T var1, var2; |
100 | 3572 int range = FALSE; |
3573 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
|
3574 int keylen = -1; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3575 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3576 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
|
3577 return FAIL; |
56 | 3578 |
7046
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3579 init_tv(&var1); |
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3580 init_tv(&var2); |
100 | 3581 if (**arg == '.') |
3582 { | |
3583 /* | |
3584 * dict.name | |
3585 */ | |
3586 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
|
3587 for (keylen = 0; eval_isdictc(key[keylen]); ++keylen) |
100 | 3588 ; |
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
|
3589 if (keylen == 0) |
100 | 3590 return FAIL; |
22244
9f6b8fdea159
patch 8.2.1671: Vim9: stray error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3591 *arg = key + keylen; |
100 | 3592 } |
3593 else | |
3594 { | |
3595 /* | |
3596 * something[idx] | |
3597 * | |
3598 * Get the (first) variable from inside the []. | |
3599 */ | |
21142
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
3600 *arg = skipwhite_and_linebreak(*arg + 1, evalarg); |
100 | 3601 if (**arg == ':') |
3602 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
|
3603 else if (eval1(arg, &var1, evalarg) == FAIL) // recursive! |
56 | 3604 return FAIL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3605 else if (evaluate && tv_get_string_chk(&var1) == NULL) |
323 | 3606 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3607 // not a number or string |
323 | 3608 clear_tv(&var1); |
3609 return FAIL; | |
3610 } | |
100 | 3611 |
3612 /* | |
3613 * Get the second variable from inside the [:]. | |
3614 */ | |
21142
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
3615 *arg = skipwhite_and_linebreak(*arg, evalarg); |
100 | 3616 if (**arg == ':') |
3617 { | |
3618 range = TRUE; | |
21142
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
3619 *arg = skipwhite_and_linebreak(*arg + 1, evalarg); |
100 | 3620 if (**arg == ']') |
3621 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
|
3622 else if (eval1(arg, &var2, evalarg) == FAIL) // recursive! |
100 | 3623 { |
323 | 3624 if (!empty1) |
3625 clear_tv(&var1); | |
3626 return FAIL; | |
3627 } | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3628 else if (evaluate && tv_get_string_chk(&var2) == NULL) |
323 | 3629 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3630 // not a number or string |
323 | 3631 if (!empty1) |
3632 clear_tv(&var1); | |
3633 clear_tv(&var2); | |
100 | 3634 return FAIL; |
3635 } | |
3636 } | |
3637 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3638 // 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
|
3639 *arg = skipwhite_and_linebreak(*arg, evalarg); |
100 | 3640 if (**arg != ']') |
3641 { | |
159 | 3642 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3643 emsg(_(e_missbrac)); |
100 | 3644 clear_tv(&var1); |
3645 if (range) | |
3646 clear_tv(&var2); | |
3647 return FAIL; | |
3648 } | |
21837
2b941fbab4d9
patch 8.2.1468: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21833
diff
changeset
|
3649 *arg = *arg + 1; // skip over the ']' |
56 | 3650 } |
3651 | |
3652 if (evaluate) | |
3653 { | |
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
|
3654 int res = eval_index_inner(rettv, 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
|
3655 empty1 ? NULL : &var1, empty2 ? NULL : &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
|
3656 key, keylen, 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
|
3657 if (!empty1) |
71 | 3658 clear_tv(&var1); |
56 | 3659 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
|
3660 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
|
3661 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
|
3662 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3663 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
|
3664 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3665 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3666 /* |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3667 * 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
|
3668 */ |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3669 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
|
3670 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
|
3671 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3672 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
|
3673 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3674 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
|
3675 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
|
3676 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
|
3677 emsg(_("E695: Cannot index a Funcref")); |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3678 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
|
3679 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
|
3680 #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
|
3681 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
|
3682 emsg(_(e_float_as_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
|
3683 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
|
3684 #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
|
3685 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
|
3686 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
|
3687 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
|
3688 case VAR_CHANNEL: |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3689 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
|
3690 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
|
3691 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
|
3692 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
|
3693 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
|
3694 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
|
3695 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
|
3696 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3697 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
|
3698 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
|
3699 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3700 // 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
|
3701 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3702 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
|
3703 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
|
3704 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
|
3705 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
|
3706 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
|
3707 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
|
3708 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
|
3709 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
|
3710 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
|
3711 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3712 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
|
3713 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3714 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3715 /* |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3716 * 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
|
3717 * "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
|
3718 * "var2" is the second index, NULL for [expr] and [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
|
3719 * 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
|
3720 */ |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3721 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
|
3722 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
|
3723 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
|
3724 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
|
3725 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
|
3726 typval_T *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
|
3727 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
|
3728 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
|
3729 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
|
3730 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3731 long n1, n2 = 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
|
3732 long len; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3733 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3734 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
|
3735 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
|
3736 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
|
3737 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3738 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
|
3739 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3740 if (rettv->v_type == VAR_DICT) |
56 | 3741 { |
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
|
3742 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
|
3743 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
|
3744 return FAIL; |
71 | 3745 } |
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
|
3746 if (var2 == 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
|
3747 n2 = -1; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3748 else |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3749 n2 = tv_get_number(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
|
3750 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3751 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3752 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
|
3753 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3754 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
|
3755 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
|
3756 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
|
3757 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
|
3758 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
|
3759 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
|
3760 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
|
3761 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
|
3762 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
|
3763 case VAR_CHANNEL: |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3764 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
|
3765 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3766 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
|
3767 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
|
3768 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3769 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
|
3770 |
56 | 3771 len = (long)STRLEN(s); |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
3772 if (in_vim9script()) |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
3773 { |
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
|
3774 if (is_range) |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
3775 s = string_slice(s, n1, n2); |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
3776 else |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
3777 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
|
3778 } |
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
|
3779 else if (is_range) |
56 | 3780 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3781 // 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
|
3782 // are out of range the result is empty. |
56 | 3783 if (n1 < 0) |
3784 { | |
3785 n1 = len + n1; | |
3786 if (n1 < 0) | |
3787 n1 = 0; | |
3788 } | |
3789 if (n2 < 0) | |
3790 n2 = len + n2; | |
3791 else if (n2 >= len) | |
3792 n2 = len; | |
3793 if (n1 >= len || n2 < 0 || n1 > n2) | |
3794 s = NULL; | |
3795 else | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
3796 s = vim_strnsave(s + n1, n2 - n1 + 1); |
56 | 3797 } |
3798 else | |
3799 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3800 // 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
|
3801 // 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
|
3802 // result is empty. |
56 | 3803 if (n1 >= len || n1 < 0) |
3804 s = NULL; | |
3805 else | |
3806 s = vim_strnsave(s + n1, 1); | |
3807 } | |
71 | 3808 clear_tv(rettv); |
3809 rettv->v_type = VAR_STRING; | |
3810 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
|
3811 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3812 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
|
3813 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3814 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
|
3815 len = blob_len(rettv->vval.v_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
|
3816 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
|
3817 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3818 // The resulting variable is a sub-blob. If the indexes |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3819 // are out of range the result is empty. |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3820 if (n1 < 0) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3821 { |
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
|
3822 n1 = len + n1; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3823 if (n1 < 0) |
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
|
3824 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
|
3825 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3826 if (n2 < 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
|
3827 n2 = len + n2; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3828 else if (n2 >= len) |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3829 n2 = len - 1; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3830 if (n1 >= len || n2 < 0 || n1 > n2) |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3831 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3832 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
|
3833 rettv->v_type = 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
|
3834 rettv->vval.v_blob = NULL; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3835 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3836 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3837 { |
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
|
3838 blob_T *blob = blob_alloc(); |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3839 long i; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3840 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3841 if (blob != NULL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3842 { |
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
|
3843 if (ga_grow(&blob->bv_ga, n2 - n1 + 1) == 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
|
3844 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3845 blob_free(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
|
3846 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
|
3847 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3848 blob->bv_ga.ga_len = n2 - n1 + 1; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3849 for (i = n1; i <= n2; i++) |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3850 blob_set(blob, i - n1, |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3851 blob_get(rettv->vval.v_blob, i)); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3852 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3853 clear_tv(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
|
3854 rettv_blob_set(rettv, blob); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3855 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3856 } |
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
|
3857 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3858 else |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3859 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3860 // The resulting variable is a byte value. |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3861 // If the index is too big or negative that is an error. |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3862 if (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
|
3863 n1 = len + n1; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3864 if (n1 < len && n1 >= 0) |
100 | 3865 { |
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
|
3866 int v = blob_get(rettv->vval.v_blob, n1); |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3867 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3868 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
|
3869 rettv->v_type = 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
|
3870 rettv->vval.v_number = v; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3871 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3872 else |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3873 semsg(_(e_blobidx), n1); |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3874 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3875 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
|
3876 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3877 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
|
3878 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
|
3879 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
|
3880 if (var2 == 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
|
3881 n2 = -1; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3882 if (list_slice_or_index(rettv->vval.v_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
|
3883 is_range, n1, n2, rettv, 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
|
3884 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
|
3885 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
|
3886 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3887 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
|
3888 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3889 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
|
3890 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
|
3891 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3892 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
|
3893 { |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3894 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
|
3895 if (key == NULL) |
100 | 3896 return FAIL; |
3897 } | |
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
|
3898 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3899 item = dict_find(rettv->vval.v_dict, key, (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
|
3900 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3901 if (item == NULL && 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
|
3902 semsg(_(e_dictkey), 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
|
3903 if (item == 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
|
3904 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
|
3905 |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3906 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
|
3907 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
|
3908 *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
|
3909 } |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
3910 break; |
100 | 3911 } |
56 | 3912 return OK; |
3913 } | |
3914 | |
3915 /* | |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3916 * 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
|
3917 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3918 char_u * |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3919 partial_name(partial_T *pt) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3920 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3921 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3922 return pt->pt_name; |
20158
94f05de75e9f
patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents:
20156
diff
changeset
|
3923 if (pt->pt_func != NULL) |
94f05de75e9f
patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents:
20156
diff
changeset
|
3924 return pt->pt_func->uf_name; |
94f05de75e9f
patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents:
20156
diff
changeset
|
3925 return (char_u *)""; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3926 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3927 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3928 static void |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3929 partial_free(partial_T *pt) |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3930 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3931 int i; |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3932 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3933 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
|
3934 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
|
3935 vim_free(pt->pt_argv); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3936 dict_unref(pt->pt_dict); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3937 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3938 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3939 func_unref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3940 vim_free(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3941 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3942 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3943 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
|
3944 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3945 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
|
3946 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3947 // Decrease the reference count for the context of a closure. If down |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3948 // to zero free it and clear the variables on the stack. |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3949 if (--pt->pt_funcstack->fs_refcount == 0) |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3950 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3951 garray_T *gap = &pt->pt_funcstack->fs_ga; |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3952 typval_T *stack = gap->ga_data; |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3953 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3954 for (i = 0; i < gap->ga_len; ++i) |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3955 clear_tv(stack + i); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3956 ga_clear(gap); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3957 vim_free(pt->pt_funcstack); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3958 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3959 pt->pt_funcstack = NULL; |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3960 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3961 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3962 vim_free(pt); |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3963 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3964 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3965 /* |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3966 * 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
|
3967 * becomes zero. |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3968 */ |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3969 void |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3970 partial_unref(partial_T *pt) |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3971 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3972 if (pt != NULL && --pt->pt_refcount <= 0) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3973 partial_free(pt); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3974 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3975 |
80 | 3976 /* |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3977 * Return the next (unique) copy ID. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3978 * Used for serializing nested structures. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3979 */ |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3980 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3981 get_copyID(void) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3982 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3983 current_copyID += COPYID_INC; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3984 return current_copyID; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3985 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3986 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3987 /* |
371 | 3988 * Garbage collection for lists and dictionaries. |
3989 * | |
3990 * We use reference counts to be able to free most items right away when they | |
3991 * are no longer used. But for composite items it's possible that it becomes | |
3992 * unused while the reference count is > 0: When there is a recursive | |
3993 * reference. Example: | |
3994 * :let l = [1, 2, 3] | |
3995 * :let d = {9: l} | |
3996 * :let l[1] = d | |
3997 * | |
3998 * Since this is quite unusual we handle this with garbage collection: every | |
3999 * once in a while find out which lists and dicts are not referenced from any | |
4000 * variable. | |
4001 * | |
4002 * Here is a good reference text about garbage collection (refers to Python | |
4003 * but it applies to all reference-counting mechanisms): | |
4004 * http://python.ca/nas/python/gc/ | |
4005 */ | |
4006 | |
4007 /* | |
4008 * 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
|
4009 * When "testing" is TRUE this is called from test_garbagecollect_now(). |
371 | 4010 * Return TRUE if some memory was freed. |
4011 */ | |
4012 int | |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
4013 garbage_collect(int testing) |
371 | 4014 { |
1891 | 4015 int copyID; |
6565 | 4016 int abort = FALSE; |
371 | 4017 buf_T *buf; |
4018 win_T *wp; | |
6588 | 4019 int did_free = FALSE; |
819 | 4020 tabpage_T *tp; |
371 | 4021 |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
4022 if (!testing) |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
4023 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4024 // Only do this once. |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
4025 want_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
4026 may_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
4027 garbage_collect_at_exit = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
4028 } |
958 | 4029 |
19001
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
4030 // 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
|
4031 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
|
4032 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
4033 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
|
4034 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
|
4035 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
|
4036 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
4037 // 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
|
4038 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
|
4039 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
|
4040 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
|
4041 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
4042 // 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
|
4043 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
|
4044 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
4045 new_len = exestack.ga_itemsize * (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
|
4046 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
|
4047 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
|
4048 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
|
4049 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
|
4050 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
|
4051 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
4052 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
4053 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4054 // 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
|
4055 // previous_funccal. |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4056 copyID = get_copyID(); |
1891 | 4057 |
371 | 4058 /* |
4059 * 1. Go through all accessible variables and mark all lists and dicts | |
4060 * with copyID. | |
4061 */ | |
1891 | 4062 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4063 // 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
|
4064 // 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
|
4065 // 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
|
4066 abort = abort || set_ref_in_previous_funccal(copyID); |
1891 | 4067 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4068 // 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
|
4069 abort = abort || garbage_collect_scriptvars(copyID); |
371 | 4070 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4071 // buffer-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
4072 FOR_ALL_BUFFERS(buf) |
6565 | 4073 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID, |
4074 NULL, NULL); | |
371 | 4075 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4076 // window-local variables |
819 | 4077 FOR_ALL_TAB_WINDOWS(tp, wp) |
6565 | 4078 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, |
4079 NULL, NULL); | |
4309 | 4080 if (aucmd_win != NULL) |
6565 | 4081 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID, |
4082 NULL, NULL); | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
4083 #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
|
4084 FOR_ALL_POPUPWINS(wp) |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
4085 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
|
4086 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
4087 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
|
4088 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
|
4089 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
|
4090 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
4091 #endif |
371 | 4092 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4093 // tabpage-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
4094 FOR_ALL_TABPAGES(tp) |
6565 | 4095 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, |
4096 NULL, NULL); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4097 // 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
|
4098 abort = abort || garbage_collect_globvars(copyID); |
371 | 4099 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4100 // function-local variables |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4101 abort = abort || set_ref_in_call_stack(copyID); |
371 | 4102 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4103 // named functions (matters for closures) |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
4104 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
|
4105 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4106 // 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
|
4107 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
|
4108 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4109 // 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
|
4110 abort = abort || garbage_collect_vimvars(copyID); |
1733 | 4111 |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4112 // callbacks in buffers |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4113 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
|
4114 |
3450 | 4115 #ifdef FEAT_LUA |
6565 | 4116 abort = abort || set_ref_in_lua(copyID); |
3450 | 4117 #endif |
4118 | |
3618 | 4119 #ifdef FEAT_PYTHON |
6565 | 4120 abort = abort || set_ref_in_python(copyID); |
3618 | 4121 #endif |
4122 | |
4123 #ifdef FEAT_PYTHON3 | |
6565 | 4124 abort = abort || set_ref_in_python3(copyID); |
4125 #endif | |
4126 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4127 #ifdef FEAT_JOB_CHANNEL |
8877
50e40f322e78
commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents:
8870
diff
changeset
|
4128 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
|
4129 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
|
4130 #endif |
9052
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
4131 #ifdef FEAT_NETBEANS_INTG |
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
4132 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
|
4133 #endif |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7895
diff
changeset
|
4134 |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
4135 #ifdef FEAT_TIMERS |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
4136 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
|
4137 #endif |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
4138 |
11412
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
4139 #ifdef FEAT_QUICKFIX |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
4140 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
|
4141 #endif |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
4142 |
11804
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
4143 #ifdef FEAT_TERMINAL |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
4144 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
|
4145 #endif |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
4146 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
4147 #ifdef FEAT_PROP_POPUP |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4148 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
|
4149 #endif |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4150 |
6565 | 4151 if (!abort) |
4152 { | |
4153 /* | |
4154 * 2. Free lists and dictionaries that are not referenced. | |
4155 */ | |
4156 did_free = free_unref_items(copyID); | |
4157 | |
4158 /* | |
4159 * 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
|
4160 * This may call us back recursively. |
6565 | 4161 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4162 free_unref_funccal(copyID, testing); |
6565 | 4163 } |
4164 else if (p_verbose > 0) | |
4165 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4166 verb_msg(_("Not enough memory to set references, garbage collection aborted!")); |
6565 | 4167 } |
1891 | 4168 |
4169 return did_free; | |
4170 } | |
4171 | |
4172 /* | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4173 * Free lists, dictionaries, channels and jobs that are no longer referenced. |
1891 | 4174 */ |
4175 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4176 free_unref_items(int copyID) |
1891 | 4177 { |
4178 int did_free = FALSE; | |
4179 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4180 // 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
|
4181 // 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
|
4182 // do that here. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4183 in_free_unref_items = TRUE; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4184 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4185 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4186 * 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
|
4187 * 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
|
4188 */ |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4189 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4190 // 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
|
4191 did_free |= dict_free_nonref(copyID); |
371 | 4192 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4193 // 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
|
4194 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
|
4195 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4196 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4197 // 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
|
4198 // 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
|
4199 // 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
|
4200 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
|
4201 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4202 // 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
|
4203 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
|
4204 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4205 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4206 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4207 * PASS 2: free the items themselves. |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4208 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4209 dict_free_items(copyID); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
9556
diff
changeset
|
4210 list_free_items(copyID); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4211 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4212 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4213 // 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
|
4214 // 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
|
4215 // 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
|
4216 free_unused_jobs(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4217 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4218 // 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
|
4219 free_unused_channels(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4220 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4221 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4222 in_free_unref_items = FALSE; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4223 |
371 | 4224 return did_free; |
4225 } | |
4226 | |
4227 /* | |
4228 * Mark all lists and dicts referenced through hashtab "ht" with "copyID". | |
6565 | 4229 * "list_stack" is used to add lists to be marked. Can be NULL. |
4230 * | |
4231 * Returns TRUE if setting references failed somehow. | |
4232 */ | |
4233 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4234 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack) |
364 | 4235 { |
4236 int todo; | |
6565 | 4237 int abort = FALSE; |
364 | 4238 hashitem_T *hi; |
6565 | 4239 hashtab_T *cur_ht; |
4240 ht_stack_T *ht_stack = NULL; | |
4241 ht_stack_T *tempitem; | |
4242 | |
4243 cur_ht = ht; | |
4244 for (;;) | |
4245 { | |
4246 if (!abort) | |
4247 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4248 // 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
|
4249 // 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
|
4250 // list_stack. |
6565 | 4251 todo = (int)cur_ht->ht_used; |
4252 for (hi = cur_ht->ht_array; todo > 0; ++hi) | |
4253 if (!HASHITEM_EMPTY(hi)) | |
4254 { | |
4255 --todo; | |
4256 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID, | |
4257 &ht_stack, list_stack); | |
4258 } | |
4259 } | |
4260 | |
4261 if (ht_stack == NULL) | |
4262 break; | |
4263 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4264 // take an item from the stack |
6565 | 4265 cur_ht = ht_stack->ht; |
4266 tempitem = ht_stack; | |
4267 ht_stack = ht_stack->prev; | |
4268 free(tempitem); | |
4269 } | |
4270 | |
4271 return abort; | |
371 | 4272 } |
4273 | |
4274 /* | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4275 * 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
|
4276 * 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
|
4277 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4278 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4279 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
|
4280 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4281 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
|
4282 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4283 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
|
4284 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
|
4285 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4286 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
|
4287 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4288 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4289 /* |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4290 * 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
|
4291 * 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
|
4292 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4293 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4294 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
|
4295 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4296 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
|
4297 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4298 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
|
4299 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
|
4300 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4301 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
|
4302 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4303 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4304 /* |
371 | 4305 * Mark all lists and dicts referenced through list "l" with "copyID". |
6565 | 4306 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. |
4307 * | |
4308 * Returns TRUE if setting references failed somehow. | |
4309 */ | |
4310 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
|
4311 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack) |
6565 | 4312 { |
4313 listitem_T *li; | |
4314 int abort = FALSE; | |
4315 list_T *cur_l; | |
4316 list_stack_T *list_stack = NULL; | |
4317 list_stack_T *tempitem; | |
4318 | |
4319 cur_l = l; | |
4320 for (;;) | |
4321 { | |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
4322 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
|
4323 // 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
|
4324 // 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
|
4325 // list_stack. |
6565 | 4326 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next) |
4327 abort = abort || set_ref_in_item(&li->li_tv, copyID, | |
4328 ht_stack, &list_stack); | |
4329 if (list_stack == NULL) | |
4330 break; | |
4331 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4332 // take an item from the stack |
6565 | 4333 cur_l = list_stack->list; |
4334 tempitem = list_stack; | |
4335 list_stack = list_stack->prev; | |
4336 free(tempitem); | |
4337 } | |
4338 | |
4339 return abort; | |
371 | 4340 } |
4341 | |
4342 /* | |
4343 * Mark all lists and dicts referenced through typval "tv" with "copyID". | |
6565 | 4344 * "list_stack" is used to add lists to be marked. Can be NULL. |
4345 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. | |
4346 * | |
4347 * Returns TRUE if setting references failed somehow. | |
4348 */ | |
4349 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4350 set_ref_in_item( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4351 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4352 int copyID, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4353 ht_stack_T **ht_stack, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4354 list_stack_T **list_stack) |
364 | 4355 { |
6565 | 4356 int abort = FALSE; |
364 | 4357 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4358 if (tv->v_type == VAR_DICT) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4359 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4360 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
|
4361 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4362 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
|
4363 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4364 // 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
|
4365 dd->dv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4366 if (ht_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4367 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4368 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
|
4369 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4370 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4371 { |
21915
2559dc02bd64
patch 8.2.1507: using malloc() directly
Bram Moolenaar <Bram@vim.org>
parents:
21899
diff
changeset
|
4372 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
|
4373 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4374 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4375 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4376 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4377 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4378 newitem->ht = &dd->dv_hashtab; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4379 newitem->prev = *ht_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4380 *ht_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4381 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4382 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4383 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4384 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4385 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
|
4386 { |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4387 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
|
4388 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4389 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
|
4390 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4391 // 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
|
4392 ll->lv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4393 if (list_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4394 { |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4395 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
|
4396 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4397 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4398 { |
21915
2559dc02bd64
patch 8.2.1507: using malloc() directly
Bram Moolenaar <Bram@vim.org>
parents:
21899
diff
changeset
|
4399 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
|
4400 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4401 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4402 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4403 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4404 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4405 newitem->list = ll; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4406 newitem->prev = *list_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4407 *list_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4408 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4409 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4410 } |
6565 | 4411 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4412 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
|
4413 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4414 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
|
4415 } |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4416 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
|
4417 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4418 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
|
4419 int i; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4420 |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4421 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
|
4422 { |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4423 // 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
|
4424 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
|
4425 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4426 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
|
4427 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4428 if (pt->pt_dict != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4429 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4430 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4431 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4432 dtv.v_type = VAR_DICT; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4433 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
|
4434 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
|
4435 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4436 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4437 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
|
4438 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
|
4439 ht_stack, list_stack); |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4440 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
|
4441 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4442 typval_T *stack = pt->pt_funcstack->fs_ga.ga_data; |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4443 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4444 for (i = 0; i < pt->pt_funcstack->fs_ga.ga_len; ++i) |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4445 abort = abort || set_ref_in_item(stack + i, copyID, |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4446 ht_stack, list_stack); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4447 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4448 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4449 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4450 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4451 #ifdef FEAT_JOB_CHANNEL |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4452 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
|
4453 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4454 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
|
4455 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4456 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4457 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
|
4458 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4459 job->jv_copyID = copyID; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4460 if (job->jv_channel != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4461 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4462 dtv.v_type = VAR_CHANNEL; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4463 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
|
4464 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
|
4465 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4466 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
|
4467 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4468 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
|
4469 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
|
4470 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
|
4471 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4472 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4473 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4474 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
|
4475 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4476 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
|
4477 ch_part_T part; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4478 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4479 jsonq_T *jq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4480 cbq_T *cq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4481 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4482 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
|
4483 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4484 ch->ch_copyID = copyID; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10235
diff
changeset
|
4485 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
|
4486 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4487 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
|
4488 jq = jq->jq_next) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4489 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
|
4490 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
|
4491 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
|
4492 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
|
4493 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4494 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
|
4495 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
|
4496 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
|
4497 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4498 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
|
4499 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4500 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
|
4501 dtv.vval.v_partial = |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4502 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
|
4503 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
|
4504 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4505 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4506 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
|
4507 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4508 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
|
4509 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
|
4510 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
|
4511 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4512 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
|
4513 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4514 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
|
4515 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
|
4516 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
|
4517 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4518 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4519 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4520 #endif |
6565 | 4521 return abort; |
364 | 4522 } |
4523 | |
100 | 4524 /* |
56 | 4525 * Return a string with the string representation of a variable. |
4526 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
80 | 4527 * "numbuf" is used for a number. |
634 | 4528 * 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
|
4529 * When both "echo_style" and "composite_val" are FALSE, put quotes around |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4530 * stings as "string()", otherwise does not put quotes around strings, as |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4531 * ":echo" displays values. |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4532 * 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
|
4533 * are replaced with "...". |
1360 | 4534 * May return NULL. |
56 | 4535 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4536 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4537 echo_string_core( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4538 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4539 char_u **tofree, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4540 char_u *numbuf, |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4541 int copyID, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4542 int echo_style, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4543 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
|
4544 int composite_val) |
56 | 4545 { |
104 | 4546 static int recurse = 0; |
4547 char_u *r = NULL; | |
4548 | |
137 | 4549 if (recurse >= DICT_MAXNEST) |
104 | 4550 { |
5973 | 4551 if (!did_echo_string_emsg) |
4552 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4553 // 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
|
4554 // 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
|
4555 // and dicts. |
5973 | 4556 did_echo_string_emsg = TRUE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
4557 emsg(_("E724: variable nested too deep for displaying")); |
5973 | 4558 } |
104 | 4559 *tofree = NULL; |
5973 | 4560 return (char_u *)"{E724}"; |
104 | 4561 } |
4562 ++recurse; | |
4563 | |
56 | 4564 switch (tv->v_type) |
4565 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4566 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
|
4567 if (echo_style && !composite_val) |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4568 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4569 *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
|
4570 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
|
4571 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
|
4572 r = (char_u *)""; |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4573 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4574 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4575 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4576 *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
|
4577 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4578 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4579 break; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4580 |
56 | 4581 case VAR_FUNC: |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4582 if (echo_style) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4583 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4584 *tofree = NULL; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4585 r = tv->vval.v_string; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4586 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4587 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4588 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4589 *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
|
4590 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4591 } |
104 | 4592 break; |
634 | 4593 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4594 case VAR_PARTIAL: |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4595 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4596 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
|
4597 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
|
4598 : partial_name(pt), FALSE); |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4599 garray_T ga; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4600 int i; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4601 char_u *tf; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4602 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4603 ga_init2(&ga, 1, 100); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4604 ga_concat(&ga, (char_u *)"function("); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4605 if (fname != NULL) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4606 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4607 ga_concat(&ga, fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4608 vim_free(fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4609 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4610 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
|
4611 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4612 ga_concat(&ga, (char_u *)", ["); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4613 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
|
4614 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4615 if (i > 0) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4616 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4617 ga_concat(&ga, |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4618 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
|
4619 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4620 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4621 ga_concat(&ga, (char_u *)"]"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4622 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4623 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
|
4624 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4625 typval_T dtv; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4626 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4627 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4628 dtv.v_type = VAR_DICT; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4629 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
|
4630 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
|
4631 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4632 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4633 ga_concat(&ga, (char_u *)")"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4634 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4635 *tofree = ga.ga_data; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4636 r = *tofree; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4637 break; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4638 } |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4639 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4640 case VAR_BLOB: |
15466
435fcefd2c8e
patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15464
diff
changeset
|
4641 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
|
4642 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4643 |
56 | 4644 case VAR_LIST: |
634 | 4645 if (tv->vval.v_list == NULL) |
4646 { | |
20126
831b1ea43020
patch 8.2.0618: echoing a null list results in no output
Bram Moolenaar <Bram@vim.org>
parents:
20111
diff
changeset
|
4647 // NULL list is equivalent to empty list. |
634 | 4648 *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
|
4649 r = (char_u *)"[]"; |
634 | 4650 } |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4651 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
|
4652 && tv->vval.v_list->lv_len > 0) |
634 | 4653 { |
4654 *tofree = NULL; | |
4655 r = (char_u *)"[...]"; | |
4656 } | |
4657 else | |
4658 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4659 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
|
4660 |
634 | 4661 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
|
4662 *tofree = list2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4663 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4664 tv->vval.v_list->lv_copyID = old_copyID; |
634 | 4665 r = *tofree; |
4666 } | |
4667 break; | |
4668 | |
100 | 4669 case VAR_DICT: |
634 | 4670 if (tv->vval.v_dict == NULL) |
4671 { | |
20128
0b35a7ffceb2
patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents:
20126
diff
changeset
|
4672 // NULL dict is equivalent to empty dict. |
634 | 4673 *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
|
4674 r = (char_u *)"{}"; |
634 | 4675 } |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4676 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
|
4677 && tv->vval.v_dict->dv_hashtab.ht_used != 0) |
634 | 4678 { |
4679 *tofree = NULL; | |
4680 r = (char_u *)"{...}"; | |
4681 } | |
4682 else | |
4683 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4684 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
|
4685 |
634 | 4686 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
|
4687 *tofree = dict2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4688 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4689 tv->vval.v_dict->dv_copyID = old_copyID; |
634 | 4690 r = *tofree; |
4691 } | |
4692 break; | |
4693 | |
71 | 4694 case VAR_NUMBER: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4695 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
|
4696 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
|
4697 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
|
4698 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4699 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
|
4700 break; |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4701 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4702 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
4703 case VAR_CHANNEL: |
104 | 4704 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4705 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
|
4706 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
|
4707 { |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4708 *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
|
4709 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
|
4710 } |
71 | 4711 break; |
634 | 4712 |
1624 | 4713 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4714 #ifdef FEAT_FLOAT |
1624 | 4715 *tofree = NULL; |
4716 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float); | |
4717 r = numbuf; | |
4718 break; | |
4719 #endif | |
4720 | |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
4721 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4722 case VAR_SPECIAL: |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4723 *tofree = NULL; |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
4724 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
|
4725 break; |
104 | 4726 } |
4727 | |
5973 | 4728 if (--recurse == 0) |
4729 did_echo_string_emsg = FALSE; | |
104 | 4730 return r; |
97 | 4731 } |
4732 | |
4733 /* | |
4734 * Return a string with the string representation of a variable. | |
4735 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
4736 * "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
|
4737 * 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
|
4738 * 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
|
4739 * May return NULL. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4740 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4741 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4742 echo_string( |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4743 typval_T *tv, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4744 char_u **tofree, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4745 char_u *numbuf, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4746 int copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4747 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4748 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
|
4749 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4750 |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4751 /* |
137 | 4752 * Return string "str" in ' quotes, doubling ' characters. |
4753 * If "str" is NULL an empty string is assumed. | |
100 | 4754 * If "function" is TRUE make it function('string'). |
97 | 4755 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4756 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4757 string_quote(char_u *str, int function) |
97 | 4758 { |
137 | 4759 unsigned len; |
97 | 4760 char_u *p, *r, *s; |
4761 | |
137 | 4762 len = (function ? 13 : 3); |
4763 if (str != NULL) | |
4764 { | |
835 | 4765 len += (unsigned)STRLEN(str); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
4766 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
137 | 4767 if (*p == '\'') |
4768 ++len; | |
4769 } | |
97 | 4770 s = r = alloc(len); |
4771 if (r != NULL) | |
4772 { | |
4773 if (function) | |
4774 { | |
100 | 4775 STRCPY(r, "function('"); |
97 | 4776 r += 10; |
4777 } | |
4778 else | |
100 | 4779 *r++ = '\''; |
137 | 4780 if (str != NULL) |
4781 for (p = str; *p != NUL; ) | |
4782 { | |
4783 if (*p == '\'') | |
4784 *r++ = '\''; | |
4785 MB_COPY_CHAR(p, r); | |
4786 } | |
100 | 4787 *r++ = '\''; |
97 | 4788 if (function) |
4789 *r++ = ')'; | |
4790 *r++ = NUL; | |
4791 } | |
4792 return s; | |
4793 } | |
4794 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4795 #if defined(FEAT_FLOAT) || defined(PROTO) |
1624 | 4796 /* |
4797 * Convert the string "text" to a floating point number. | |
4798 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure | |
4799 * this always uses a decimal point. | |
4800 * Returns the length of the text that was consumed. | |
4801 */ | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4802 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4803 string2float( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4804 char_u *text, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4805 float_T *value) // result stored here |
1624 | 4806 { |
4807 char *s = (char *)text; | |
4808 float_T f; | |
4809 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4810 // MS-Windows does not deal with "inf" and "nan" properly. |
10536
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4811 if (STRNICMP(text, "inf", 3) == 0) |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4812 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4813 *value = INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4814 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4815 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4816 if (STRNICMP(text, "-inf", 3) == 0) |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4817 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4818 *value = -INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4819 return 4; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4820 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4821 if (STRNICMP(text, "nan", 3) == 0) |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4822 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4823 *value = NAN; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4824 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4825 } |
1624 | 4826 f = strtod(s, &s); |
4827 *value = f; | |
4828 return (int)((char_u *)s - text); | |
4829 } | |
4830 #endif | |
4831 | |
97 | 4832 /* |
7 | 4833 * Translate a String variable into a position. |
685 | 4834 * Returns NULL when there is an error. |
7 | 4835 */ |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4836 pos_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4837 var2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4838 typval_T *varp, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4839 int dollar_lnum, // TRUE when $ is last line |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4840 int *fnum) // set to fnum for '0, 'A, etc. |
7 | 4841 { |
700 | 4842 char_u *name; |
7 | 4843 static pos_T pos; |
700 | 4844 pos_T *pp; |
7 | 4845 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4846 // Argument can be [lnum, col, coladd]. |
685 | 4847 if (varp->v_type == VAR_LIST) |
4848 { | |
4849 list_T *l; | |
4850 int len; | |
705 | 4851 int error = FALSE; |
1317 | 4852 listitem_T *li; |
685 | 4853 |
4854 l = varp->vval.v_list; | |
4855 if (l == NULL) | |
4856 return NULL; | |
4857 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4858 // Get the line number |
705 | 4859 pos.lnum = list_find_nr(l, 0L, &error); |
4860 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
|
4861 return NULL; // invalid line number |
21899
8fe86125dcba
patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents:
21889
diff
changeset
|
4862 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
|
4863 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4864 // Get the column number |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4865 // We accept "$" for the column number: last column. |
1317 | 4866 li = list_find(l, 1L); |
4867 if (li != NULL && li->li_tv.v_type == VAR_STRING | |
4868 && li->li_tv.vval.v_string != NULL | |
4869 && 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
|
4870 { |
1317 | 4871 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
|
4872 } |
8fe86125dcba
patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents:
21889
diff
changeset
|
4873 else |
8fe86125dcba
patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents:
21889
diff
changeset
|
4874 { |
8fe86125dcba
patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents:
21889
diff
changeset
|
4875 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
|
4876 if (error) |
8fe86125dcba
patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents:
21889
diff
changeset
|
4877 return NULL; |
8fe86125dcba
patch 8.2.1499: Vim9: error when using "$" with col()
Bram Moolenaar <Bram@vim.org>
parents:
21889
diff
changeset
|
4878 } |
1317 | 4879 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4880 // Accept a position up to the NUL after the line. |
826 | 4881 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
|
4882 return NULL; // invalid column number |
705 | 4883 --pos.col; |
4884 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4885 // Get the virtual offset. Defaults to zero. |
705 | 4886 pos.coladd = list_find_nr(l, 2L, &error); |
4887 if (error) | |
4888 pos.coladd = 0; | |
4889 | |
685 | 4890 return &pos; |
4891 } | |
4892 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4893 name = tv_get_string_chk(varp); |
323 | 4894 if (name == NULL) |
4895 return NULL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4896 if (name[0] == '.') // cursor |
7 | 4897 return &curwin->w_cursor; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4898 if (name[0] == 'v' && name[1] == NUL) // Visual start |
1609 | 4899 { |
4900 if (VIsual_active) | |
4901 return &VIsual; | |
4902 return &curwin->w_cursor; | |
4903 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4904 if (name[0] == '\'') // mark |
7 | 4905 { |
4043 | 4906 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); |
7 | 4907 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) |
4908 return NULL; | |
4909 return pp; | |
4910 } | |
705 | 4911 |
4912 pos.coladd = 0; | |
4913 | |
1317 | 4914 if (name[0] == 'w' && dollar_lnum) |
666 | 4915 { |
4916 pos.col = 0; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4917 if (name[1] == '0') // "w0": first visible line |
666 | 4918 { |
671 | 4919 update_topline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4920 // 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
|
4921 // 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
|
4922 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; |
666 | 4923 return &pos; |
4924 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4925 else if (name[1] == '$') // "w$": last visible line |
666 | 4926 { |
671 | 4927 validate_botline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4928 // 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
|
4929 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; |
666 | 4930 return &pos; |
4931 } | |
4932 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4933 else if (name[0] == '$') // last column or line |
7 | 4934 { |
1317 | 4935 if (dollar_lnum) |
7 | 4936 { |
4937 pos.lnum = curbuf->b_ml.ml_line_count; | |
4938 pos.col = 0; | |
4939 } | |
4940 else | |
4941 { | |
4942 pos.lnum = curwin->w_cursor.lnum; | |
4943 pos.col = (colnr_T)STRLEN(ml_get_curline()); | |
4944 } | |
4945 return &pos; | |
4946 } | |
4947 return NULL; | |
4948 } | |
4949 | |
4950 /* | |
709 | 4951 * Convert list in "arg" into a position and optional file number. |
4952 * When "fnump" is NULL there is no file number, only 3 items. | |
4953 * Note that the column is passed on as-is, the caller may want to decrement | |
4954 * it to use 1 for the first column. | |
4955 * Return FAIL when conversion is not possible, doesn't check the position for | |
4956 * validity. | |
4957 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4958 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4959 list2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4960 typval_T *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4961 pos_T *posp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4962 int *fnump, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4963 colnr_T *curswantp) |
709 | 4964 { |
4965 list_T *l = arg->vval.v_list; | |
4966 long i = 0; | |
4967 long n; | |
4968 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4969 // 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
|
4970 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional. |
915 | 4971 if (arg->v_type != VAR_LIST |
4972 || l == NULL | |
4973 || l->lv_len < (fnump == NULL ? 2 : 3) | |
5938 | 4974 || l->lv_len > (fnump == NULL ? 4 : 5)) |
709 | 4975 return FAIL; |
4976 | |
4977 if (fnump != NULL) | |
4978 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4979 n = list_find_nr(l, i++, NULL); // fnum |
709 | 4980 if (n < 0) |
4981 return FAIL; | |
4982 if (n == 0) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4983 n = curbuf->b_fnum; // current buffer |
709 | 4984 *fnump = n; |
4985 } | |
4986 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4987 n = list_find_nr(l, i++, NULL); // lnum |
709 | 4988 if (n < 0) |
4989 return FAIL; | |
4990 posp->lnum = n; | |
4991 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4992 n = list_find_nr(l, i++, NULL); // col |
709 | 4993 if (n < 0) |
4994 return FAIL; | |
4995 posp->col = n; | |
4996 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4997 n = list_find_nr(l, i, NULL); // off |
709 | 4998 if (n < 0) |
915 | 4999 posp->coladd = 0; |
5000 else | |
5001 posp->coladd = n; | |
709 | 5002 |
5938 | 5003 if (curswantp != NULL) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5004 *curswantp = list_find_nr(l, i + 1, NULL); // curswant |
5938 | 5005 |
709 | 5006 return OK; |
5007 } | |
5008 | |
5009 /* | |
7 | 5010 * Get the length of an environment variable name. |
5011 * Advance "arg" to the first character after the name. | |
5012 * Return 0 for error. | |
5013 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
5014 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5015 get_env_len(char_u **arg) |
7 | 5016 { |
5017 char_u *p; | |
5018 int len; | |
5019 | |
5020 for (p = *arg; vim_isIDc(*p); ++p) | |
5021 ; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5022 if (p == *arg) // no name found |
7 | 5023 return 0; |
5024 | |
5025 len = (int)(p - *arg); | |
5026 *arg = p; | |
5027 return len; | |
5028 } | |
5029 | |
5030 /* | |
5031 * 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
|
5032 * "arg" is advanced to after the name. |
7 | 5033 * Return 0 if something is wrong. |
5034 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5035 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5036 get_id_len(char_u **arg) |
7 | 5037 { |
5038 char_u *p; | |
5039 int len; | |
5040 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5041 // Find the end of the name. |
7 | 5042 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
|
5043 { |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5044 if (*p == ':') |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5045 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5046 // "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
|
5047 // 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
|
5048 len = (int)(p - *arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5049 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
|
5050 || len > 1) |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5051 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5052 } |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5053 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5054 if (p == *arg) // no name found |
7 | 5055 return 0; |
5056 | |
5057 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
|
5058 *arg = p; |
7 | 5059 |
5060 return len; | |
5061 } | |
5062 | |
5063 /* | |
124 | 5064 * Get the length of the name of a variable or function. |
5065 * Only the name is recognized, does not handle ".key" or "[idx]". | |
7 | 5066 * "arg" is advanced to the first non-white character after the name. |
159 | 5067 * Return -1 if curly braces expansion failed. |
5068 * Return 0 if something else is wrong. | |
7 | 5069 * If the name contains 'magic' {}'s, expand them and return the |
5070 * expanded name in an allocated string via 'alias' - caller must free. | |
5071 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
5072 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5073 get_name_len( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5074 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5075 char_u **alias, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5076 int evaluate, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5077 int verbose) |
7 | 5078 { |
5079 int len; | |
5080 char_u *p; | |
5081 char_u *expr_start; | |
5082 char_u *expr_end; | |
5083 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5084 *alias = NULL; // default to no alias |
7 | 5085 |
5086 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA | |
5087 && (*arg)[2] == (int)KE_SNR) | |
5088 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5089 // hard coded <SNR>, already translated |
7 | 5090 *arg += 3; |
5091 return get_id_len(arg) + 3; | |
5092 } | |
5093 len = eval_fname_script(*arg); | |
5094 if (len > 0) | |
5095 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5096 // literal "<SID>", "s:" or "<SNR>" |
7 | 5097 *arg += len; |
5098 } | |
5099 | |
5100 /* | |
71 | 5101 * Find the end of the name; check for {} construction. |
7 | 5102 */ |
271 | 5103 p = find_name_end(*arg, &expr_start, &expr_end, |
5104 len > 0 ? 0 : FNE_CHECK_START); | |
7 | 5105 if (expr_start != NULL) |
5106 { | |
5107 char_u *temp_string; | |
5108 | |
5109 if (!evaluate) | |
5110 { | |
5111 len += (int)(p - *arg); | |
5112 *arg = skipwhite(p); | |
5113 return len; | |
5114 } | |
5115 | |
5116 /* | |
5117 * Include any <SID> etc in the expanded string: | |
5118 * Thus the -len here. | |
5119 */ | |
5120 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p); | |
5121 if (temp_string == NULL) | |
159 | 5122 return -1; |
7 | 5123 *alias = temp_string; |
5124 *arg = skipwhite(p); | |
5125 return (int)STRLEN(temp_string); | |
5126 } | |
5127 | |
5128 len += get_id_len(arg); | |
15464
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
5129 // 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
|
5130 // reported at a higher level. |
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
5131 if (len == 0 && verbose && **arg != NUL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5132 semsg(_(e_invexpr2), *arg); |
7 | 5133 |
5134 return len; | |
5135 } | |
5136 | |
71 | 5137 /* |
5138 * Find the end of a variable or function name, taking care of magic braces. | |
5139 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the | |
5140 * start and end of the first magic braces item. | |
271 | 5141 * "flags" can have FNE_INCL_BR and FNE_CHECK_START. |
71 | 5142 * Return a pointer to just after the name. Equal to "arg" if there is no |
5143 * valid name. | |
5144 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5145 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5146 find_name_end( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5147 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5148 char_u **expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5149 char_u **expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5150 int flags) |
71 | 5151 { |
5152 int mb_nest = 0; | |
5153 int br_nest = 0; | |
7 | 5154 char_u *p; |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5155 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
|
5156 int vim9script = in_vim9script(); |
7 | 5157 |
71 | 5158 if (expr_start != NULL) |
5159 { | |
5160 *expr_start = NULL; | |
5161 *expr_end = NULL; | |
5162 } | |
5163 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5164 // 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
|
5165 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
|
5166 && (*arg != '{' || vim9script)) |
271 | 5167 return arg; |
5168 | |
71 | 5169 for (p = arg; *p != NUL |
5170 && (eval_isnamec(*p) | |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
5171 || (*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
|
5172 || ((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
|
5173 || (*p == '.' && eval_isdictc(p[1])))) |
71 | 5174 || mb_nest != 0 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
5175 || br_nest != 0); MB_PTR_ADV(p)) |
468 | 5176 { |
5177 if (*p == '\'') | |
5178 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5179 // 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
|
5180 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) |
468 | 5181 ; |
5182 if (*p == NUL) | |
5183 break; | |
5184 } | |
5185 else if (*p == '"') | |
5186 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5187 // 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
|
5188 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
468 | 5189 if (*p == '\\' && p[1] != NUL) |
5190 ++p; | |
5191 if (*p == NUL) | |
5192 break; | |
5193 } | |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5194 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
|
5195 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5196 // "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
|
5197 // 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
|
5198 len = (int)(p - arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5199 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
|
5200 || (len > 1 && p[-1] != '}')) |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5201 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5202 } |
468 | 5203 |
71 | 5204 if (mb_nest == 0) |
5205 { | |
5206 if (*p == '[') | |
5207 ++br_nest; | |
5208 else if (*p == ']') | |
5209 --br_nest; | |
5210 } | |
468 | 5211 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
5212 if (br_nest == 0 && !vim9script) |
71 | 5213 { |
5214 if (*p == '{') | |
5215 { | |
5216 mb_nest++; | |
5217 if (expr_start != NULL && *expr_start == NULL) | |
5218 *expr_start = p; | |
5219 } | |
5220 else if (*p == '}') | |
5221 { | |
5222 mb_nest--; | |
5223 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) | |
5224 *expr_end = p; | |
5225 } | |
5226 } | |
7 | 5227 } |
5228 | |
5229 return p; | |
5230 } | |
5231 | |
5232 /* | |
159 | 5233 * Expands out the 'magic' {}'s in a variable/function name. |
5234 * Note that this can call itself recursively, to deal with | |
5235 * constructs like foo{bar}{baz}{bam} | |
5236 * The four pointer arguments point to "foo{expre}ss{ion}bar" | |
5237 * "in_start" ^ | |
5238 * "expr_start" ^ | |
5239 * "expr_end" ^ | |
5240 * "in_end" ^ | |
5241 * | |
5242 * Returns a new allocated string, which the caller must free. | |
5243 * Returns NULL for failure. | |
5244 */ | |
5245 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5246 make_expanded_name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5247 char_u *in_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5248 char_u *expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5249 char_u *expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5250 char_u *in_end) |
159 | 5251 { |
5252 char_u c1; | |
5253 char_u *retval = NULL; | |
5254 char_u *temp_result; | |
5255 | |
5256 if (expr_end == NULL || in_end == NULL) | |
5257 return NULL; | |
5258 *expr_start = NUL; | |
5259 *expr_end = NUL; | |
5260 c1 = *in_end; | |
5261 *in_end = NUL; | |
5262 | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
5263 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
|
5264 if (temp_result != NULL) |
159 | 5265 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5266 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
|
5267 + (in_end - expr_end) + 1); |
159 | 5268 if (retval != NULL) |
5269 { | |
5270 STRCPY(retval, in_start); | |
5271 STRCAT(retval, temp_result); | |
5272 STRCAT(retval, expr_end + 1); | |
5273 } | |
5274 } | |
5275 vim_free(temp_result); | |
5276 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5277 *in_end = c1; // put char back for error messages |
159 | 5278 *expr_start = '{'; |
5279 *expr_end = '}'; | |
5280 | |
5281 if (retval != NULL) | |
5282 { | |
271 | 5283 temp_result = find_name_end(retval, &expr_start, &expr_end, 0); |
159 | 5284 if (expr_start != NULL) |
5285 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5286 // Further expansion! |
159 | 5287 temp_result = make_expanded_name(retval, expr_start, |
5288 expr_end, temp_result); | |
5289 vim_free(retval); | |
5290 retval = temp_result; | |
5291 } | |
5292 } | |
5293 | |
5294 return retval; | |
5295 } | |
5296 | |
5297 /* | |
7 | 5298 * Return TRUE if character "c" can be used in a variable or function name. |
104 | 5299 * Does not include '{' or '}' for magic braces. |
7 | 5300 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5301 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5302 eval_isnamec(int c) |
7 | 5303 { |
21512
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5304 return ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR; |
271 | 5305 } |
5306 | |
5307 /* | |
5308 * Return TRUE if character "c" can be used as the first character in a | |
5309 * variable or function name (excluding '{' and '}'). | |
5310 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5311 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5312 eval_isnamec1(int c) |
271 | 5313 { |
21512
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5314 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
|
5315 } |
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5316 |
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5317 /* |
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5318 * 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
|
5319 * 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
|
5320 */ |
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5321 int |
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5322 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
|
5323 { |
81c47a694479
patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
5324 return ASCII_ISALNUM(c) || c == '_'; |
7 | 5325 } |
5326 | |
5327 /* | |
21823
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5328 * Return the character "str[index]" where "index" is the character index. If |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5329 * "index" is out of range NULL is returned. |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5330 */ |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5331 char_u * |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5332 char_from_string(char_u *str, varnumber_T index) |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5333 { |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5334 size_t nbyte = 0; |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5335 varnumber_T nchar = index; |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5336 size_t slen; |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5337 |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5338 if (str == NULL || index < 0) |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5339 return NULL; |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5340 slen = STRLEN(str); |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5341 while (nchar > 0 && nbyte < slen) |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5342 { |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5343 nbyte += MB_CPTR2LEN(str + nbyte); |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5344 --nchar; |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5345 } |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5346 if (nbyte >= slen) |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5347 return NULL; |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5348 return vim_strnsave(str + nbyte, MB_CPTR2LEN(str + nbyte)); |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5349 } |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5350 |
b1f3d8a44ab6
patch 8.2.1461: Vim9: string indexes are counted in bytes
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5351 /* |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5352 * Get the byte index for character index "idx" in string "str" with length |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5353 * "str_len". |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5354 * If going over the end return "str_len". |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5355 * If "idx" is negative count from the end, -1 is the last character. |
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
|
5356 * When going over the start return -1. |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5357 */ |
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
|
5358 static long |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5359 char_idx2byte(char_u *str, size_t str_len, varnumber_T idx) |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5360 { |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5361 varnumber_T nchar = idx; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5362 size_t nbyte = 0; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5363 |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5364 if (nchar >= 0) |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5365 { |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5366 while (nchar > 0 && nbyte < str_len) |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5367 { |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5368 nbyte += MB_CPTR2LEN(str + nbyte); |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5369 --nchar; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5370 } |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5371 } |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5372 else |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5373 { |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5374 nbyte = str_len; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5375 while (nchar < 0 && nbyte > 0) |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5376 { |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5377 --nbyte; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5378 nbyte -= mb_head_off(str, str + nbyte); |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5379 ++nchar; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5380 } |
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
|
5381 if (nchar < 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
|
5382 return -1; |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5383 } |
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
|
5384 return (long)nbyte; |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5385 } |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5386 |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5387 /* |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5388 * Return the slice "str[first:last]" using character indexes. |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5389 * Return NULL when the result is empty. |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5390 */ |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5391 char_u * |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5392 string_slice(char_u *str, varnumber_T first, varnumber_T last) |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5393 { |
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
|
5394 long start_byte, end_byte; |
e3f9528bddda
patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
5395 size_t slen; |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5396 |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5397 if (str == NULL) |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5398 return NULL; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5399 slen = STRLEN(str); |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5400 start_byte = char_idx2byte(str, slen, first); |
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
|
5401 if (start_byte < 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
|
5402 start_byte = 0; // first index very negative: use zero |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5403 if (last == -1) |
21965
ddfb5f5b2ce5
patch 8.2.1532: compiler warning for conversion of size_t to long
Bram Moolenaar <Bram@vim.org>
parents:
21949
diff
changeset
|
5404 end_byte = (long)slen; |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5405 else |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5406 { |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5407 end_byte = char_idx2byte(str, slen, last); |
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
|
5408 if (end_byte >= 0 && end_byte < (long)slen) |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5409 // end index is inclusive |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5410 end_byte += MB_CPTR2LEN(str + end_byte); |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5411 } |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5412 |
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
|
5413 if (start_byte >= (long)slen || end_byte <= start_byte) |
21826
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5414 return NULL; |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5415 return vim_strnsave(str + start_byte, end_byte - start_byte); |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5416 } |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5417 |
ccad66ac6c3e
patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21823
diff
changeset
|
5418 /* |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5419 * Handle: |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5420 * - 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
|
5421 * - ".name" lookup |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5422 * - 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
|
5423 * - method call: var->method() |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5424 * |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5425 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len() |
159 | 5426 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5427 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5428 handle_subscript( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5429 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5430 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
|
5431 evalarg_T *evalarg, |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
5432 int verbose) // give error messages |
159 | 5433 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
5434 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
|
5435 && (evalarg->eval_flags & EVAL_EVALUATE); |
159 | 5436 int ret = OK; |
5437 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
|
5438 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
|
5439 int getnext; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5440 char_u *p; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5441 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5442 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
|
5443 { |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5444 // 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
|
5445 // 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
|
5446 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
|
5447 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
|
5448 && ((rettv->v_type == VAR_DICT && *p == '.' && eval_isdictc(p[1])) |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
5449 || (p[0] == '-' && p[1] == '>' |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5450 && (p[2] == '{' || ASCII_ISALPHA(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
|
5451 { |
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
5452 *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
|
5453 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
|
5454 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
|
5455 } |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5456 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5457 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
|
5458 || 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
|
5459 && (!check_white || !VIM_ISWHITE(*(*arg - 1)))) |
159 | 5460 { |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
5461 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
|
5462 selfdict, NULL); |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5463 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5464 // 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
|
5465 // 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
|
5466 // but not caught. |
159 | 5467 if (aborting()) |
5468 { | |
5469 if (ret == OK) | |
5470 clear_tv(rettv); | |
5471 ret = FAIL; | |
5472 } | |
5473 dict_unref(selfdict); | |
5474 selfdict = NULL; | |
5475 } | |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
5476 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
|
5477 { |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
5478 *arg = p; |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5479 if (ret == OK) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5480 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5481 if ((*arg)[2] == '{') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5482 // 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
|
5483 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
|
5484 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5485 // 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
|
5486 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
|
5487 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5488 } |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5489 // "." 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
|
5490 // 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
|
5491 else if (**arg == '[' |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5492 || (**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
|
5493 || (!evaluate |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5494 && (*arg)[1] != '.' |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5495 && current_sctx.sc_version >= 2)))) |
159 | 5496 { |
5497 dict_unref(selfdict); | |
5498 if (rettv->v_type == VAR_DICT) | |
5499 { | |
5500 selfdict = rettv->vval.v_dict; | |
5501 if (selfdict != NULL) | |
5502 ++selfdict->dv_refcount; | |
5503 } | |
5504 else | |
5505 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
|
5506 if (eval_index(arg, rettv, evalarg, verbose) == FAIL) |
159 | 5507 { |
5508 clear_tv(rettv); | |
5509 ret = FAIL; | |
5510 } | |
5511 } | |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5512 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5513 break; |
159 | 5514 } |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5515 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5516 // 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
|
5517 // 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
|
5518 // explicitly (pt_auto is FALSE). |
9104
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5519 if (selfdict != NULL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5520 && (rettv->v_type == VAR_FUNC |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5521 || (rettv->v_type == VAR_PARTIAL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5522 && (rettv->vval.v_partial->pt_auto |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5523 || 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
|
5524 selfdict = make_partial(selfdict, rettv); |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5525 |
159 | 5526 dict_unref(selfdict); |
5527 return ret; | |
5528 } | |
5529 | |
5530 /* | |
104 | 5531 * Make a copy of an item. |
5532 * Lists and Dictionaries are also copied. A deep copy if "deep" is set. | |
165 | 5533 * For deepcopy() "copyID" is zero for a full copy or the ID for when a |
5534 * reference to an already copied list/dict can be used. | |
5535 * Returns FAIL or OK. | |
5536 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
5537 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5538 item_copy( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5539 typval_T *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5540 typval_T *to, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5541 int deep, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5542 int copyID) |
104 | 5543 { |
5544 static int recurse = 0; | |
165 | 5545 int ret = OK; |
104 | 5546 |
137 | 5547 if (recurse >= DICT_MAXNEST) |
104 | 5548 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5549 emsg(_("E698: variable nested too deep for making a copy")); |
165 | 5550 return FAIL; |
104 | 5551 } |
5552 ++recurse; | |
5553 | |
5554 switch (from->v_type) | |
5555 { | |
5556 case VAR_NUMBER: | |
1624 | 5557 case VAR_FLOAT: |
104 | 5558 case VAR_STRING: |
5559 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5560 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
|
5561 case VAR_BOOL: |
7862
d4fec9208e7e
commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5562 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5563 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5564 case VAR_CHANNEL: |
104 | 5565 copy_tv(from, to); |
5566 break; | |
5567 case VAR_LIST: | |
5568 to->v_type = VAR_LIST; | |
151 | 5569 to->v_lock = 0; |
165 | 5570 if (from->vval.v_list == NULL) |
5571 to->vval.v_list = NULL; | |
5572 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID) | |
5573 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5574 // use the copy made earlier |
165 | 5575 to->vval.v_list = from->vval.v_list->lv_copylist; |
5576 ++to->vval.v_list->lv_refcount; | |
5577 } | |
5578 else | |
5579 to->vval.v_list = list_copy(from->vval.v_list, deep, copyID); | |
5580 if (to->vval.v_list == NULL) | |
5581 ret = FAIL; | |
104 | 5582 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
|
5583 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
|
5584 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
|
5585 break; |
104 | 5586 case VAR_DICT: |
5587 to->v_type = VAR_DICT; | |
151 | 5588 to->v_lock = 0; |
165 | 5589 if (from->vval.v_dict == NULL) |
5590 to->vval.v_dict = NULL; | |
5591 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID) | |
5592 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5593 // use the copy made earlier |
165 | 5594 to->vval.v_dict = from->vval.v_dict->dv_copydict; |
5595 ++to->vval.v_dict->dv_refcount; | |
5596 } | |
5597 else | |
5598 to->vval.v_dict = dict_copy(from->vval.v_dict, deep, copyID); | |
5599 if (to->vval.v_dict == NULL) | |
5600 ret = FAIL; | |
104 | 5601 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5602 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
|
5603 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
|
5604 case VAR_VOID: |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
5605 internal_error_no_abort("item_copy(UNKNOWN)"); |
165 | 5606 ret = FAIL; |
104 | 5607 } |
5608 --recurse; | |
165 | 5609 return ret; |
104 | 5610 } |
5611 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5612 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5613 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
|
5614 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5615 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
|
5616 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
|
5617 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
|
5618 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5619 if (*atstart) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5620 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5621 *atstart = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5622 // 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
|
5623 // 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
|
5624 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
|
5625 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5626 // 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
|
5627 // 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
|
5628 // 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
|
5629 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
|
5630 msg_start(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5631 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5632 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5633 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
|
5634 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
|
5635 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5636 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
|
5637 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
|
5638 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5639 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
|
5640 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5641 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
|
5642 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5643 // 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
|
5644 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
|
5645 *needclr = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5646 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5647 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
|
5648 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5649 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5650 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5651 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
|
5652 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5653 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
|
5654 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5655 (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
|
5656 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
|
5657 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5658 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5659 (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
|
5660 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5661 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5662 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
|
5663 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5664 |
104 | 5665 /* |
7 | 5666 * ":echo expr1 ..." print each argument separated with a space, add a |
5667 * newline at the end. | |
5668 * ":echon expr1 ..." print each argument plain. | |
5669 */ | |
5670 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5671 ex_echo(exarg_T *eap) |
7 | 5672 { |
5673 char_u *arg = eap->arg; | |
137 | 5674 typval_T rettv; |
7 | 5675 char_u *p; |
5676 int needclr = TRUE; | |
5677 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
|
5678 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
|
5679 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
|
5680 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
|
5681 |
21104
f8ec5a7a9cf6
patch 8.2.1103: Coverity reports an unnecessary NULL check
Bram Moolenaar <Bram@vim.org>
parents:
21098
diff
changeset
|
5682 fill_evalarg_from_eap(&evalarg, eap, eap->skip); |
7 | 5683 |
5684 if (eap->skip) | |
5685 ++emsg_skip; | |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5686 while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int) |
7 | 5687 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5688 // 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
|
5689 // still need to be cleared. E.g., "echo 22,44". |
1624 | 5690 need_clr_eos = needclr; |
5691 | |
7 | 5692 p = 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
|
5693 if (eval1(&arg, &rettv, &evalarg) == FAIL) |
7 | 5694 { |
5695 /* | |
5696 * Report the invalid expression unless the expression evaluation | |
5697 * has been cancelled due to an aborting error, an interrupt, or an | |
5698 * exception. | |
5699 */ | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5700 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
|
5701 && called_emsg == called_emsg_before) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5702 semsg(_(e_invexpr2), p); |
1624 | 5703 need_clr_eos = FALSE; |
5704 break; | |
5705 } | |
5706 need_clr_eos = FALSE; | |
5707 | |
7 | 5708 if (!eap->skip) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5709 echo_one(&rettv, eap->cmdidx == CMD_echo, &atstart, &needclr); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5710 |
71 | 5711 clear_tv(&rettv); |
7 | 5712 arg = skipwhite(arg); |
5713 } | |
5714 eap->nextcmd = check_nextcmd(arg); | |
21050
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
5715 clear_evalarg(&evalarg, eap); |
7 | 5716 |
5717 if (eap->skip) | |
5718 --emsg_skip; | |
5719 else | |
5720 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5721 // remove text that may still be there from the command |
7 | 5722 if (needclr) |
5723 msg_clr_eos(); | |
5724 if (eap->cmdidx == CMD_echo) | |
5725 msg_end(); | |
5726 } | |
5727 } | |
5728 | |
5729 /* | |
5730 * ":echohl {name}". | |
5731 */ | |
5732 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5733 ex_echohl(exarg_T *eap) |
7 | 5734 { |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
5735 echo_attr = syn_name2attr(eap->arg); |
7 | 5736 } |
5737 | |
5738 /* | |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5739 * 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
|
5740 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5741 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5742 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
|
5743 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5744 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
|
5745 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5746 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5747 /* |
7 | 5748 * ":execute expr1 ..." execute the result of an expression. |
5749 * ":echomsg expr1 ..." Print a message | |
5750 * ":echoerr expr1 ..." Print an error | |
5751 * Each gets spaces around each argument and a newline at the end for | |
5752 * echo commands | |
5753 */ | |
5754 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5755 ex_execute(exarg_T *eap) |
7 | 5756 { |
5757 char_u *arg = eap->arg; | |
137 | 5758 typval_T rettv; |
7 | 5759 int ret = OK; |
5760 char_u *p; | |
5761 garray_T ga; | |
5762 int len; | |
5763 | |
5764 ga_init2(&ga, 1, 80); | |
5765 | |
5766 if (eap->skip) | |
5767 ++emsg_skip; | |
20061
6e6a75800884
patch 8.2.0586: Vim9: # comment not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20059
diff
changeset
|
5768 while (!ends_excmd2(eap->cmd, arg) || *arg == '"') |
7 | 5769 { |
21098
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
5770 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
|
5771 if (ret == FAIL) |
7 | 5772 break; |
5773 | |
5774 if (!eap->skip) | |
5775 { | |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5776 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
|
5777 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5778 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
|
5779 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5780 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
|
5781 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5782 emsg(_(e_inval_string)); |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5783 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
|
5784 } |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5785 else |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5786 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
|
5787 } |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5788 else |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5789 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
|
5790 if (p == NULL) |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5791 { |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5792 clear_tv(&rettv); |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5793 ret = FAIL; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5794 break; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5795 } |
7 | 5796 len = (int)STRLEN(p); |
5797 if (ga_grow(&ga, len + 2) == FAIL) | |
5798 { | |
71 | 5799 clear_tv(&rettv); |
7 | 5800 ret = FAIL; |
5801 break; | |
5802 } | |
5803 if (ga.ga_len) | |
5804 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' '; | |
5805 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p); | |
5806 ga.ga_len += len; | |
5807 } | |
5808 | |
71 | 5809 clear_tv(&rettv); |
7 | 5810 arg = skipwhite(arg); |
5811 } | |
5812 | |
5813 if (ret != FAIL && ga.ga_data != NULL) | |
5814 { | |
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
|
5815 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
|
5816 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5817 // 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
|
5818 // 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
|
5819 // 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
|
5820 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
|
5821 } |
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5822 |
7 | 5823 if (eap->cmdidx == CMD_echomsg) |
625 | 5824 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
5825 msg_attr(ga.ga_data, echo_attr); |
625 | 5826 out_flush(); |
5827 } | |
7 | 5828 else if (eap->cmdidx == CMD_echoerr) |
5829 { | |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20128
diff
changeset
|
5830 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
|
5831 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5832 // 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
|
5833 emsg(ga.ga_data); |
7 | 5834 if (!force_abort) |
5835 did_emsg = save_did_emsg; | |
5836 } | |
5837 else if (eap->cmdidx == CMD_execute) | |
5838 do_cmdline((char_u *)ga.ga_data, | |
5839 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); | |
5840 } | |
5841 | |
5842 ga_clear(&ga); | |
5843 | |
5844 if (eap->skip) | |
5845 --emsg_skip; | |
5846 | |
5847 eap->nextcmd = check_nextcmd(arg); | |
5848 } | |
5849 | |
5850 /* | |
5851 * Skip over the name of an option: "&option", "&g:option" or "&l:option". | |
5852 * "arg" points to the "&" or '+' when called, to "option" when returning. | |
5853 * Returns NULL when no option name found. Otherwise pointer to the char | |
5854 * after the option name. | |
5855 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
5856 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5857 find_option_end(char_u **arg, int *opt_flags) |
7 | 5858 { |
5859 char_u *p = *arg; | |
5860 | |
5861 ++p; | |
5862 if (*p == 'g' && p[1] == ':') | |
5863 { | |
5864 *opt_flags = OPT_GLOBAL; | |
5865 p += 2; | |
5866 } | |
5867 else if (*p == 'l' && p[1] == ':') | |
5868 { | |
5869 *opt_flags = OPT_LOCAL; | |
5870 p += 2; | |
5871 } | |
5872 else | |
5873 *opt_flags = 0; | |
5874 | |
5875 if (!ASCII_ISALPHA(*p)) | |
5876 return NULL; | |
5877 *arg = p; | |
5878 | |
5879 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
|
5880 p += 4; // termcap option |
7 | 5881 else |
5882 while (ASCII_ISALPHA(*p)) | |
5883 ++p; | |
5884 return p; | |
5885 } | |
5886 | |
5887 /* | |
448 | 5888 * Display script name where an item was last set. |
5889 * Should only be invoked when 'verbose' is non-zero. | |
5890 */ | |
5891 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
|
5892 last_set_msg(sctx_T script_ctx) |
448 | 5893 { |
507 | 5894 char_u *p; |
5895 | |
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
|
5896 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
|
5897 { |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
5898 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); |
507 | 5899 if (p != NULL) |
5900 { | |
5901 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
5902 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
|
5903 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
|
5904 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
|
5905 { |
18939
25ebc35e104f
patch 8.2.0030: "gF" does not work on output of "verbose command"
Bram Moolenaar <Bram@vim.org>
parents:
18851
diff
changeset
|
5906 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
|
5907 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
|
5908 } |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
5909 verbose_leave(); |
507 | 5910 vim_free(p); |
5911 } | |
448 | 5912 } |
5913 } | |
5914 | |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
5915 #endif // FEAT_EVAL |
7 | 5916 |
5917 /* | |
5918 * 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
|
5919 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL. |
7 | 5920 * "flags" can be "g" to do a global substitute. |
5921 * Returns an allocated string, NULL for error. | |
5922 */ | |
5923 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5924 do_string_sub( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5925 char_u *str, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5926 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5927 char_u *sub, |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5928 typval_T *expr, |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5929 char_u *flags) |
7 | 5930 { |
5931 int sublen; | |
5932 regmatch_T regmatch; | |
5933 int i; | |
5934 int do_all; | |
5935 char_u *tail; | |
6332 | 5936 char_u *end; |
7 | 5937 garray_T ga; |
5938 char_u *ret; | |
5939 char_u *save_cpo; | |
5623 | 5940 char_u *zero_width = NULL; |
7 | 5941 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5942 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here |
7 | 5943 save_cpo = p_cpo; |
1672 | 5944 p_cpo = empty_option; |
7 | 5945 |
5946 ga_init2(&ga, 1, 200); | |
5947 | |
5948 do_all = (flags[0] == 'g'); | |
5949 | |
5950 regmatch.rm_ic = p_ic; | |
5951 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | |
5952 if (regmatch.regprog != NULL) | |
5953 { | |
5954 tail = str; | |
6332 | 5955 end = str + STRLEN(str); |
7 | 5956 while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) |
5957 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5958 // Skip empty match except for first match. |
5623 | 5959 if (regmatch.startp[0] == regmatch.endp[0]) |
5960 { | |
5961 if (zero_width == regmatch.startp[0]) | |
5962 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5963 // 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
|
5964 i = mb_ptr2len(tail); |
5964 | 5965 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, |
5966 (size_t)i); | |
5967 ga.ga_len += i; | |
5968 tail += i; | |
5623 | 5969 continue; |
5970 } | |
5971 zero_width = regmatch.startp[0]; | |
5972 } | |
5973 | |
7 | 5974 /* |
5975 * Get some space for a temporary buffer to do the substitution | |
5976 * into. It will contain: | |
5977 * - The text up to where the match is. | |
5978 * - The substituted text. | |
5979 * - The text after the match. | |
5980 */ | |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5981 sublen = vim_regsub(®match, sub, expr, tail, FALSE, TRUE, FALSE); |
6332 | 5982 if (ga_grow(&ga, (int)((end - tail) + sublen - |
7 | 5983 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL) |
5984 { | |
5985 ga_clear(&ga); | |
5986 break; | |
5987 } | |
5988 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5989 // copy the text up to where the match is |
7 | 5990 i = (int)(regmatch.startp[0] - tail); |
5991 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
|
5992 // add the substituted text |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5993 (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data |
7 | 5994 + ga.ga_len + i, TRUE, TRUE, FALSE); |
5995 ga.ga_len += i + sublen - 1; | |
5388 | 5996 tail = regmatch.endp[0]; |
5997 if (*tail == NUL) | |
5998 break; | |
7 | 5999 if (!do_all) |
6000 break; | |
6001 } | |
6002 | |
6003 if (ga.ga_data != NULL) | |
6004 STRCPY((char *)ga.ga_data + ga.ga_len, tail); | |
6005 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4778
diff
changeset
|
6006 vim_regfree(regmatch.regprog); |
7 | 6007 } |
6008 | |
6009 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data); | |
6010 ga_clear(&ga); | |
1672 | 6011 if (p_cpo == empty_option) |
6012 p_cpo = save_cpo; | |
6013 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6014 // Darn, evaluating {sub} expression or {expr} changed the value. |
1672 | 6015 free_string_option(save_cpo); |
7 | 6016 |
6017 return ret; | |
6018 } |