Mercurial > vim
annotate src/eval.c @ 21208:09377fd59b2e v8.2.1155
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Commit: https://github.com/vim/vim/commit/7a4b8980ea5ecaea061caae7816ea62cc4940011
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 8 17:36:21 2020 +0200
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Problem: Vim9: cannot handle line break inside lambda.
Solution: Pass the compilation context through. (closes https://github.com/vim/vim/issues/6407, closes https://github.com/vim/vim/issues/6409)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 08 Jul 2020 17:45:06 +0200 |
parents | 667192c5938b |
children | ad13736a1783 |
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 |
117 | 23 static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); |
1624 | 24 |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
25 #define NAMESPACE_CHAR (char_u *)"abglstvw" |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
26 |
142 | 27 /* |
364 | 28 * When recursively copying lists and dicts we need to remember which ones we |
29 * have done to avoid endless recursiveness. This unique ID is used for that. | |
1891 | 30 * The last bit is used for previous_funccal, ignored when comparing. |
364 | 31 */ |
32 static int current_copyID = 0; | |
5973 | 33 |
7 | 34 /* |
76 | 35 * Info used by a ":for" loop. |
36 */ | |
137 | 37 typedef struct |
76 | 38 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 blob_T *fi_blob; // blob being used |
137 | 46 } forinfo_T; |
76 | 47 |
7720
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 static int eval7(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int want_string); |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
55 static int eval7_leader(typval_T *rettv, int numeric_only, char_u *start_leader, char_u **end_leaderp); |
7720
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
56 |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
57 static int free_unref_items(int copyID); |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
58 static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end); |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
59 |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
60 /* |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
61 * Return "n1" divided by "n2", taking care of dividing by zero. |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
62 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
63 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
64 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
|
65 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
66 varnumber_T result; |
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 (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
|
69 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
70 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_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
|
72 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
|
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 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
75 result = VARNUM_MAX; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
76 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
77 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
78 result = n1 / n2; |
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 return result; |
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 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
83 /* |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
84 * 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
|
85 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
86 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
87 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
|
88 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
89 // 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
|
90 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
|
91 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
92 |
10567
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
93 #if defined(EBCDIC) || defined(PROTO) |
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 * 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
|
96 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
97 static int |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
98 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
|
99 { |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
100 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
|
101 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
|
102 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
103 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
|
104 } |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
105 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
106 /* |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
107 * 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
|
108 * 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
|
109 * 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
|
110 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
111 static void |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
112 sortFunctions(void) |
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 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
|
115 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
116 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
|
117 } |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
118 #endif |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
119 |
137 | 120 /* |
121 * Initialize the global and v: variables. | |
122 */ | |
123 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
124 eval_init(void) |
137 | 125 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
126 evalvars_init(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
127 func_init(); |
137 | 128 |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
129 #ifdef EBCDIC |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
130 /* |
3178 | 131 * 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
|
132 */ |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
133 sortFunctions(); |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
134 #endif |
137 | 135 } |
136 | |
357 | 137 #if defined(EXITFREE) || defined(PROTO) |
138 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
139 eval_clear(void) |
357 | 140 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
141 evalvars_clear(); |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
142 free_scriptnames(); // must come after evalvars_clear(). |
2849 | 143 free_locales(); |
357 | 144 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
145 // 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
|
146 free_autoload_scriptnames(); |
855 | 147 |
16967
586d625e21b4
patch 8.1.1484: some tests are slow
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
148 // unreferenced lists and dicts |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
149 (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
|
150 |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16967
diff
changeset
|
151 // 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
|
152 free_all_functions(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
153 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
154 #endif |
137 | 155 |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
156 void |
21096
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
157 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
|
158 { |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 { |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
163 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
|
164 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
|
165 } |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
166 } |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
167 |
7 | 168 /* |
169 * Top level evaluation function, returning a boolean. | |
170 * Sets "error" to TRUE if there was an error. | |
171 * Return TRUE or FALSE. | |
172 */ | |
173 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
174 eval_to_bool( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
175 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
176 int *error, |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
177 exarg_T *eap, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
178 int skip) // only parse, don't execute |
7 | 179 { |
137 | 180 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
181 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
|
182 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
|
183 |
21096
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
184 fill_evalarg_from_eap(&evalarg, eap, skip); |
7 | 185 |
186 if (skip) | |
187 ++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
|
188 if (eval0(arg, &tv, eap, &evalarg) == FAIL) |
7 | 189 *error = TRUE; |
190 else | |
191 { | |
192 *error = FALSE; | |
193 if (!skip) | |
194 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
195 retval = (tv_get_number_chk(&tv, error) != 0); |
71 | 196 clear_tv(&tv); |
7 | 197 } |
198 } | |
199 if (skip) | |
200 --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
|
201 clear_evalarg(&evalarg, eap); |
7 | 202 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
203 return (int)retval; |
7 | 204 } |
205 | |
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
|
206 /* |
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 * 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
|
208 */ |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
209 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
|
210 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
|
211 { |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 |
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
218 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
|
219 |
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
220 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
|
221 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
|
222 { |
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 // 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
|
224 // 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
|
225 // 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
|
226 // 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
|
227 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
|
228 && called_emsg == called_emsg_before) |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
229 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
|
230 } |
21098
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
231 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
|
232 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
|
233 } |
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 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
235 /* |
20731
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
236 * 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
|
237 * 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
|
238 */ |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
239 int |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
240 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
|
241 { |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
242 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
|
243 && (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
|
244 || (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
|
245 } |
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 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
248 * 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
|
249 * 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
|
250 * 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
|
251 */ |
16231
0761a4c111a7
patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
252 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
|
253 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
|
254 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 |
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 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
|
260 { |
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 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
|
262 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
|
263 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
264 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
|
265 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
266 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
|
267 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
|
268 } |
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 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
|
270 { |
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 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
|
272 |
20156
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
273 if (partial == NULL) |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
274 return FAIL; |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
275 |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20526
diff
changeset
|
276 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
|
277 && 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
|
278 { |
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
|
279 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
|
280 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
|
281 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
282 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
283 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
284 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
285 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
|
286 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
|
287 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 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
|
292 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
293 } |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
294 } |
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 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
|
296 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
303 if (*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
|
304 { |
14331
f8280e1bfc84
patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
305 clear_tv(rettv); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
306 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
|
307 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
|
308 } |
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 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
|
311 } |
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 * 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
|
315 * 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
|
316 */ |
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 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
|
318 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
|
319 { |
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 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
|
321 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
|
322 |
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 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
|
324 { |
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 *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
|
326 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
|
327 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
328 res = (tv_get_number_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
|
329 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
|
330 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
|
331 } |
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 |
7 | 333 /* |
334 * Top level evaluation function, returning a string. If "skip" is TRUE, | |
335 * only parsing to "nextcmd" is done, without reporting errors. Return | |
336 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE. | |
337 */ | |
338 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
339 eval_to_string_skip( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
340 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
|
341 exarg_T *eap, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
342 int skip) // only parse, don't execute |
7 | 343 { |
137 | 344 typval_T tv; |
7 | 345 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
|
346 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
|
347 |
21096
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
348 fill_evalarg_from_eap(&evalarg, eap, skip); |
7 | 349 if (skip) |
350 ++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
|
351 if (eval0(arg, &tv, eap, &evalarg) == FAIL || skip) |
7 | 352 retval = NULL; |
353 else | |
354 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
355 retval = vim_strsave(tv_get_string(&tv)); |
71 | 356 clear_tv(&tv); |
7 | 357 } |
358 if (skip) | |
359 --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
|
360 clear_evalarg(&evalarg, eap); |
7 | 361 |
362 return retval; | |
363 } | |
364 | |
365 /* | |
9 | 366 * Skip over an expression at "*pp". |
367 * Return FAIL for an error, OK otherwise. | |
368 */ | |
369 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
370 skip_expr(char_u **pp) |
9 | 371 { |
137 | 372 typval_T rettv; |
9 | 373 |
374 *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
|
375 return eval1(pp, &rettv, NULL); |
9 | 376 } |
377 | |
378 /* | |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
379 * 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
|
380 * 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
|
381 * concatenated. "evalarg->eval_tofree" will be set accordingly. |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
382 * 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
|
383 */ |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
384 int |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
385 skip_expr_concatenate(char_u **start, char_u **end, evalarg_T *evalarg) |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
386 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
387 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
|
388 int res; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
389 int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
390 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
|
391 int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
392 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
393 if (vim9script |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
394 && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL)) |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
395 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
396 ga_init2(gap, sizeof(char_u *), 10); |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
397 // leave room for "start" |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
398 if (ga_grow(gap, 1) == OK) |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
399 ++gap->ga_len; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
400 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
401 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
402 // 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
|
403 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
|
404 evalarg->eval_flags &= ~EVAL_EVALUATE; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
405 *end = skipwhite(*end); |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
406 res = eval1(end, &rettv, evalarg); |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
407 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
|
408 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
|
409 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
410 if (vim9script |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
411 && (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
|
412 { |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
413 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
|
414 { |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
415 // 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
|
416 ga_clear(gap); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
417 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
|
418 } |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
419 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
420 { |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
421 char_u *p; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
422 size_t endoff = STRLEN(*end); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
423 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
424 // 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
|
425 *((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
|
426 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
|
427 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
428 // 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
|
429 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
|
430 { |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
431 *((char_u **)gap->ga_data) = NULL; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
432 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
|
433 } |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
434 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
435 ga_clear(gap); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
436 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
|
437 if (p == NULL) |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
438 return FAIL; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
439 *start = p; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
440 vim_free(evalarg->eval_tofree); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
441 evalarg->eval_tofree = p; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
442 // 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
|
443 *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
|
444 } |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
445 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
446 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
447 return res; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
448 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
449 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
450 /* |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
451 * 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
|
452 * breaks. |
1713 | 453 * When "convert" is TRUE convert a List into a sequence of lines and convert |
454 * a Float to a String. | |
7 | 455 * Return pointer to allocated memory, or NULL for failure. |
456 */ | |
457 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
458 eval_to_string( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
459 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
460 int convert) |
7 | 461 { |
137 | 462 typval_T tv; |
7 | 463 char_u *retval; |
714 | 464 garray_T ga; |
1851 | 465 #ifdef FEAT_FLOAT |
1713 | 466 char_u numbuf[NUMBUFLEN]; |
1851 | 467 #endif |
7 | 468 |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
469 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) |
7 | 470 retval = NULL; |
471 else | |
472 { | |
1713 | 473 if (convert && tv.v_type == VAR_LIST) |
714 | 474 { |
475 ga_init2(&ga, (int)sizeof(char), 80); | |
1690 | 476 if (tv.vval.v_list != NULL) |
3000 | 477 { |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
478 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0); |
3000 | 479 if (tv.vval.v_list->lv_len > 0) |
480 ga_append(&ga, NL); | |
481 } | |
714 | 482 ga_append(&ga, NUL); |
483 retval = (char_u *)ga.ga_data; | |
484 } | |
1713 | 485 #ifdef FEAT_FLOAT |
486 else if (convert && tv.v_type == VAR_FLOAT) | |
487 { | |
488 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float); | |
489 retval = vim_strsave(numbuf); | |
490 } | |
491 #endif | |
714 | 492 else |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
493 retval = vim_strsave(tv_get_string(&tv)); |
71 | 494 clear_tv(&tv); |
7 | 495 } |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
496 clear_evalarg(&EVALARG_EVALUATE, NULL); |
7 | 497 |
498 return retval; | |
499 } | |
500 | |
501 /* | |
634 | 502 * 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
|
503 * textwinlock. When "use_sandbox" is TRUE use the sandbox. |
7 | 504 */ |
505 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
506 eval_to_string_safe( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
507 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
508 int use_sandbox) |
7 | 509 { |
510 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
|
511 funccal_entry_T funccal_entry; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
512 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
513 save_funccal(&funccal_entry); |
634 | 514 if (use_sandbox) |
515 ++sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
516 ++textwinlock; |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
517 retval = eval_to_string(arg, FALSE); |
634 | 518 if (use_sandbox) |
519 --sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
520 --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
|
521 restore_funccal(); |
7 | 522 return retval; |
523 } | |
524 | |
525 /* | |
526 * Top level evaluation function, returning a number. | |
527 * Evaluates "expr" silently. | |
528 * Returns -1 for an error. | |
529 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
530 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
531 eval_to_number(char_u *expr) |
7 | 532 { |
137 | 533 typval_T rettv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
534 varnumber_T retval; |
97 | 535 char_u *p = skipwhite(expr); |
7 | 536 |
537 ++emsg_off; | |
538 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
539 if (eval1(&p, &rettv, &EVALARG_EVALUATE) == FAIL) |
7 | 540 retval = -1; |
541 else | |
542 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
543 retval = tv_get_number_chk(&rettv, NULL); |
71 | 544 clear_tv(&rettv); |
7 | 545 } |
546 --emsg_off; | |
547 | |
548 return retval; | |
549 } | |
550 | |
446 | 551 /* |
625 | 552 * Top level evaluation function. |
553 * Returns an allocated typval_T with the result. | |
554 * Returns NULL when there is an error. | |
446 | 555 */ |
556 typval_T * | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
557 eval_expr(char_u *arg, exarg_T *eap) |
446 | 558 { |
559 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
|
560 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
|
561 |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
562 fill_evalarg_from_eap(&evalarg, eap, eap != NULL && eap->skip); |
446 | 563 |
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
|
564 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
|
565 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
|
566 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
|
567 |
74e5e212e550
patch 8.2.1099: Vim9: cannot use line break in :cexpr argument
Bram Moolenaar <Bram@vim.org>
parents:
21094
diff
changeset
|
568 clear_evalarg(&evalarg, eap); |
446 | 569 return tv; |
570 } | |
571 | |
7 | 572 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
573 * 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
|
574 * 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
|
575 * should have type VAR_UNKNOWN. |
408 | 576 * Returns OK or FAIL. |
577 */ | |
3078 | 578 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
579 call_vim_function( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
580 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
581 int argc, |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
582 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
|
583 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
|
584 { |
408 | 585 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
586 funcexe_T funcexe; |
7 | 587 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
588 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
|
589 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
|
590 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
|
591 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
|
592 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
593 ret = call_func(func, -1, rettv, argc, argv, &funcexe); |
408 | 594 if (ret == FAIL) |
595 clear_tv(rettv); | |
596 | |
597 return ret; | |
598 } | |
599 | |
4133 | 600 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
601 * Call Vim script function "func" and return the result as a number. |
4133 | 602 * 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
|
603 * 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
|
604 * have type VAR_UNKNOWN. |
4133 | 605 */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
606 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
607 call_func_retnr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
608 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
609 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
|
610 typval_T *argv) |
4133 | 611 { |
612 typval_T rettv; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
613 varnumber_T retval; |
4133 | 614 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
615 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
4133 | 616 return -1; |
617 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
618 retval = tv_get_number_chk(&rettv, NULL); |
4133 | 619 clear_tv(&rettv); |
620 return retval; | |
621 } | |
622 | |
408 | 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 string. |
453 | 625 * 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
|
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. |
408 | 628 */ |
629 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
630 call_func_retstr( |
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) |
408 | 634 { |
635 typval_T rettv; | |
453 | 636 char_u *retval; |
408 | 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) |
408 | 639 return NULL; |
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 = vim_strsave(tv_get_string(&rettv)); |
408 | 642 clear_tv(&rettv); |
7 | 643 return retval; |
644 } | |
1322 | 645 |
453 | 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 List. |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
648 * 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
|
649 * have type VAR_UNKNOWN. |
1690 | 650 * Returns NULL when there is something wrong. |
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_retlist( |
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; | |
659 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
660 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 661 return NULL; |
662 | |
663 if (rettv.v_type != VAR_LIST) | |
664 { | |
665 clear_tv(&rettv); | |
666 return NULL; | |
667 } | |
668 | |
669 return rettv.vval.v_list; | |
670 } | |
1322 | 671 |
7 | 672 #ifdef FEAT_FOLDING |
673 /* | |
674 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding | |
675 * it in "*cp". Doesn't give error messages. | |
676 */ | |
677 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
678 eval_foldexpr(char_u *arg, int *cp) |
7 | 679 { |
137 | 680 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
681 varnumber_T retval; |
7 | 682 char_u *s; |
681 | 683 int use_sandbox = was_set_insecurely((char_u *)"foldexpr", |
684 OPT_LOCAL); | |
7 | 685 |
686 ++emsg_off; | |
634 | 687 if (use_sandbox) |
688 ++sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
689 ++textwinlock; |
7 | 690 *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
|
691 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) |
7 | 692 retval = 0; |
693 else | |
694 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
695 // If the result is a number, just return the number. |
71 | 696 if (tv.v_type == VAR_NUMBER) |
697 retval = tv.vval.v_number; | |
156 | 698 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL) |
7 | 699 retval = 0; |
700 else | |
701 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
702 // 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
|
703 // the number. |
71 | 704 s = tv.vval.v_string; |
7 | 705 if (!VIM_ISDIGIT(*s) && *s != '-') |
706 *cp = *s++; | |
707 retval = atol((char *)s); | |
708 } | |
71 | 709 clear_tv(&tv); |
7 | 710 } |
711 --emsg_off; | |
634 | 712 if (use_sandbox) |
713 --sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
714 --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
|
715 clear_evalarg(&EVALARG_EVALUATE, NULL); |
7 | 716 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
717 return (int)retval; |
7 | 718 } |
719 #endif | |
720 | |
721 /* | |
110 | 722 * Get an lval: variable, Dict item or List item that can be assigned a value |
723 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]", | |
724 * "name.key", "name.key[expr]" etc. | |
725 * Indexing only works if "name" is an existing List or Dictionary. | |
726 * "name" points to the start of the name. | |
727 * If "rettv" is not NULL it points to the value to be assigned. | |
728 * "unlet" is TRUE for ":unlet": slightly different behavior when something is | |
729 * wrong; must end in space or cmd separator. | |
730 * | |
5604 | 731 * flags: |
732 * 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
|
733 * GLV_READ_ONLY: will not change the variable |
5604 | 734 * GLV_NO_AUTOLOAD: do not use script autoloading |
735 * | |
110 | 736 * Returns a pointer to just after the name, including indexes. |
124 | 737 * When an evaluation error occurs "lp->ll_name" is NULL; |
110 | 738 * Returns NULL for a parsing error. Still need to free items in "lp"! |
71 | 739 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
740 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
741 get_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
742 char_u *name, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
743 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
744 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
745 int unlet, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
746 int skip, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
747 int flags, // GLV_ values |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
748 int fne_flags) // flags for find_name_end() |
110 | 749 { |
750 char_u *p; | |
751 char_u *expr_start, *expr_end; | |
752 int cc; | |
137 | 753 dictitem_T *v; |
754 typval_T var1; | |
755 typval_T var2; | |
110 | 756 int empty1 = FALSE; |
137 | 757 listitem_T *ni; |
100 | 758 char_u *key = NULL; |
759 int len; | |
137 | 760 hashtab_T *ht; |
5604 | 761 int quiet = flags & GLV_QUIET; |
71 | 762 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
763 // Clear everything in "lp". |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
764 CLEAR_POINTER(lp); |
110 | 765 |
766 if (skip) | |
767 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
768 // When skipping just find the end of the name. |
110 | 769 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
|
770 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
|
771 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
|
772 return lp->ll_name_end; |
110 | 773 } |
774 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
775 // Find the end of the name. |
271 | 776 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
|
777 lp->ll_name_end = p; |
110 | 778 if (expr_start != NULL) |
779 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
780 // 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
|
781 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p) |
110 | 782 && *p != '[' && *p != '.') |
783 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
784 emsg(_(e_trailing)); |
110 | 785 return NULL; |
786 } | |
787 | |
788 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); | |
789 if (lp->ll_exp_name == NULL) | |
790 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
791 // 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
|
792 // 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
|
793 // aborting error, an interrupt, or an exception. |
110 | 794 if (!aborting() && !quiet) |
795 { | |
121 | 796 emsg_severe = TRUE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
797 semsg(_(e_invarg2), name); |
110 | 798 return NULL; |
799 } | |
800 } | |
801 lp->ll_name = lp->ll_exp_name; | |
802 } | |
803 else | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
804 { |
110 | 805 lp->ll_name = name; |
806 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
807 if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && *p == ':') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
808 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
809 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
810 char_u *tp = skipwhite(p + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
811 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
812 // parse the type after the name |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
813 lp->ll_type = parse_type(&tp, &si->sn_type_list); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
814 lp->ll_name_end = tp; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
815 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
816 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
817 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
818 // Without [idx] or .key we are done. |
110 | 819 if ((*p != '[' && *p != '.') || lp->ll_name == NULL) |
820 return p; | |
821 | |
822 cc = *p; | |
823 *p = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
824 // 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
|
825 // 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
|
826 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
|
827 flags & GLV_NO_AUTOLOAD); |
110 | 828 if (v == NULL && !quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
829 semsg(_(e_undefvar), lp->ll_name); |
110 | 830 *p = cc; |
71 | 831 if (v == NULL) |
832 return NULL; | |
833 | |
110 | 834 /* |
835 * Loop until no more [idx] or .key is following. | |
836 */ | |
137 | 837 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
|
838 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
|
839 var2.v_type = VAR_UNKNOWN; |
110 | 840 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) |
841 { | |
842 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) | |
843 && !(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
|
844 && 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
|
845 && !(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
|
846 && lp->ll_tv->vval.v_blob != NULL)) |
110 | 847 { |
848 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
849 emsg(_("E689: Can only index a List, Dictionary or Blob")); |
110 | 850 return NULL; |
851 } | |
852 if (lp->ll_range) | |
853 { | |
854 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
855 emsg(_("E708: [:] must come last")); |
110 | 856 return NULL; |
71 | 857 } |
88 | 858 |
100 | 859 len = -1; |
860 if (*p == '.') | |
861 { | |
862 key = p + 1; | |
863 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
864 ; | |
865 if (len == 0) | |
866 { | |
110 | 867 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
868 emsg(_(e_emptykey)); |
110 | 869 return NULL; |
88 | 870 } |
100 | 871 p = key + len; |
872 } | |
873 else | |
874 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
875 // Get the index [expr] or the first index [expr: ]. |
88 | 876 p = skipwhite(p + 1); |
100 | 877 if (*p == ':') |
878 empty1 = TRUE; | |
88 | 879 else |
880 { | |
100 | 881 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
|
882 if (eval1(&p, &var1, &EVALARG_EVALUATE) == FAIL) // recursive! |
110 | 883 return NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
884 if (tv_get_string_chk(&var1) == NULL) |
323 | 885 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
886 // not a number or string |
323 | 887 clear_tv(&var1); |
888 return NULL; | |
889 } | |
100 | 890 } |
891 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
892 // Optionally get the second index [ :expr]. |
100 | 893 if (*p == ':') |
894 { | |
110 | 895 if (lp->ll_tv->v_type == VAR_DICT) |
896 { | |
897 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
898 emsg(_(e_dictrange)); |
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
|
899 clear_tv(&var1); |
110 | 900 return NULL; |
901 } | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
902 if (rettv != NULL |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
903 && !(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
|
904 && rettv->vval.v_list != NULL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
905 && !(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
|
906 && rettv->vval.v_blob != NULL)) |
110 | 907 { |
908 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
909 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
|
910 clear_tv(&var1); |
110 | 911 return NULL; |
88 | 912 } |
100 | 913 p = skipwhite(p + 1); |
914 if (*p == ']') | |
110 | 915 lp->ll_empty2 = TRUE; |
100 | 916 else |
917 { | |
110 | 918 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
|
919 // 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
|
920 if (eval1(&p, &var2, &EVALARG_EVALUATE) == FAIL) |
100 | 921 { |
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
|
922 clear_tv(&var1); |
110 | 923 return NULL; |
100 | 924 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
925 if (tv_get_string_chk(&var2) == NULL) |
323 | 926 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
927 // 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
|
928 clear_tv(&var1); |
323 | 929 clear_tv(&var2); |
930 return NULL; | |
931 } | |
100 | 932 } |
110 | 933 lp->ll_range = TRUE; |
100 | 934 } |
935 else | |
110 | 936 lp->ll_range = FALSE; |
100 | 937 |
938 if (*p != ']') | |
939 { | |
110 | 940 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
941 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
|
942 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
|
943 clear_tv(&var2); |
110 | 944 return NULL; |
100 | 945 } |
946 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
947 // Skip to past ']'. |
100 | 948 ++p; |
949 } | |
950 | |
110 | 951 if (lp->ll_tv->v_type == VAR_DICT) |
100 | 952 { |
953 if (len == -1) | |
954 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
955 // "[key]": get key from "var1" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
956 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
|
957 if (key == NULL) |
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
958 { |
100 | 959 clear_tv(&var1); |
110 | 960 return NULL; |
961 } | |
962 } | |
117 | 963 lp->ll_list = NULL; |
964 lp->ll_dict = lp->ll_tv->vval.v_dict; | |
121 | 965 lp->ll_di = dict_find(lp->ll_dict, key, len); |
2739 | 966 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
967 // 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
|
968 // 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
|
969 // g: dictionary). Disallow overwriting a builtin function. |
3687 | 970 if (rettv != NULL && lp->ll_dict->dv_scope != 0) |
971 { | |
972 int prevval; | |
973 int wrong; | |
974 | |
975 if (len != -1) | |
976 { | |
977 prevval = key[len]; | |
978 key[len] = NUL; | |
979 } | |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
980 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
981 prevval = 0; // avoid compiler warning |
3687 | 982 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE |
983 && rettv->v_type == VAR_FUNC | |
2739 | 984 && var_check_func_name(key, lp->ll_di == NULL)) |
3687 | 985 || !valid_varname(key); |
986 if (len != -1) | |
987 key[len] = prevval; | |
988 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
|
989 { |
0b35a7ffceb2
patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents:
20126
diff
changeset
|
990 clear_tv(&var1); |
2739 | 991 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
|
992 } |
2739 | 993 } |
994 | |
110 | 995 if (lp->ll_di == NULL) |
100 | 996 { |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
997 // 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
|
998 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
|
999 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht()) |
2739 | 1000 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1001 semsg(_(e_illvar), name); |
16013
93b08b92a049
patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents:
15969
diff
changeset
|
1002 clear_tv(&var1); |
2739 | 1003 return NULL; |
1004 } | |
1005 | |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
1006 // Key does not exist in dict: may need to add it. |
110 | 1007 if (*p == '[' || *p == '.' || unlet) |
1008 { | |
1009 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1010 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
|
1011 clear_tv(&var1); |
110 | 1012 return NULL; |
100 | 1013 } |
1014 if (len == -1) | |
110 | 1015 lp->ll_newkey = vim_strsave(key); |
100 | 1016 else |
110 | 1017 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
|
1018 clear_tv(&var1); |
110 | 1019 if (lp->ll_newkey == NULL) |
100 | 1020 p = NULL; |
1021 break; | |
1022 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1023 // 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
|
1024 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
|
1025 && 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
|
1026 { |
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
1027 clear_tv(&var1); |
2739 | 1028 return NULL; |
10910
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
1029 } |
2739 | 1030 |
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
|
1031 clear_tv(&var1); |
110 | 1032 lp->ll_tv = &lp->ll_di->di_tv; |
100 | 1033 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1034 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
|
1035 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1036 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
|
1037 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1038 /* |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1039 * 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
|
1040 */ |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1041 if (empty1) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1042 lp->ll_n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1043 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1044 // is number or string |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1045 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
|
1046 clear_tv(&var1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1047 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1048 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
|
1049 || lp->ll_n1 > bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1050 || (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
|
1051 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1052 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1053 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
|
1054 clear_tv(&var2); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1055 return NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1056 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1057 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
|
1058 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1059 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
|
1060 clear_tv(&var2); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1061 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
|
1062 || lp->ll_n2 >= bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1063 || 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
|
1064 { |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1065 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1066 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
|
1067 return NULL; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1068 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1069 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1070 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
|
1071 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
|
1072 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1073 } |
100 | 1074 else |
1075 { | |
1076 /* | |
1077 * Get the number and item for the only or first index of the List. | |
1078 */ | |
1079 if (empty1) | |
110 | 1080 lp->ll_n1 = 0; |
100 | 1081 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1082 // 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
|
1083 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
|
1084 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
|
1085 |
117 | 1086 lp->ll_dict = NULL; |
110 | 1087 lp->ll_list = lp->ll_tv->vval.v_list; |
1088 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
1089 if (lp->ll_li == NULL) | |
1090 { | |
842 | 1091 if (lp->ll_n1 < 0) |
1092 { | |
1093 lp->ll_n1 = 0; | |
1094 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
1095 } | |
1096 } | |
1097 if (lp->ll_li == NULL) | |
1098 { | |
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
|
1099 clear_tv(&var2); |
2772 | 1100 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1101 semsg(_(e_listidx), lp->ll_n1); |
110 | 1102 return NULL; |
100 | 1103 } |
1104 | |
1105 /* | |
1106 * May need to find the item or absolute index for the second | |
1107 * index of a range. | |
110 | 1108 * When no index given: "lp->ll_empty2" is TRUE. |
1109 * Otherwise "lp->ll_n2" is set to the second index. | |
100 | 1110 */ |
110 | 1111 if (lp->ll_range && !lp->ll_empty2) |
1112 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1113 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
|
1114 // is number or string |
88 | 1115 clear_tv(&var2); |
110 | 1116 if (lp->ll_n2 < 0) |
1117 { | |
1118 ni = list_find(lp->ll_list, lp->ll_n2); | |
100 | 1119 if (ni == NULL) |
2772 | 1120 { |
1121 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1122 semsg(_(e_listidx), lp->ll_n2); |
110 | 1123 return NULL; |
2772 | 1124 } |
110 | 1125 lp->ll_n2 = list_idx_of_item(lp->ll_list, ni); |
1126 } | |
1127 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1128 // Check that lp->ll_n2 isn't before lp->ll_n1. |
110 | 1129 if (lp->ll_n1 < 0) |
1130 lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li); | |
1131 if (lp->ll_n2 < lp->ll_n1) | |
2772 | 1132 { |
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_n2); |
110 | 1135 return NULL; |
2772 | 1136 } |
110 | 1137 } |
1138 | |
1139 lp->ll_tv = &lp->ll_li->li_tv; | |
1140 } | |
1141 } | |
1142 | |
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
|
1143 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
|
1144 lp->ll_name_end = p; |
110 | 1145 return p; |
1146 } | |
1147 | |
1148 /* | |
137 | 1149 * Clear lval "lp" that was filled by get_lval(). |
110 | 1150 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1151 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1152 clear_lval(lval_T *lp) |
110 | 1153 { |
1154 vim_free(lp->ll_exp_name); | |
1155 vim_free(lp->ll_newkey); | |
1156 } | |
1157 | |
1158 /* | |
151 | 1159 * Set a variable that was parsed by get_lval() to "rettv". |
110 | 1160 * "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
|
1161 * "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
|
1162 * "%" for "%=", "." for ".=" or "=" for "=". |
117 | 1163 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
1164 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1165 set_var_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1166 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1167 char_u *endp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1168 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1169 int copy, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1170 int flags, // LET_IS_CONST and/or LET_NO_COMMAND |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1171 char_u *op) |
110 | 1172 { |
1173 int cc; | |
137 | 1174 listitem_T *ri; |
1175 dictitem_T *di; | |
110 | 1176 |
1177 if (lp->ll_tv == NULL) | |
1178 { | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1179 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
|
1180 *endp = NUL; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1181 if (lp->ll_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1182 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1183 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
|
1184 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1185 if (op != NULL && *op != '=') |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1186 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1187 semsg(_(e_letwrong), op); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1188 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1189 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1190 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1191 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
|
1192 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1193 int il, ir; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1194 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1195 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1196 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
|
1197 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1198 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
|
1199 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1200 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
|
1201 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1202 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1203 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1204 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
|
1205 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1206 ir = 0; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1207 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
|
1208 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
|
1209 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
|
1210 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1211 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1212 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1213 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
|
1214 if (!error) |
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 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
|
1217 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1218 // 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
|
1219 // the end is an error otherwise. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1220 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
|
1221 || (lp->ll_n1 == gap->ga_len |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1222 && 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
|
1223 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1224 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
|
1225 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
|
1226 ++gap->ga_len; |
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 // 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
|
1229 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1230 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1231 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1232 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
|
1233 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1234 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
|
1235 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1236 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
|
1237 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1238 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
|
1239 *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
|
1240 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1241 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1242 |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1243 // 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
|
1244 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
|
1245 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
|
1246 &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
|
1247 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1248 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
|
1249 || (!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
|
1250 && !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
|
1251 && 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
|
1252 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
|
1253 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
|
1254 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1255 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1256 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1257 set_var_const(lp->ll_name, lp->ll_type, rettv, copy, flags); |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1258 *endp = cc; |
110 | 1259 } |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1260 else if (var_check_lock(lp->ll_newkey == NULL |
151 | 1261 ? lp->ll_tv->v_lock |
6773 | 1262 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE)) |
151 | 1263 ; |
110 | 1264 else if (lp->ll_range) |
1265 { | |
6166 | 1266 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
|
1267 int ll_n1 = lp->ll_n1; |
6166 | 1268 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1269 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
|
1270 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1271 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
|
1272 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1273 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1274 |
6166 | 1275 /* |
1276 * Check whether any of the list items is locked | |
1277 */ | |
6422 | 1278 for (ri = rettv->vval.v_list->lv_first; ri != NULL && ll_li != NULL; ) |
6166 | 1279 { |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1280 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE)) |
6166 | 1281 return; |
1282 ri = ri->li_next; | |
1283 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == ll_n1)) | |
1284 break; | |
1285 ll_li = ll_li->li_next; | |
1286 ++ll_n1; | |
1287 } | |
1288 | |
110 | 1289 /* |
1290 * Assign the List values to the list items. | |
1291 */ | |
1292 for (ri = rettv->vval.v_list->lv_first; ri != NULL; ) | |
1293 { | |
117 | 1294 if (op != NULL && *op != '=') |
1295 tv_op(&lp->ll_li->li_tv, &ri->li_tv, op); | |
1296 else | |
1297 { | |
1298 clear_tv(&lp->ll_li->li_tv); | |
1299 copy_tv(&ri->li_tv, &lp->ll_li->li_tv); | |
1300 } | |
110 | 1301 ri = ri->li_next; |
1302 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1)) | |
1303 break; | |
1304 if (lp->ll_li->li_next == NULL) | |
1305 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1306 // Need to add an empty item. |
533 | 1307 if (list_append_number(lp->ll_list, 0) == FAIL) |
110 | 1308 { |
1309 ri = NULL; | |
88 | 1310 break; |
110 | 1311 } |
1312 } | |
1313 lp->ll_li = lp->ll_li->li_next; | |
1314 ++lp->ll_n1; | |
1315 } | |
1316 if (ri != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1317 emsg(_("E710: List value has more items than target")); |
117 | 1318 else if (lp->ll_empty2 |
1319 ? (lp->ll_li != NULL && lp->ll_li->li_next != NULL) | |
110 | 1320 : 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
|
1321 emsg(_("E711: List value has not enough items")); |
110 | 1322 } |
1323 else | |
1324 { | |
1325 /* | |
1326 * Assign to a List or Dictionary item. | |
1327 */ | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1328 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
|
1329 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1330 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
|
1331 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1332 } |
110 | 1333 if (lp->ll_newkey != NULL) |
1334 { | |
117 | 1335 if (op != NULL && *op != '=') |
1336 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1337 semsg(_(e_letwrong), op); |
117 | 1338 return; |
1339 } | |
1340 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1341 // Need to add an item to the Dictionary. |
121 | 1342 di = dictitem_alloc(lp->ll_newkey); |
110 | 1343 if (di == NULL) |
1344 return; | |
121 | 1345 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL) |
1346 { | |
1347 vim_free(di); | |
1348 return; | |
1349 } | |
110 | 1350 lp->ll_tv = &di->di_tv; |
1351 } | |
117 | 1352 else if (op != NULL && *op != '=') |
1353 { | |
1354 tv_op(lp->ll_tv, rettv, op); | |
1355 return; | |
1356 } | |
110 | 1357 else |
1358 clear_tv(lp->ll_tv); | |
1359 | |
1360 /* | |
1361 * Assign the value to the variable or list item. | |
1362 */ | |
1363 if (copy) | |
1364 copy_tv(rettv, lp->ll_tv); | |
1365 else | |
1366 { | |
1367 *lp->ll_tv = *rettv; | |
156 | 1368 lp->ll_tv->v_lock = 0; |
110 | 1369 init_tv(rettv); |
1370 } | |
1371 } | |
7 | 1372 } |
1373 | |
76 | 1374 /* |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1375 * 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
|
1376 * and "tv1 .= tv2" |
117 | 1377 * Returns OK or FAIL. |
1378 */ | |
1379 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1380 tv_op(typval_T *tv1, typval_T *tv2, char_u *op) |
117 | 1381 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1382 varnumber_T n; |
117 | 1383 char_u numbuf[NUMBUFLEN]; |
1384 char_u *s; | |
1385 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1386 // 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
|
1387 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
|
1388 && tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL) |
117 | 1389 { |
1390 switch (tv1->v_type) | |
1391 { | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1392 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
|
1393 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
|
1394 case VAR_VOID: |
117 | 1395 case VAR_DICT: |
1396 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1397 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
|
1398 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1399 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1400 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
1401 case VAR_CHANNEL: |
117 | 1402 break; |
1403 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1404 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1405 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
|
1406 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1407 // BLOB += BLOB |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1408 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
|
1409 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1410 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
|
1411 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
|
1412 int i, len = blob_len(b2); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1413 for (i = 0; i < len; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1414 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
|
1415 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1416 return OK; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1417 |
117 | 1418 case VAR_LIST: |
1419 if (*op != '+' || tv2->v_type != VAR_LIST) | |
1420 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1421 // List += List |
117 | 1422 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL) |
1423 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL); | |
1424 return OK; | |
1425 | |
1426 case VAR_NUMBER: | |
1427 case VAR_STRING: | |
1428 if (tv2->v_type == VAR_LIST) | |
1429 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1430 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
|
1431 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1432 // 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
|
1433 n = tv_get_number(tv1); |
1624 | 1434 #ifdef FEAT_FLOAT |
1435 if (tv2->v_type == VAR_FLOAT) | |
1436 { | |
1437 float_T f = n; | |
1438 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1439 if (*op == '%') |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1440 break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1441 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1442 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1443 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
|
1444 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
|
1445 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
|
1446 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
|
1447 } |
1624 | 1448 clear_tv(tv1); |
1449 tv1->v_type = VAR_FLOAT; | |
1450 tv1->vval.v_float = f; | |
1451 } | |
117 | 1452 else |
1624 | 1453 #endif |
1454 { | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1455 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1456 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1457 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
|
1458 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
|
1459 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
|
1460 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
|
1461 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
|
1462 } |
1624 | 1463 clear_tv(tv1); |
1464 tv1->v_type = VAR_NUMBER; | |
1465 tv1->vval.v_number = n; | |
1466 } | |
1467 } | |
1468 else | |
1469 { | |
1470 if (tv2->v_type == VAR_FLOAT) | |
1471 break; | |
1472 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1473 // str .= str |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1474 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
|
1475 s = concat_str(s, tv_get_string_buf(tv2, numbuf)); |
117 | 1476 clear_tv(tv1); |
1477 tv1->v_type = VAR_STRING; | |
1478 tv1->vval.v_string = s; | |
1479 } | |
1480 return OK; | |
1624 | 1481 |
1482 case VAR_FLOAT: | |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1483 #ifdef FEAT_FLOAT |
1624 | 1484 { |
1485 float_T f; | |
1486 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1487 if (*op == '%' || *op == '.' |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1488 || (tv2->v_type != VAR_FLOAT |
1624 | 1489 && tv2->v_type != VAR_NUMBER |
1490 && tv2->v_type != VAR_STRING)) | |
1491 break; | |
1492 if (tv2->v_type == VAR_FLOAT) | |
1493 f = tv2->vval.v_float; | |
1494 else | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1495 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
|
1496 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1497 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1498 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
|
1499 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
|
1500 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
|
1501 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
|
1502 } |
1624 | 1503 } |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1504 #endif |
1624 | 1505 return OK; |
117 | 1506 } |
1507 } | |
1508 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1509 semsg(_(e_letwrong), op); |
117 | 1510 return FAIL; |
1511 } | |
1512 | |
1513 /* | |
76 | 1514 * Evaluate the expression used in a ":for var in expr" command. |
1515 * "arg" points to "var". | |
1516 * Set "*errp" to TRUE for an error, FALSE otherwise; | |
1517 * Return a pointer that holds the info. Null when there is an error. | |
1518 */ | |
1519 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1520 eval_for_line( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1521 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1522 int *errp, |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1523 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
|
1524 evalarg_T *evalarg) |
76 | 1525 { |
137 | 1526 forinfo_T *fi; |
76 | 1527 char_u *expr; |
137 | 1528 typval_T tv; |
1529 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
|
1530 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
|
1531 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1532 *errp = TRUE; // default: there is an error |
76 | 1533 |
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
|
1534 fi = ALLOC_CLEAR_ONE(forinfo_T); |
76 | 1535 if (fi == NULL) |
1536 return NULL; | |
1537 | |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
1538 expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon, FALSE); |
76 | 1539 if (expr == NULL) |
1540 return fi; | |
1541 | |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1542 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
|
1543 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
|
1544 || !(expr[2] == NUL || VIM_ISWHITE(expr[2]))) |
76 | 1545 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1546 emsg(_(e_missing_in)); |
76 | 1547 return fi; |
1548 } | |
1549 | |
1550 if (skip) | |
1551 ++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
|
1552 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
|
1553 if (eval0(expr, &tv, eap, evalarg) == OK) |
76 | 1554 { |
1555 *errp = FALSE; | |
1556 if (!skip) | |
1557 { | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1558 if (tv.v_type == VAR_LIST) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1559 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1560 l = tv.vval.v_list; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1561 if (l == NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1562 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1563 // 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
|
1564 clear_tv(&tv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1565 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1566 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1567 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1568 // 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
|
1569 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
|
1570 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1571 // 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
|
1572 // the list being used in "tv". |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1573 fi->fi_list = l; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1574 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
|
1575 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
|
1576 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1577 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1578 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
|
1579 { |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1580 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
|
1581 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
|
1582 { |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1583 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
|
1584 |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1585 // 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
|
1586 // 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
|
1587 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
|
1588 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
|
1589 } |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1590 clear_tv(&tv); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1591 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1592 else |
359 | 1593 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1594 emsg(_(e_listreq)); |
359 | 1595 clear_tv(&tv); |
1596 } | |
76 | 1597 } |
1598 } | |
1599 if (skip) | |
1600 --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
|
1601 fi->fi_break_count = evalarg->eval_break_count; |
76 | 1602 |
1603 return fi; | |
1604 } | |
1605 | |
1606 /* | |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1607 * 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
|
1608 */ |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1609 void |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1610 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
|
1611 { |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1612 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
|
1613 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
|
1614 |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1615 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
|
1616 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
|
1617 } |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1618 |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1619 /* |
76 | 1620 * Use the first item in a ":for" list. Advance to the next. |
1621 * Assign the values to the variable (list). "arg" points to the first one. | |
1622 * Return TRUE when a valid item was found, FALSE when at end of list or | |
1623 * something wrong. | |
1624 */ | |
1625 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1626 next_for_item(void *fi_void, char_u *arg) |
76 | 1627 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
1628 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1629 int result; |
19568
c0749ad6c699
patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
1630 int flag = current_sctx.sc_version == SCRIPT_VERSION_VIM9 ? |
c0749ad6c699
patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
1631 LET_NO_COMMAND : 0; |
137 | 1632 listitem_T *item; |
76 | 1633 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1634 if (fi->fi_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1635 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1636 typval_T tv; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1637 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1638 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
|
1639 return FALSE; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1640 tv.v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1641 tv.v_lock = VAR_FIXED; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1642 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
|
1643 ++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
|
1644 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
|
1645 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
|
1646 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1647 |
76 | 1648 item = fi->fi_lw.lw_item; |
1649 if (item == NULL) | |
1650 result = FALSE; | |
1651 else | |
1652 { | |
1653 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
|
1654 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
|
1655 fi->fi_varcount, flag, NULL) == OK); |
76 | 1656 } |
1657 return result; | |
1658 } | |
1659 | |
1660 /* | |
1661 * Free the structure used to store info used by ":for". | |
1662 */ | |
1663 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1664 free_for_info(void *fi_void) |
76 | 1665 { |
137 | 1666 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1667 |
92 | 1668 if (fi != NULL && fi->fi_list != NULL) |
359 | 1669 { |
76 | 1670 list_rem_watch(fi->fi_list, &fi->fi_lw); |
359 | 1671 list_unref(fi->fi_list); |
1672 } | |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
1673 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
|
1674 blob_unref(fi->fi_blob); |
76 | 1675 vim_free(fi); |
1676 } | |
1677 | |
7 | 1678 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1679 set_context_for_expression( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1680 expand_T *xp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1681 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1682 cmdidx_T cmdidx) |
7 | 1683 { |
1684 int got_eq = FALSE; | |
1685 int c; | |
76 | 1686 char_u *p; |
1687 | |
18713
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1688 if (cmdidx == CMD_let || cmdidx == CMD_const) |
76 | 1689 { |
1690 xp->xp_context = EXPAND_USER_VARS; | |
159 | 1691 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) |
76 | 1692 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1693 // ":let var1 var2 ...": find last space. |
159 | 1694 for (p = arg + STRLEN(arg); p >= arg; ) |
76 | 1695 { |
1696 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
|
1697 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
|
1698 if (VIM_ISWHITE(*p)) |
76 | 1699 break; |
1700 } | |
1701 return; | |
1702 } | |
1703 } | |
1704 else | |
1705 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS | |
1706 : EXPAND_EXPRESSION; | |
7 | 1707 while ((xp->xp_pattern = vim_strpbrk(arg, |
1708 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) | |
1709 { | |
1710 c = *xp->xp_pattern; | |
1711 if (c == '&') | |
1712 { | |
1713 c = xp->xp_pattern[1]; | |
1714 if (c == '&') | |
1715 { | |
1716 ++xp->xp_pattern; | |
1717 xp->xp_context = cmdidx != CMD_let || got_eq | |
1718 ? EXPAND_EXPRESSION : EXPAND_NOTHING; | |
1719 } | |
1720 else if (c != ' ') | |
201 | 1721 { |
7 | 1722 xp->xp_context = EXPAND_SETTINGS; |
201 | 1723 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') |
1724 xp->xp_pattern += 2; | |
1725 | |
1726 } | |
7 | 1727 } |
1728 else if (c == '$') | |
1729 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1730 // environment variable |
7 | 1731 xp->xp_context = EXPAND_ENV_VARS; |
1732 } | |
1733 else if (c == '=') | |
1734 { | |
1735 got_eq = TRUE; | |
1736 xp->xp_context = EXPAND_EXPRESSION; | |
1737 } | |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1738 else if (c == '#' |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1739 && xp->xp_context == EXPAND_EXPRESSION) |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1740 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1741 // Autoload function/variable contains '#'. |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1742 break; |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1743 } |
6367 | 1744 else if ((c == '<' || c == '#') |
7 | 1745 && xp->xp_context == EXPAND_FUNCTIONS |
1746 && vim_strchr(xp->xp_pattern, '(') == NULL) | |
1747 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1748 // Function name can start with "<SNR>" and contain '#'. |
7 | 1749 break; |
1750 } | |
1751 else if (cmdidx != CMD_let || got_eq) | |
1752 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1753 if (c == '"') // string |
7 | 1754 { |
1755 while ((c = *++xp->xp_pattern) != NUL && c != '"') | |
1756 if (c == '\\' && xp->xp_pattern[1] != NUL) | |
1757 ++xp->xp_pattern; | |
1758 xp->xp_context = EXPAND_NOTHING; | |
1759 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1760 else if (c == '\'') // literal string |
7 | 1761 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1762 // Trick: '' is like stopping and starting a literal string. |
7 | 1763 while ((c = *++xp->xp_pattern) != NUL && c != '\'') |
1764 /* skip */ ; | |
1765 xp->xp_context = EXPAND_NOTHING; | |
1766 } | |
1767 else if (c == '|') | |
1768 { | |
1769 if (xp->xp_pattern[1] == '|') | |
1770 { | |
1771 ++xp->xp_pattern; | |
1772 xp->xp_context = EXPAND_EXPRESSION; | |
1773 } | |
1774 else | |
1775 xp->xp_context = EXPAND_COMMANDS; | |
1776 } | |
1777 else | |
1778 xp->xp_context = EXPAND_EXPRESSION; | |
1779 } | |
1780 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1781 // 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
|
1782 // anyway. |
76 | 1783 xp->xp_context = EXPAND_EXPRESSION; |
7 | 1784 arg = xp->xp_pattern; |
1785 if (*arg != NUL) | |
1786 while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) | |
1787 /* skip */ ; | |
1788 } | |
1789 xp->xp_pattern = arg; | |
1790 } | |
1791 | |
1792 /* | |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1793 * Return TRUE if "pat" matches "text". |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1794 * 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
|
1795 */ |
17377
cb008de2a6ec
patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17375
diff
changeset
|
1796 int |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1797 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
|
1798 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1799 int matches = FALSE; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1800 char_u *save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1801 regmatch_T regmatch; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1802 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1803 // avoid 'l' flag in 'cpoptions' |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1804 save_cpo = p_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1805 p_cpo = (char_u *)""; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1806 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
|
1807 if (regmatch.regprog != NULL) |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1808 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1809 regmatch.rm_ic = ic; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1810 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
|
1811 vim_regfree(regmatch.regprog); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1812 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1813 p_cpo = save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1814 return matches; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1815 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1816 |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1817 /* |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1818 * 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
|
1819 * "expr->name(arg)". |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1820 * Returns OK or FAIL. |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1821 */ |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1822 static int |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1823 eval_func( |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1824 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
|
1825 evalarg_T *evalarg, |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1826 char_u *name, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1827 int name_len, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1828 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
|
1829 int flags, |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1830 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
|
1831 { |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1832 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
|
1833 char_u *s = name; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1834 int len = name_len; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1835 partial_T *partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1836 int ret = OK; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1837 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1838 if (!evaluate) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1839 check_vars(s, len); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1840 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1841 // 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
|
1842 // use its contents. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1843 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
|
1844 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1845 // 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
|
1846 // the name invalid. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1847 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
|
1848 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
|
1849 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1850 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1851 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1852 funcexe_T funcexe; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1853 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1854 // Invoke the function. |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1855 CLEAR_FIELD(funcexe); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1856 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
|
1857 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
|
1858 funcexe.evaluate = evaluate; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1859 funcexe.partial = partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1860 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
|
1861 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
|
1862 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1863 vim_free(s); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1864 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1865 // 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
|
1866 // 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
|
1867 // 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
|
1868 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
|
1869 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1870 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
|
1871 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
|
1872 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1873 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1874 // 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
|
1875 // 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
|
1876 // 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
|
1877 if (evaluate && aborting()) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1878 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1879 if (ret == OK) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1880 clear_tv(rettv); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1881 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1882 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1883 return ret; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1884 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1885 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1886 /* |
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
|
1887 * 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
|
1888 * 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
|
1889 * 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
|
1890 * 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
|
1891 * "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
|
1892 */ |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21026
diff
changeset
|
1893 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
|
1894 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
|
1895 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1896 *getnext = FALSE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1897 if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1898 && evalarg != NULL |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1899 && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != 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
|
1900 && (*arg == NUL || (VIM_ISWHITE(arg[-1]) |
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
|
1901 && *arg == '#' && arg[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
|
1902 { |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1903 char_u *p; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1904 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1905 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
|
1906 p = getline_peek(evalarg->eval_getline, evalarg->eval_cookie); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1907 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1908 p = peek_next_line_from_context(evalarg->eval_cctx); |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1909 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1910 if (p != NULL) |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1911 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1912 *getnext = TRUE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1913 return skipwhite(p); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1914 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1915 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1916 return arg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1917 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1918 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1919 /* |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1920 * 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
|
1921 */ |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21026
diff
changeset
|
1922 char_u * |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1923 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
|
1924 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1925 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
|
1926 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
|
1927 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1928 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
|
1929 line = evalarg->eval_getline(0, evalarg->eval_cookie, 0, TRUE); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1930 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1931 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
|
1932 ++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
|
1933 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
|
1934 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1935 // 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
|
1936 ((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
|
1937 ++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
|
1938 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1939 else |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1940 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1941 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
|
1942 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
|
1943 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1944 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
|
1945 } |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1946 |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
1947 /* |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
1948 * 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
|
1949 */ |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1950 char_u * |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1951 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
|
1952 { |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1953 int getnext; |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1954 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
|
1955 |
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
|
1956 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
|
1957 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
|
1958 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
|
1959 if (getnext) |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1960 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
|
1961 return p; |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1962 } |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1963 |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1964 /* |
21050
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1965 * After using "evalarg" filled from "eap" free the memory. |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1966 */ |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1967 void |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1968 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
|
1969 { |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1970 if (evalarg != NULL && evalarg->eval_tofree != NULL) |
21050
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1971 { |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1972 if (eap != NULL) |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1973 { |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1974 // We may need to keep the original command line, e.g. for |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1975 // ":let" it has the variable names. But we may also need the |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1976 // new one, "nextcmd" points into it. Keep both. |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1977 vim_free(eap->cmdline_tofree); |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1978 eap->cmdline_tofree = *eap->cmdlinep; |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1979 *eap->cmdlinep = evalarg->eval_tofree; |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1980 } |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1981 else |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1982 vim_free(evalarg->eval_tofree); |
21050
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1983 evalarg->eval_tofree = NULL; |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1984 } |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1985 } |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1986 |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1987 /* |
7 | 1988 * The "evaluate" argument: When FALSE, the argument is only parsed but not |
71 | 1989 * executed. The function may return OK, but the rettv will be of type |
7 | 1990 * VAR_UNKNOWN. The function still returns FAIL for a syntax error. |
1991 */ | |
1992 | |
1993 /* | |
1994 * Handle zero level expression. | |
1995 * This calls eval1() and handles error message and nextcmd. | |
71 | 1996 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. |
533 | 1997 * 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
|
1998 * "evalarg" can be NULL, EVALARG_EVALUATE or a pointer. |
7 | 1999 * Return OK or FAIL. |
2000 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
2001 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2002 eval0( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2003 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2004 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
|
2005 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
|
2006 evalarg_T *evalarg) |
7 | 2007 { |
2008 int ret; | |
2009 char_u *p; | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
2010 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
|
2011 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
|
2012 int flags = evalarg == NULL ? 0 : evalarg->eval_flags; |
7 | 2013 |
2014 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
|
2015 ret = eval1(&p, rettv, evalarg); |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2016 |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2017 if (ret == FAIL || !ends_excmd2(arg, p)) |
7 | 2018 { |
2019 if (ret != FAIL) | |
71 | 2020 clear_tv(rettv); |
7 | 2021 /* |
2022 * Report the invalid expression unless the expression evaluation has | |
2023 * 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
|
2024 * 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
|
2025 * Also check called_emsg for when using assert_fails(). |
7 | 2026 */ |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2027 if (!aborting() |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2028 && 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
|
2029 && 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
|
2030 && (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
|
2031 semsg(_(e_invexpr2), arg); |
7 | 2032 ret = FAIL; |
2033 } | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2034 |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2035 if (eap != NULL) |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2036 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
|
2037 |
7 | 2038 return ret; |
2039 } | |
2040 | |
2041 /* | |
2042 * Handle top level expression: | |
1800 | 2043 * expr2 ? expr1 : expr1 |
7 | 2044 * |
2045 * "arg" must point to the first non-white of the expression. | |
2046 * "arg" is advanced to the next non-white after the recognized expression. | |
2047 * | |
533 | 2048 * Note: "rettv.v_lock" is not set. |
2049 * | |
7 | 2050 * Return OK or FAIL. |
2051 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
2052 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
|
2053 eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2054 { |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2055 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
|
2056 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
|
2057 |
7 | 2058 /* |
2059 * Get the first variable. | |
2060 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2061 if (eval2(arg, rettv, evalarg) == FAIL) |
7 | 2062 return FAIL; |
2063 | |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2064 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
|
2065 if (*p == '?') |
7 | 2066 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2067 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
|
2068 typval_T var2; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2069 evalarg_T nested_evalarg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2070 int orig_flags; |
21002
4852db420162
patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2071 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
|
2072 |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2073 if (getnext) |
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2074 *arg = eval_next_line(evalarg); |
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2075 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2076 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
|
2077 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2078 CLEAR_FIELD(nested_evalarg); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2079 orig_flags = 0; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2080 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2081 else |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2082 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2083 nested_evalarg = *evalarg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2084 orig_flags = evalarg->eval_flags; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2085 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2086 |
21002
4852db420162
patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2087 evaluate = nested_evalarg.eval_flags & EVAL_EVALUATE; |
7 | 2088 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
|
2089 if (evaluate) |
7 | 2090 { |
323 | 2091 int error = FALSE; |
2092 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2093 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 2094 result = TRUE; |
71 | 2095 clear_tv(rettv); |
323 | 2096 if (error) |
2097 return FAIL; | |
7 | 2098 } |
2099 | |
2100 /* | |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2101 * Get the second variable. Recursive! |
7 | 2102 */ |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2103 *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
|
2104 nested_evalarg.eval_flags = result ? 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
|
2105 : orig_flags & ~EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2106 if (eval1(arg, rettv, &nested_evalarg) == FAIL) |
7 | 2107 return FAIL; |
2108 | |
2109 /* | |
2110 * Check for the ":". | |
2111 */ | |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2112 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
|
2113 if (*p != ':') |
7 | 2114 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2115 emsg(_(e_missing_colon)); |
7 | 2116 if (evaluate && result) |
71 | 2117 clear_tv(rettv); |
7 | 2118 return FAIL; |
2119 } | |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2120 if (getnext) |
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2121 *arg = eval_next_line(evalarg); |
7 | 2122 |
2123 /* | |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2124 * Get the third variable. Recursive! |
7 | 2125 */ |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2126 *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
|
2127 nested_evalarg.eval_flags = !result ? 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
|
2128 : orig_flags & ~EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2129 if (eval1(arg, &var2, &nested_evalarg) == FAIL) |
7 | 2130 { |
2131 if (evaluate && result) | |
71 | 2132 clear_tv(rettv); |
7 | 2133 return FAIL; |
2134 } | |
2135 if (evaluate && !result) | |
71 | 2136 *rettv = var2; |
7 | 2137 } |
2138 | |
2139 return OK; | |
2140 } | |
2141 | |
2142 /* | |
2143 * Handle first level expression: | |
2144 * expr2 || expr2 || expr2 logical OR | |
2145 * | |
2146 * "arg" must point to the first non-white of the expression. | |
2147 * "arg" is advanced to the next non-white after the recognized expression. | |
2148 * | |
2149 * Return OK or FAIL. | |
2150 */ | |
2151 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
|
2152 eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2153 { |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2154 char_u *p; |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2155 int getnext; |
137 | 2156 typval_T var2; |
7 | 2157 long result; |
2158 int first; | |
323 | 2159 int error = FALSE; |
7 | 2160 |
2161 /* | |
2162 * Get the first variable. | |
2163 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2164 if (eval3(arg, rettv, evalarg) == FAIL) |
7 | 2165 return FAIL; |
2166 | |
2167 /* | |
2168 * Repeat until there is no following "||". | |
2169 */ | |
2170 first = TRUE; | |
2171 result = FALSE; | |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2172 p = eval_next_non_blank(*arg, evalarg, &getnext); |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2173 while (p[0] == '|' && p[1] == '|') |
7 | 2174 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2175 evalarg_T nested_evalarg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2176 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
|
2177 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
|
2178 |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2179 if (getnext) |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2180 *arg = eval_next_line(evalarg); |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2181 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2182 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
|
2183 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2184 CLEAR_FIELD(nested_evalarg); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2185 orig_flags = 0; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2186 evaluate = FALSE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2187 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2188 else |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2189 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2190 nested_evalarg = *evalarg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2191 orig_flags = evalarg->eval_flags; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2192 evaluate = orig_flags & EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2193 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2194 |
7 | 2195 if (evaluate && first) |
2196 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2197 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 2198 result = TRUE; |
71 | 2199 clear_tv(rettv); |
323 | 2200 if (error) |
2201 return FAIL; | |
7 | 2202 first = FALSE; |
2203 } | |
2204 | |
2205 /* | |
2206 * Get the second variable. | |
2207 */ | |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2208 *arg = skipwhite_and_linebreak(*arg + 2, 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
|
2209 nested_evalarg.eval_flags = !result ? 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
|
2210 : orig_flags & ~EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2211 if (eval3(arg, &var2, &nested_evalarg) == FAIL) |
7 | 2212 return FAIL; |
2213 | |
2214 /* | |
2215 * Compute the result. | |
2216 */ | |
2217 if (evaluate && !result) | |
2218 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2219 if (tv_get_number_chk(&var2, &error) != 0) |
7 | 2220 result = TRUE; |
71 | 2221 clear_tv(&var2); |
323 | 2222 if (error) |
2223 return FAIL; | |
7 | 2224 } |
2225 if (evaluate) | |
2226 { | |
71 | 2227 rettv->v_type = VAR_NUMBER; |
2228 rettv->vval.v_number = result; | |
7 | 2229 } |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2230 |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2231 p = eval_next_non_blank(*arg, evalarg, &getnext); |
7 | 2232 } |
2233 | |
2234 return OK; | |
2235 } | |
2236 | |
2237 /* | |
2238 * Handle second level expression: | |
2239 * expr3 && expr3 && expr3 logical AND | |
2240 * | |
2241 * "arg" must point to the first non-white of the expression. | |
2242 * "arg" is advanced to the next non-white after the recognized expression. | |
2243 * | |
2244 * Return OK or FAIL. | |
2245 */ | |
2246 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
|
2247 eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2248 { |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2249 char_u *p; |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2250 int getnext; |
137 | 2251 typval_T var2; |
7 | 2252 long result; |
2253 int first; | |
323 | 2254 int error = FALSE; |
7 | 2255 |
2256 /* | |
2257 * Get the first variable. | |
2258 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2259 if (eval4(arg, rettv, evalarg) == FAIL) |
7 | 2260 return FAIL; |
2261 | |
2262 /* | |
2263 * Repeat until there is no following "&&". | |
2264 */ | |
2265 first = TRUE; | |
2266 result = TRUE; | |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2267 p = eval_next_non_blank(*arg, evalarg, &getnext); |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2268 while (p[0] == '&' && p[1] == '&') |
7 | 2269 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2270 evalarg_T nested_evalarg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2271 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
|
2272 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
|
2273 |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2274 if (getnext) |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2275 *arg = eval_next_line(evalarg); |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2276 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2277 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
|
2278 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2279 CLEAR_FIELD(nested_evalarg); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2280 orig_flags = 0; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2281 evaluate = FALSE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2282 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2283 else |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2284 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2285 nested_evalarg = *evalarg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2286 orig_flags = evalarg->eval_flags; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2287 evaluate = orig_flags & EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2288 } |
7 | 2289 if (evaluate && first) |
2290 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2291 if (tv_get_number_chk(rettv, &error) == 0) |
7 | 2292 result = FALSE; |
71 | 2293 clear_tv(rettv); |
323 | 2294 if (error) |
2295 return FAIL; | |
7 | 2296 first = FALSE; |
2297 } | |
2298 | |
2299 /* | |
2300 * Get the second variable. | |
2301 */ | |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2302 *arg = skipwhite_and_linebreak(*arg + 2, 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
|
2303 nested_evalarg.eval_flags = result ? 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
|
2304 : orig_flags & ~EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2305 if (eval4(arg, &var2, &nested_evalarg) == FAIL) |
7 | 2306 return FAIL; |
2307 | |
2308 /* | |
2309 * Compute the result. | |
2310 */ | |
2311 if (evaluate && result) | |
2312 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2313 if (tv_get_number_chk(&var2, &error) == 0) |
7 | 2314 result = FALSE; |
71 | 2315 clear_tv(&var2); |
323 | 2316 if (error) |
2317 return FAIL; | |
7 | 2318 } |
2319 if (evaluate) | |
2320 { | |
71 | 2321 rettv->v_type = VAR_NUMBER; |
2322 rettv->vval.v_number = result; | |
7 | 2323 } |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2324 |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2325 p = eval_next_non_blank(*arg, evalarg, &getnext); |
7 | 2326 } |
2327 | |
2328 return OK; | |
2329 } | |
2330 | |
2331 /* | |
2332 * Handle third level expression: | |
2333 * var1 == var2 | |
2334 * var1 =~ var2 | |
2335 * var1 != var2 | |
2336 * var1 !~ var2 | |
2337 * var1 > var2 | |
2338 * var1 >= var2 | |
2339 * var1 < var2 | |
2340 * var1 <= var2 | |
80 | 2341 * var1 is var2 |
2342 * var1 isnot var2 | |
7 | 2343 * |
2344 * "arg" must point to the first non-white of the expression. | |
2345 * "arg" is advanced to the next non-white after the recognized expression. | |
2346 * | |
2347 * Return OK or FAIL. | |
2348 */ | |
2349 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
|
2350 eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2351 { |
137 | 2352 typval_T var2; |
7 | 2353 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
|
2354 int getnext; |
7 | 2355 int i; |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2356 exptype_T type = EXPR_UNKNOWN; |
7 | 2357 int len = 2; |
2358 int ic; | |
2359 | |
2360 /* | |
2361 * Get the first variable. | |
2362 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2363 if (eval5(arg, rettv, evalarg) == FAIL) |
7 | 2364 return FAIL; |
2365 | |
21026
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2366 p = eval_next_non_blank(*arg, evalarg, &getnext); |
7 | 2367 switch (p[0]) |
2368 { | |
2369 case '=': if (p[1] == '=') | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2370 type = EXPR_EQUAL; |
7 | 2371 else if (p[1] == '~') |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2372 type = EXPR_MATCH; |
7 | 2373 break; |
2374 case '!': if (p[1] == '=') | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2375 type = EXPR_NEQUAL; |
7 | 2376 else if (p[1] == '~') |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2377 type = EXPR_NOMATCH; |
7 | 2378 break; |
2379 case '>': if (p[1] != '=') | |
2380 { | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2381 type = EXPR_GREATER; |
7 | 2382 len = 1; |
2383 } | |
2384 else | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2385 type = EXPR_GEQUAL; |
7 | 2386 break; |
2387 case '<': if (p[1] != '=') | |
2388 { | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2389 type = EXPR_SMALLER; |
7 | 2390 len = 1; |
2391 } | |
2392 else | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2393 type = EXPR_SEQUAL; |
7 | 2394 break; |
80 | 2395 case 'i': if (p[1] == 's') |
2396 { | |
2397 if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') | |
2398 len = 5; | |
7064
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2399 i = p[len]; |
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2400 if (!isalnum(i) && i != '_') |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2401 type = len == 2 ? EXPR_IS : EXPR_ISNOT; |
80 | 2402 } |
2403 break; | |
7 | 2404 } |
2405 | |
2406 /* | |
1624 | 2407 * If there is a comparative operator, use it. |
7 | 2408 */ |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2409 if (type != EXPR_UNKNOWN) |
7 | 2410 { |
21026
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2411 if (getnext) |
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2412 *arg = eval_next_line(evalarg); |
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2413 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2414 // extra question mark appended: ignore case |
7 | 2415 if (p[len] == '?') |
2416 { | |
2417 ic = TRUE; | |
2418 ++len; | |
2419 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2420 // extra '#' appended: match case |
7 | 2421 else if (p[len] == '#') |
2422 { | |
2423 ic = FALSE; | |
2424 ++len; | |
2425 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2426 // nothing appended: use 'ignorecase' |
7 | 2427 else |
2428 ic = p_ic; | |
2429 | |
2430 /* | |
2431 * Get the second variable. | |
2432 */ | |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2433 *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
|
2434 if (eval5(arg, &var2, evalarg) == FAIL) |
7 | 2435 { |
71 | 2436 clear_tv(rettv); |
7 | 2437 return FAIL; |
2438 } | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2439 if (evalarg != NULL && (evalarg->eval_flags & EVAL_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
|
2440 { |
18966
6bd715870e32
patch 8.2.0044: expression type is used inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
18939
diff
changeset
|
2441 int 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
|
2442 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2443 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
|
2444 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
|
2445 } |
7 | 2446 } |
2447 | |
2448 return OK; | |
2449 } | |
2450 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2451 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2452 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
|
2453 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2454 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
|
2455 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
|
2456 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
|
2457 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2458 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2459 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
|
2460 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2461 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
|
2462 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
|
2463 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
|
2464 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
|
2465 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2466 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
|
2467 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
|
2468 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2469 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2470 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2471 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2472 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
|
2473 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2474 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
|
2475 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2476 // concatenate Lists |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2477 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
|
2478 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2479 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
|
2480 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
|
2481 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2482 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2483 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
|
2484 *tv1 = var3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2485 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2486 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2487 |
7 | 2488 /* |
2489 * Handle fourth level expression: | |
2490 * + number addition | |
2491 * - number subtraction | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2492 * . 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
|
2493 * .. string concatenation |
7 | 2494 * |
2495 * "arg" must point to the first non-white of the expression. | |
2496 * "arg" is advanced to the next non-white after the recognized expression. | |
2497 * | |
2498 * Return OK or FAIL. | |
2499 */ | |
2500 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
|
2501 eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2502 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2503 int evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE); |
7 | 2504 |
2505 /* | |
2506 * Get the first variable. | |
2507 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2508 if (eval6(arg, rettv, evalarg, FALSE) == FAIL) |
7 | 2509 return FAIL; |
2510 | |
2511 /* | |
2512 * Repeat computing, until no '+', '-' or '.' is following. | |
2513 */ | |
2514 for (;;) | |
2515 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2516 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
|
2517 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
|
2518 int op; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2519 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
|
2520 typval_T var2; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2521 |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2522 // "." 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
|
2523 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
|
2524 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
|
2525 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
|
2526 if (op != '+' && op != '-' && !concat) |
7 | 2527 break; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2528 if (getnext) |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2529 *arg = eval_next_line(evalarg); |
7 | 2530 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2531 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
|
2532 && rettv->v_type != VAR_BLOB)) |
1624 | 2533 #ifdef FEAT_FLOAT |
2534 && (op == '.' || rettv->v_type != VAR_FLOAT) | |
2535 #endif | |
2536 ) | |
323 | 2537 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2538 // 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
|
2539 // 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
|
2540 // 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
|
2541 // 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
|
2542 // 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
|
2543 // 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
|
2544 // 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
|
2545 if (evaluate && tv_get_string_chk(rettv) == NULL) |
323 | 2546 { |
2547 clear_tv(rettv); | |
2548 return FAIL; | |
2549 } | |
2550 } | |
2551 | |
7 | 2552 /* |
2553 * Get the second variable. | |
2554 */ | |
16219
bd49e1656c72
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents:
16170
diff
changeset
|
2555 if (op == '.' && *(*arg + 1) == '.') // .. string concatenation |
bd49e1656c72
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents:
16170
diff
changeset
|
2556 ++*arg; |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2557 *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
|
2558 if (eval6(arg, &var2, evalarg, op == '.') == FAIL) |
7 | 2559 { |
71 | 2560 clear_tv(rettv); |
7 | 2561 return FAIL; |
2562 } | |
2563 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2564 if (evaluate) |
7 | 2565 { |
2566 /* | |
2567 * Compute the result. | |
2568 */ | |
2569 if (op == '.') | |
2570 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2571 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
|
2572 char_u *s1 = tv_get_string_buf(rettv, buf1); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2573 char_u *s2 = tv_get_string_buf_chk(&var2, buf2); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2574 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2575 if (s2 == NULL) // type error ? |
323 | 2576 { |
2577 clear_tv(rettv); | |
2578 clear_tv(&var2); | |
2579 return FAIL; | |
2580 } | |
117 | 2581 p = concat_str(s1, s2); |
71 | 2582 clear_tv(rettv); |
2583 rettv->v_type = VAR_STRING; | |
2584 rettv->vval.v_string = p; | |
7 | 2585 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2586 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
|
2587 && 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
|
2588 eval_addblob(rettv, &var2); |
104 | 2589 else if (op == '+' && rettv->v_type == VAR_LIST |
2590 && var2.v_type == VAR_LIST) | |
80 | 2591 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2592 if (eval_addlist(rettv, &var2) == FAIL) |
80 | 2593 return FAIL; |
2594 } | |
7 | 2595 else |
2596 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2597 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
|
2598 varnumber_T n1, n2; |
1624 | 2599 #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
|
2600 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
|
2601 |
1624 | 2602 if (rettv->v_type == VAR_FLOAT) |
2603 { | |
2604 f1 = rettv->vval.v_float; | |
2605 n1 = 0; | |
2606 } | |
2607 else | |
2608 #endif | |
2609 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2610 n1 = tv_get_number_chk(rettv, &error); |
1624 | 2611 if (error) |
2612 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2613 // 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
|
2614 // "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
|
2615 // before evaluating the 2nd operand. |
1624 | 2616 clear_tv(rettv); |
2617 return FAIL; | |
2618 } | |
2619 #ifdef FEAT_FLOAT | |
2620 if (var2.v_type == VAR_FLOAT) | |
2621 f1 = n1; | |
2622 #endif | |
2623 } | |
2624 #ifdef FEAT_FLOAT | |
2625 if (var2.v_type == VAR_FLOAT) | |
2626 { | |
2627 f2 = var2.vval.v_float; | |
2628 n2 = 0; | |
2629 } | |
2630 else | |
2631 #endif | |
2632 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2633 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2634 if (error) |
2635 { | |
2636 clear_tv(rettv); | |
2637 clear_tv(&var2); | |
2638 return FAIL; | |
2639 } | |
2640 #ifdef FEAT_FLOAT | |
2641 if (rettv->v_type == VAR_FLOAT) | |
2642 f2 = n2; | |
2643 #endif | |
323 | 2644 } |
71 | 2645 clear_tv(rettv); |
1624 | 2646 |
2647 #ifdef FEAT_FLOAT | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2648 // If there is a float on either side the result is a float. |
1624 | 2649 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) |
2650 { | |
2651 if (op == '+') | |
2652 f1 = f1 + f2; | |
2653 else | |
2654 f1 = f1 - f2; | |
2655 rettv->v_type = VAR_FLOAT; | |
2656 rettv->vval.v_float = f1; | |
2657 } | |
2658 else | |
2659 #endif | |
2660 { | |
2661 if (op == '+') | |
2662 n1 = n1 + n2; | |
2663 else | |
2664 n1 = n1 - n2; | |
2665 rettv->v_type = VAR_NUMBER; | |
2666 rettv->vval.v_number = n1; | |
2667 } | |
71 | 2668 } |
2669 clear_tv(&var2); | |
7 | 2670 } |
2671 } | |
2672 return OK; | |
2673 } | |
2674 | |
2675 /* | |
2676 * Handle fifth level expression: | |
2677 * * number multiplication | |
2678 * / number division | |
2679 * % number modulo | |
2680 * | |
2681 * "arg" must point to the first non-white of the expression. | |
2682 * "arg" is advanced to the next non-white after the recognized expression. | |
2683 * | |
2684 * Return OK or FAIL. | |
2685 */ | |
2686 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2687 eval6( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2688 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2689 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
|
2690 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2691 int want_string) // after "." operator |
7 | 2692 { |
137 | 2693 typval_T var2; |
7 | 2694 int op; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2695 varnumber_T n1, n2; |
1624 | 2696 #ifdef FEAT_FLOAT |
2697 int use_float = FALSE; | |
16405
840fa633ad64
patch 8.1.1207: some compilers give warning messages
Bram Moolenaar <Bram@vim.org>
parents:
16366
diff
changeset
|
2698 float_T f1 = 0, f2 = 0; |
1624 | 2699 #endif |
323 | 2700 int error = FALSE; |
7 | 2701 |
2702 /* | |
2703 * Get the first variable. | |
2704 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2705 if (eval7(arg, rettv, evalarg, want_string) == FAIL) |
7 | 2706 return FAIL; |
2707 | |
2708 /* | |
2709 * Repeat computing, until no '*', '/' or '%' is following. | |
2710 */ | |
2711 for (;;) | |
2712 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2713 int evaluate = evalarg == NULL ? 0 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2714 : (evalarg->eval_flags & EVAL_EVALUATE); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2715 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
|
2716 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2717 op = *eval_next_non_blank(*arg, evalarg, &getnext); |
17387
2558f90045e5
patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents:
17377
diff
changeset
|
2718 if (op != '*' && op != '/' && op != '%') |
7 | 2719 break; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2720 if (getnext) |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2721 *arg = eval_next_line(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
|
2722 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2723 if (evaluate) |
7 | 2724 { |
1624 | 2725 #ifdef FEAT_FLOAT |
2726 if (rettv->v_type == VAR_FLOAT) | |
2727 { | |
2728 f1 = rettv->vval.v_float; | |
2729 use_float = TRUE; | |
2730 n1 = 0; | |
2731 } | |
2732 else | |
2733 #endif | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2734 n1 = tv_get_number_chk(rettv, &error); |
71 | 2735 clear_tv(rettv); |
323 | 2736 if (error) |
2737 return FAIL; | |
7 | 2738 } |
2739 else | |
2740 n1 = 0; | |
2741 | |
2742 /* | |
2743 * Get the second variable. | |
2744 */ | |
2745 *arg = skipwhite(*arg + 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
|
2746 if (eval7(arg, &var2, evalarg, FALSE) == FAIL) |
7 | 2747 return FAIL; |
2748 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2749 if (evaluate) |
7 | 2750 { |
1624 | 2751 #ifdef FEAT_FLOAT |
2752 if (var2.v_type == VAR_FLOAT) | |
2753 { | |
2754 if (!use_float) | |
2755 { | |
2756 f1 = n1; | |
2757 use_float = TRUE; | |
2758 } | |
2759 f2 = var2.vval.v_float; | |
2760 n2 = 0; | |
2761 } | |
2762 else | |
2763 #endif | |
2764 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2765 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2766 clear_tv(&var2); |
2767 if (error) | |
2768 return FAIL; | |
2769 #ifdef FEAT_FLOAT | |
2770 if (use_float) | |
2771 f2 = n2; | |
2772 #endif | |
2773 } | |
7 | 2774 |
2775 /* | |
2776 * Compute the result. | |
1624 | 2777 * When either side is a float the result is a float. |
7 | 2778 */ |
1624 | 2779 #ifdef FEAT_FLOAT |
2780 if (use_float) | |
2781 { | |
2782 if (op == '*') | |
2783 f1 = f1 * f2; | |
2784 else if (op == '/') | |
2785 { | |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2786 # ifdef VMS |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2787 // 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
|
2788 if (f2 == 0.0) |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2789 { |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2790 if (f1 == 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2791 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
|
2792 else if (f1 < 0) |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2793 f1 = -1 * __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2794 else |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2795 f1 = __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2796 } |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2797 else |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2798 f1 = f1 / f2; |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2799 # else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2800 // 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
|
2801 // by zero to result in "inf" and not a crash. |
1624 | 2802 f1 = f1 / f2; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2803 # endif |
1624 | 2804 } |
2805 else | |
2806 { | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2807 emsg(_(e_modulus)); |
1624 | 2808 return FAIL; |
2809 } | |
2810 rettv->v_type = VAR_FLOAT; | |
2811 rettv->vval.v_float = f1; | |
2812 } | |
2813 else | |
2814 #endif | |
2815 { | |
2816 if (op == '*') | |
2817 n1 = n1 * n2; | |
2818 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
|
2819 n1 = num_divide(n1, n2); |
1624 | 2820 else |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
2821 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
|
2822 |
1624 | 2823 rettv->v_type = VAR_NUMBER; |
2824 rettv->vval.v_number = n1; | |
2825 } | |
7 | 2826 } |
2827 } | |
2828 | |
2829 return OK; | |
2830 } | |
2831 | |
2832 /* | |
2833 * Handle sixth level expression: | |
2834 * number number constant | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2835 * 0zFFFFFFFF Blob constant |
1228 | 2836 * "string" string constant |
2837 * 'string' literal string constant | |
7 | 2838 * &option-name option value |
2839 * @r register contents | |
2840 * identifier variable value | |
2841 * function() function call | |
2842 * $VAR environment variable | |
2843 * (expression) nested expression | |
151 | 2844 * [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
|
2845 * {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
|
2846 * {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
|
2847 * #{key: val, key: val} Dictionary with literal keys |
7 | 2848 * |
2849 * Also handle: | |
2850 * ! in front logical NOT | |
2851 * - in front unary minus | |
2852 * + in front unary plus (ignored) | |
100 | 2853 * trailing [] subscript in String or List |
2854 * 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
|
2855 * trailing ->name() method call |
7 | 2856 * |
2857 * "arg" must point to the first non-white of the expression. | |
2858 * "arg" is advanced to the next non-white after the recognized expression. | |
2859 * | |
2860 * Return OK or FAIL. | |
2861 */ | |
2862 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2863 eval7( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2864 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2865 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
|
2866 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
|
2867 int want_string) // after "." operator |
7 | 2868 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2869 int flags = evalarg == NULL ? 0 : evalarg->eval_flags; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2870 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
|
2871 && (evalarg->eval_flags & EVAL_EVALUATE); |
7 | 2872 int len; |
2873 char_u *s; | |
2874 char_u *start_leader, *end_leader; | |
2875 int ret = OK; | |
2876 char_u *alias; | |
2877 | |
2878 /* | |
71 | 2879 * Initialise variable so that clear_tv() can't mistake this for a |
56 | 2880 * string and free a string that isn't there. |
7 | 2881 */ |
71 | 2882 rettv->v_type = VAR_UNKNOWN; |
7 | 2883 |
2884 /* | |
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10000
diff
changeset
|
2885 * Skip '!', '-' and '+' characters. They are handled later. |
7 | 2886 */ |
2887 start_leader = *arg; | |
2888 while (**arg == '!' || **arg == '-' || **arg == '+') | |
2889 *arg = skipwhite(*arg + 1); | |
2890 end_leader = *arg; | |
2891 | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2892 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
|
2893 #ifdef FEAT_FLOAT |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2894 || 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
|
2895 #endif |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2896 )) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2897 { |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2898 semsg(_(e_invexpr2), *arg); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2899 ++*arg; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2900 return FAIL; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2901 } |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2902 |
7 | 2903 switch (**arg) |
2904 { | |
2905 /* | |
2906 * Number constant. | |
2907 */ | |
2908 case '0': | |
2909 case '1': | |
2910 case '2': | |
2911 case '3': | |
2912 case '4': | |
2913 case '5': | |
2914 case '6': | |
2915 case '7': | |
2916 case '8': | |
2917 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
|
2918 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
|
2919 |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
2920 // 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
|
2921 // "->" follows. |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
2922 if (ret == OK && evaluate && end_leader > start_leader) |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
2923 ret = eval7_leader(rettv, TRUE, start_leader, &end_leader); |
1624 | 2924 break; |
7 | 2925 |
2926 /* | |
2927 * String constant: "string". | |
2928 */ | |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
2929 case '"': ret = eval_string(arg, rettv, evaluate); |
7 | 2930 break; |
2931 | |
2932 /* | |
100 | 2933 * Literal string constant: 'str''ing'. |
7 | 2934 */ |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
2935 case '\'': ret = eval_lit_string(arg, rettv, evaluate); |
56 | 2936 break; |
2937 | |
2938 /* | |
2939 * List: [expr, expr] | |
2940 */ | |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
2941 case '[': ret = eval_list(arg, rettv, evalarg, TRUE); |
7 | 2942 break; |
2943 | |
2944 /* | |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2945 * 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
|
2946 */ |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2947 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
|
2948 { |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2949 ++*arg; |
21034
2f8b0812819f
patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
2950 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
|
2951 } |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2952 else |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2953 ret = NOTDONE; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2954 break; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2955 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2956 /* |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2957 * 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
|
2958 * Dictionary: {'key': val, 'key': val} |
100 | 2959 */ |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
2960 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
|
2961 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
|
2962 ret = eval_dict(arg, rettv, evalarg, FALSE); |
100 | 2963 break; |
2964 | |
2965 /* | |
104 | 2966 * Option value: &name |
7 | 2967 */ |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
2968 case '&': ret = eval_option(arg, rettv, evaluate); |
7 | 2969 break; |
2970 | |
2971 /* | |
2972 * Environment variable: $VAR. | |
2973 */ | |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
2974 case '$': ret = eval_env_var(arg, rettv, evaluate); |
7 | 2975 break; |
2976 | |
2977 /* | |
2978 * Register contents: @r. | |
2979 */ | |
2980 case '@': ++*arg; | |
2981 if (evaluate) | |
2982 { | |
71 | 2983 rettv->v_type = VAR_STRING; |
5796 | 2984 rettv->vval.v_string = get_reg_contents(**arg, |
2985 GREG_EXPR_SRC); | |
7 | 2986 } |
2987 if (**arg != NUL) | |
2988 ++*arg; | |
2989 break; | |
2990 | |
2991 /* | |
2992 * nested expression: (expression). | |
2993 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2994 case '(': { |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2995 *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
|
2996 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
|
2997 |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2998 *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
|
2999 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
|
3000 ++*arg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3001 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
|
3002 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3003 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
|
3004 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
|
3005 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
|
3006 } |
7 | 3007 } |
3008 break; | |
3009 | |
100 | 3010 default: ret = NOTDONE; |
3011 break; | |
3012 } | |
3013 | |
3014 if (ret == NOTDONE) | |
3015 { | |
3016 /* | |
3017 * Must be a variable or function name. | |
3018 * Can also be a curly-braces kind of name: {expr}. | |
3019 */ | |
3020 s = *arg; | |
159 | 3021 len = get_name_len(arg, &alias, evaluate, TRUE); |
100 | 3022 if (alias != NULL) |
3023 s = alias; | |
3024 | |
159 | 3025 if (len <= 0) |
100 | 3026 ret = FAIL; |
3027 else | |
3028 { | |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3029 if (**arg == '(') |
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3030 // "name(..." recursive! |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
3031 ret = eval_func(arg, evalarg, s, len, rettv, flags, NULL); |
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
|
3032 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
|
3033 ret = FAIL; |
100 | 3034 else if (evaluate) |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3035 // get value of variable |
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3036 ret = eval_variable(s, len, rettv, NULL, TRUE, FALSE); |
117 | 3037 else |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3038 { |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
3039 // skip the name |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3040 check_vars(s, len); |
117 | 3041 ret = OK; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3042 } |
100 | 3043 } |
2690 | 3044 vim_free(alias); |
100 | 3045 } |
3046 | |
7 | 3047 *arg = skipwhite(*arg); |
3048 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3049 // 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
|
3050 // expr(expr), expr->name(expr) |
159 | 3051 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
|
3052 ret = handle_subscript(arg, rettv, evalarg, TRUE); |
7 | 3053 |
3054 /* | |
3055 * Apply logical NOT and unary '-', from right to left, ignore '+'. | |
3056 */ | |
3057 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
|
3058 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
|
3059 return ret; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3060 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3061 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3062 /* |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3063 * 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
|
3064 * 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
|
3065 * 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
|
3066 */ |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3067 static int |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3068 eval7_leader( |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3069 typval_T *rettv, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3070 int numeric_only, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3071 char_u *start_leader, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3072 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
|
3073 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3074 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
|
3075 int ret = OK; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3076 int error = FALSE; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3077 varnumber_T val = 0; |
1624 | 3078 #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
|
3079 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
|
3080 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3081 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
|
3082 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
|
3083 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3084 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3085 val = tv_get_number_chk(rettv, &error); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3086 if (error) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3087 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3088 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3089 ret = FAIL; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3090 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3091 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3092 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3093 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
|
3094 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3095 --end_leader; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3096 if (*end_leader == '!') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3097 { |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3098 if (numeric_only) |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3099 { |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3100 ++end_leader; |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3101 break; |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3102 } |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3103 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3104 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
|
3105 f = !f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3106 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3107 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3108 val = !val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3109 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3110 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
|
3111 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3112 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3113 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
|
3114 f = -f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3115 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3116 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3117 val = -val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3118 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3119 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3120 #ifdef FEAT_FLOAT |
1624 | 3121 if (rettv->v_type == VAR_FLOAT) |
323 | 3122 { |
3123 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
|
3124 rettv->vval.v_float = f; |
323 | 3125 } |
3126 else | |
1624 | 3127 #endif |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3128 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3129 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3130 rettv->v_type = VAR_NUMBER; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3131 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
|
3132 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3133 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3134 *end_leaderp = end_leader; |
7 | 3135 return ret; |
3136 } | |
3137 | |
3138 /* | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3139 * 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
|
3140 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3141 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3142 call_func_rettv( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3143 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
|
3144 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
|
3145 typval_T *rettv, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3146 int evaluate, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3147 dict_T *selfdict, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3148 typval_T *basetv) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3149 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3150 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
|
3151 funcexe_T funcexe; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3152 typval_T functv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3153 char_u *s; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3154 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3155 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3156 // 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
|
3157 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3158 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3159 functv = *rettv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3160 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
|
3161 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3162 // 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
|
3163 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
|
3164 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3165 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
|
3166 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
|
3167 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3168 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3169 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
|
3170 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3171 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3172 s = (char_u *)""; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3173 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
3174 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
|
3175 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
|
3176 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
|
3177 funcexe.evaluate = evaluate; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3178 funcexe.partial = pt; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3179 funcexe.selfdict = selfdict; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3180 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
|
3181 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
|
3182 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3183 // 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
|
3184 // 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
|
3185 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3186 clear_tv(&functv); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3187 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3188 return ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3189 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3190 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3191 /* |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3192 * Evaluate "->method()". |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3193 * "*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
|
3194 * 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
|
3195 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3196 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3197 eval_lambda( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3198 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3199 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
|
3200 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3201 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
|
3202 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3203 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
|
3204 && (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
|
3205 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
|
3206 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3207 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3208 // Skip over the ->. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3209 *arg += 2; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3210 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
|
3211 |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3212 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
|
3213 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
|
3214 return FAIL; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3215 else if (**arg != '(') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3216 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3217 if (verbose) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3218 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3219 if (*skipwhite(*arg) == '(') |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
3220 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
|
3221 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3222 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
|
3223 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3224 clear_tv(rettv); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3225 ret = FAIL; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3226 } |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3227 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
|
3228 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
|
3229 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3230 // 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
|
3231 // 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
|
3232 if (evaluate) |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3233 clear_tv(&base); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3234 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3235 return ret; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3236 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3237 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3238 /* |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3239 * Evaluate "->method()". |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3240 * "*arg" points to the '-'. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3241 * 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
|
3242 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3243 static int |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3244 eval_method( |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3245 char_u **arg, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3246 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
|
3247 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3248 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
|
3249 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3250 char_u *name; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3251 long len; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3252 char_u *alias; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3253 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
|
3254 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
|
3255 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
|
3256 && (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
|
3257 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3258 // Skip over the ->. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3259 *arg += 2; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3260 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
|
3261 |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3262 name = *arg; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3263 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
|
3264 if (alias != NULL) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3265 name = alias; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3266 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3267 if (len <= 0) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3268 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3269 if (verbose) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3270 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
|
3271 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3272 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3273 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3274 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3275 if (**arg != '(') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3276 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3277 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
|
3278 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
|
3279 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3280 } |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3281 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
|
3282 { |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3283 if (verbose) |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
3284 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
|
3285 ret = FAIL; |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3286 } |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3287 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
|
3288 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
|
3289 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
|
3290 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3291 |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3292 // 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
|
3293 // 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
|
3294 if (evaluate) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3295 clear_tv(&base); |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3296 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3297 return ret; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3298 } |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3299 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3300 /* |
829 | 3301 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". |
3302 * "*arg" points to the '[' or '.'. | |
56 | 3303 * Returns FAIL or OK. "*arg" is advanced to after the ']'. |
3304 */ | |
3305 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3306 eval_index( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3307 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3308 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
|
3309 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3310 int verbose) // give error messages |
56 | 3311 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3312 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
|
3313 && (evalarg->eval_flags & EVAL_EVALUATE); |
56 | 3314 int empty1 = FALSE, empty2 = FALSE; |
137 | 3315 typval_T var1, var2; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3316 long i; |
56 | 3317 long n1, n2 = 0; |
100 | 3318 long len = -1; |
3319 int range = FALSE; | |
56 | 3320 char_u *s; |
100 | 3321 char_u *key = NULL; |
56 | 3322 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3323 switch (rettv->v_type) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3324 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3325 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
3326 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3327 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3328 emsg(_("E695: Cannot index a Funcref")); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3329 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3330 case VAR_FLOAT: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3331 #ifdef FEAT_FLOAT |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3332 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3333 emsg(_(e_float_as_string)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3334 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3335 #endif |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
3336 case VAR_BOOL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3337 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3338 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3339 case VAR_CHANNEL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3340 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3341 emsg(_("E909: Cannot index a special variable")); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3342 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3343 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
|
3344 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
|
3345 case VAR_VOID: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3346 if (evaluate) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3347 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3348 // FALLTHROUGH |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3349 |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3350 case VAR_STRING: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3351 case VAR_NUMBER: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3352 case VAR_LIST: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3353 case VAR_DICT: |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3354 case VAR_BLOB: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3355 break; |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3356 } |
56 | 3357 |
7046
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3358 init_tv(&var1); |
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3359 init_tv(&var2); |
100 | 3360 if (**arg == '.') |
3361 { | |
3362 /* | |
3363 * dict.name | |
3364 */ | |
3365 key = *arg + 1; | |
3366 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
3367 ; | |
3368 if (len == 0) | |
3369 return FAIL; | |
3370 *arg = skipwhite(key + len); | |
3371 } | |
3372 else | |
3373 { | |
3374 /* | |
3375 * something[idx] | |
3376 * | |
3377 * Get the (first) variable from inside the []. | |
3378 */ | |
21142
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
3379 *arg = skipwhite_and_linebreak(*arg + 1, evalarg); |
100 | 3380 if (**arg == ':') |
3381 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
|
3382 else if (eval1(arg, &var1, evalarg) == FAIL) // recursive! |
56 | 3383 return FAIL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3384 else if (evaluate && tv_get_string_chk(&var1) == NULL) |
323 | 3385 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3386 // not a number or string |
323 | 3387 clear_tv(&var1); |
3388 return FAIL; | |
3389 } | |
100 | 3390 |
3391 /* | |
3392 * Get the second variable from inside the [:]. | |
3393 */ | |
21142
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
3394 *arg = skipwhite_and_linebreak(*arg, evalarg); |
100 | 3395 if (**arg == ':') |
3396 { | |
3397 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
|
3398 *arg = skipwhite_and_linebreak(*arg + 1, evalarg); |
100 | 3399 if (**arg == ']') |
3400 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
|
3401 else if (eval1(arg, &var2, evalarg) == FAIL) // recursive! |
100 | 3402 { |
323 | 3403 if (!empty1) |
3404 clear_tv(&var1); | |
3405 return FAIL; | |
3406 } | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3407 else if (evaluate && tv_get_string_chk(&var2) == NULL) |
323 | 3408 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3409 // not a number or string |
323 | 3410 if (!empty1) |
3411 clear_tv(&var1); | |
3412 clear_tv(&var2); | |
100 | 3413 return FAIL; |
3414 } | |
3415 } | |
3416 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3417 // 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
|
3418 *arg = skipwhite_and_linebreak(*arg, evalarg); |
100 | 3419 if (**arg != ']') |
3420 { | |
159 | 3421 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3422 emsg(_(e_missbrac)); |
100 | 3423 clear_tv(&var1); |
3424 if (range) | |
3425 clear_tv(&var2); | |
3426 return FAIL; | |
3427 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3428 *arg = skipwhite(*arg + 1); // skip the ']' |
56 | 3429 } |
3430 | |
3431 if (evaluate) | |
3432 { | |
100 | 3433 n1 = 0; |
3434 if (!empty1 && rettv->v_type != VAR_DICT) | |
56 | 3435 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3436 n1 = tv_get_number(&var1); |
71 | 3437 clear_tv(&var1); |
56 | 3438 } |
3439 if (range) | |
3440 { | |
3441 if (empty2) | |
3442 n2 = -1; | |
3443 else | |
3444 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3445 n2 = tv_get_number(&var2); |
71 | 3446 clear_tv(&var2); |
3447 } | |
3448 } | |
3449 | |
3450 switch (rettv->v_type) | |
56 | 3451 { |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3452 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
|
3453 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
|
3454 case VAR_VOID: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3455 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
3456 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3457 case VAR_FLOAT: |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
3458 case VAR_BOOL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3459 case VAR_SPECIAL: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3460 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3461 case VAR_CHANNEL: |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3462 break; // not evaluating, skipping over subscript |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3463 |
56 | 3464 case VAR_NUMBER: |
3465 case VAR_STRING: | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3466 s = tv_get_string(rettv); |
56 | 3467 len = (long)STRLEN(s); |
3468 if (range) | |
3469 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3470 // 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
|
3471 // are out of range the result is empty. |
56 | 3472 if (n1 < 0) |
3473 { | |
3474 n1 = len + n1; | |
3475 if (n1 < 0) | |
3476 n1 = 0; | |
3477 } | |
3478 if (n2 < 0) | |
3479 n2 = len + n2; | |
3480 else if (n2 >= len) | |
3481 n2 = len; | |
3482 if (n1 >= len || n2 < 0 || n1 > n2) | |
3483 s = NULL; | |
3484 else | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
3485 s = vim_strnsave(s + n1, n2 - n1 + 1); |
56 | 3486 } |
3487 else | |
3488 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3489 // 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
|
3490 // 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
|
3491 // result is empty. |
56 | 3492 if (n1 >= len || n1 < 0) |
3493 s = NULL; | |
3494 else | |
3495 s = vim_strnsave(s + n1, 1); | |
3496 } | |
71 | 3497 clear_tv(rettv); |
3498 rettv->v_type = VAR_STRING; | |
3499 rettv->vval.v_string = s; | |
56 | 3500 break; |
3501 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3502 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3503 len = blob_len(rettv->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3504 if (range) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3505 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
3506 // The resulting variable is a sub-blob. If the indexes |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3507 // are out of range the result is empty. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3508 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3509 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3510 n1 = len + n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3511 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3512 n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3513 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3514 if (n2 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3515 n2 = len + n2; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3516 else if (n2 >= len) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3517 n2 = len - 1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3518 if (n1 >= len || n2 < 0 || n1 > n2) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3519 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3520 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3521 rettv->v_type = VAR_BLOB; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3522 rettv->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3523 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3524 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3525 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3526 blob_T *blob = blob_alloc(); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3527 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3528 if (blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3529 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3530 if (ga_grow(&blob->bv_ga, n2 - n1 + 1) == FAIL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3531 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3532 blob_free(blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3533 return FAIL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3534 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3535 blob->bv_ga.ga_len = n2 - n1 + 1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3536 for (i = n1; i <= n2; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3537 blob_set(blob, i - n1, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3538 blob_get(rettv->vval.v_blob, i)); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3539 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3540 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3541 rettv_blob_set(rettv, blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3542 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3543 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3544 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3545 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3546 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3547 // The resulting variable is a byte value. |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3548 // If the index is too big or negative that is an error. |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3549 if (n1 < 0) |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3550 n1 = len + n1; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3551 if (n1 < len && n1 >= 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3552 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3553 int v = blob_get(rettv->vval.v_blob, n1); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3554 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3555 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3556 rettv->v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3557 rettv->vval.v_number = v; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3558 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3559 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3560 semsg(_(e_blobidx), n1); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3561 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3562 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3563 |
56 | 3564 case VAR_LIST: |
71 | 3565 len = list_len(rettv->vval.v_list); |
56 | 3566 if (n1 < 0) |
3567 n1 = len + n1; | |
3568 if (!empty1 && (n1 < 0 || n1 >= len)) | |
3569 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3570 // For a range we allow invalid values and return an empty |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3571 // list. A list index out of range is an error. |
842 | 3572 if (!range) |
3573 { | |
3574 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3575 semsg(_(e_listidx), n1); |
842 | 3576 return FAIL; |
3577 } | |
3578 n1 = len; | |
56 | 3579 } |
3580 if (range) | |
3581 { | |
137 | 3582 list_T *l; |
56 | 3583 |
3584 if (n2 < 0) | |
3585 n2 = len + n2; | |
829 | 3586 else if (n2 >= len) |
3587 n2 = len - 1; | |
3588 if (!empty2 && (n2 < 0 || n2 + 1 < n1)) | |
842 | 3589 n2 = -1; |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
3590 l = list_slice(rettv->vval.v_list, n1, n2); |
56 | 3591 if (l == NULL) |
3592 return FAIL; | |
71 | 3593 clear_tv(rettv); |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11412
diff
changeset
|
3594 rettv_list_set(rettv, l); |
56 | 3595 } |
3596 else | |
3597 { | |
842 | 3598 copy_tv(&list_find(rettv->vval.v_list, n1)->li_tv, &var1); |
71 | 3599 clear_tv(rettv); |
3600 *rettv = var1; | |
56 | 3601 } |
3602 break; | |
100 | 3603 |
3604 case VAR_DICT: | |
3605 if (range) | |
3606 { | |
159 | 3607 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3608 emsg(_(e_dictrange)); |
100 | 3609 if (len == -1) |
3610 clear_tv(&var1); | |
3611 return FAIL; | |
3612 } | |
3613 { | |
137 | 3614 dictitem_T *item; |
100 | 3615 |
3616 if (len == -1) | |
3617 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3618 key = tv_get_string_chk(&var1); |
8839
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
3619 if (key == NULL) |
100 | 3620 { |
3621 clear_tv(&var1); | |
3622 return FAIL; | |
3623 } | |
3624 } | |
3625 | |
121 | 3626 item = dict_find(rettv->vval.v_dict, key, (int)len); |
100 | 3627 |
159 | 3628 if (item == NULL && verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3629 semsg(_(e_dictkey), key); |
100 | 3630 if (len == -1) |
3631 clear_tv(&var1); | |
3632 if (item == NULL) | |
3633 return FAIL; | |
3634 | |
3635 copy_tv(&item->di_tv, &var1); | |
3636 clear_tv(rettv); | |
3637 *rettv = var1; | |
3638 } | |
3639 break; | |
3640 } | |
3641 } | |
3642 | |
56 | 3643 return OK; |
3644 } | |
3645 | |
3646 /* | |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3647 * 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
|
3648 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3649 char_u * |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3650 partial_name(partial_T *pt) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3651 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3652 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3653 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
|
3654 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
|
3655 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
|
3656 return (char_u *)""; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3657 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3658 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3659 static void |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3660 partial_free(partial_T *pt) |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3661 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3662 int i; |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3663 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3664 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
|
3665 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
|
3666 vim_free(pt->pt_argv); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3667 dict_unref(pt->pt_dict); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3668 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3669 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3670 func_unref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3671 vim_free(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3672 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3673 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3674 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
|
3675 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3676 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
|
3677 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3678 // 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
|
3679 // 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
|
3680 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
|
3681 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3682 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
|
3683 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
|
3684 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3685 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
|
3686 clear_tv(stack + i); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3687 ga_clear(gap); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3688 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
|
3689 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3690 pt->pt_funcstack = NULL; |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3691 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3692 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3693 vim_free(pt); |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3694 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3695 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3696 /* |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3697 * 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
|
3698 * becomes zero. |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3699 */ |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3700 void |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3701 partial_unref(partial_T *pt) |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3702 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3703 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
|
3704 partial_free(pt); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3705 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3706 |
80 | 3707 /* |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3708 * Return the next (unique) copy ID. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3709 * Used for serializing nested structures. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3710 */ |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3711 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3712 get_copyID(void) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3713 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3714 current_copyID += COPYID_INC; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3715 return current_copyID; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3716 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3717 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3718 /* |
371 | 3719 * Garbage collection for lists and dictionaries. |
3720 * | |
3721 * We use reference counts to be able to free most items right away when they | |
3722 * are no longer used. But for composite items it's possible that it becomes | |
3723 * unused while the reference count is > 0: When there is a recursive | |
3724 * reference. Example: | |
3725 * :let l = [1, 2, 3] | |
3726 * :let d = {9: l} | |
3727 * :let l[1] = d | |
3728 * | |
3729 * Since this is quite unusual we handle this with garbage collection: every | |
3730 * once in a while find out which lists and dicts are not referenced from any | |
3731 * variable. | |
3732 * | |
3733 * Here is a good reference text about garbage collection (refers to Python | |
3734 * but it applies to all reference-counting mechanisms): | |
3735 * http://python.ca/nas/python/gc/ | |
3736 */ | |
3737 | |
3738 /* | |
3739 * 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
|
3740 * When "testing" is TRUE this is called from test_garbagecollect_now(). |
371 | 3741 * Return TRUE if some memory was freed. |
3742 */ | |
3743 int | |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3744 garbage_collect(int testing) |
371 | 3745 { |
1891 | 3746 int copyID; |
6565 | 3747 int abort = FALSE; |
371 | 3748 buf_T *buf; |
3749 win_T *wp; | |
6588 | 3750 int did_free = FALSE; |
819 | 3751 tabpage_T *tp; |
371 | 3752 |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3753 if (!testing) |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3754 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3755 // Only do this once. |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3756 want_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3757 may_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3758 garbage_collect_at_exit = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3759 } |
958 | 3760 |
19001
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3761 // 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
|
3762 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
|
3763 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3764 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
|
3765 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
|
3766 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
|
3767 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3768 // 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
|
3769 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
|
3770 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
|
3771 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
|
3772 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3773 // 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
|
3774 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
|
3775 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3776 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
|
3777 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
|
3778 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
|
3779 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
|
3780 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
|
3781 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
|
3782 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3783 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3784 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3785 // 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
|
3786 // previous_funccal. |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3787 copyID = get_copyID(); |
1891 | 3788 |
371 | 3789 /* |
3790 * 1. Go through all accessible variables and mark all lists and dicts | |
3791 * with copyID. | |
3792 */ | |
1891 | 3793 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3794 // 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
|
3795 // 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
|
3796 // 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
|
3797 abort = abort || set_ref_in_previous_funccal(copyID); |
1891 | 3798 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3799 // 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
|
3800 abort = abort || garbage_collect_scriptvars(copyID); |
371 | 3801 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3802 // buffer-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3803 FOR_ALL_BUFFERS(buf) |
6565 | 3804 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID, |
3805 NULL, NULL); | |
371 | 3806 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3807 // window-local variables |
819 | 3808 FOR_ALL_TAB_WINDOWS(tp, wp) |
6565 | 3809 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, |
3810 NULL, NULL); | |
4309 | 3811 if (aucmd_win != NULL) |
6565 | 3812 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID, |
3813 NULL, NULL); | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
3814 #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
|
3815 FOR_ALL_POPUPWINS(wp) |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3816 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
|
3817 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3818 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
|
3819 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
|
3820 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
|
3821 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3822 #endif |
371 | 3823 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3824 // tabpage-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3825 FOR_ALL_TABPAGES(tp) |
6565 | 3826 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, |
3827 NULL, NULL); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3828 // 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
|
3829 abort = abort || garbage_collect_globvars(copyID); |
371 | 3830 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3831 // function-local variables |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3832 abort = abort || set_ref_in_call_stack(copyID); |
371 | 3833 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3834 // named functions (matters for closures) |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
3835 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
|
3836 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3837 // 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
|
3838 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
|
3839 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3840 // 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
|
3841 abort = abort || garbage_collect_vimvars(copyID); |
1733 | 3842 |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3843 // callbacks in buffers |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3844 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
|
3845 |
3450 | 3846 #ifdef FEAT_LUA |
6565 | 3847 abort = abort || set_ref_in_lua(copyID); |
3450 | 3848 #endif |
3849 | |
3618 | 3850 #ifdef FEAT_PYTHON |
6565 | 3851 abort = abort || set_ref_in_python(copyID); |
3618 | 3852 #endif |
3853 | |
3854 #ifdef FEAT_PYTHON3 | |
6565 | 3855 abort = abort || set_ref_in_python3(copyID); |
3856 #endif | |
3857 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3858 #ifdef FEAT_JOB_CHANNEL |
8877
50e40f322e78
commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents:
8870
diff
changeset
|
3859 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
|
3860 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
|
3861 #endif |
9052
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
3862 #ifdef FEAT_NETBEANS_INTG |
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
3863 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
|
3864 #endif |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7895
diff
changeset
|
3865 |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3866 #ifdef FEAT_TIMERS |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3867 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
|
3868 #endif |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3869 |
11412
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3870 #ifdef FEAT_QUICKFIX |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3871 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
|
3872 #endif |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3873 |
11804
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3874 #ifdef FEAT_TERMINAL |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3875 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
|
3876 #endif |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3877 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
3878 #ifdef FEAT_PROP_POPUP |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3879 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
|
3880 #endif |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3881 |
6565 | 3882 if (!abort) |
3883 { | |
3884 /* | |
3885 * 2. Free lists and dictionaries that are not referenced. | |
3886 */ | |
3887 did_free = free_unref_items(copyID); | |
3888 | |
3889 /* | |
3890 * 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
|
3891 * This may call us back recursively. |
6565 | 3892 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3893 free_unref_funccal(copyID, testing); |
6565 | 3894 } |
3895 else if (p_verbose > 0) | |
3896 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3897 verb_msg(_("Not enough memory to set references, garbage collection aborted!")); |
6565 | 3898 } |
1891 | 3899 |
3900 return did_free; | |
3901 } | |
3902 | |
3903 /* | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3904 * Free lists, dictionaries, channels and jobs that are no longer referenced. |
1891 | 3905 */ |
3906 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3907 free_unref_items(int copyID) |
1891 | 3908 { |
3909 int did_free = FALSE; | |
3910 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3911 // 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
|
3912 // 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
|
3913 // do that here. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3914 in_free_unref_items = TRUE; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3915 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3916 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3917 * 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
|
3918 * 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
|
3919 */ |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3920 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3921 // 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
|
3922 did_free |= dict_free_nonref(copyID); |
371 | 3923 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3924 // 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
|
3925 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
|
3926 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3927 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3928 // 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
|
3929 // 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
|
3930 // 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
|
3931 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
|
3932 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3933 // 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
|
3934 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
|
3935 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3936 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3937 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3938 * PASS 2: free the items themselves. |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3939 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
3940 dict_free_items(copyID); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
9556
diff
changeset
|
3941 list_free_items(copyID); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3942 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3943 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3944 // 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
|
3945 // 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
|
3946 // 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
|
3947 free_unused_jobs(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3948 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3949 // 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
|
3950 free_unused_channels(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3951 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3952 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3953 in_free_unref_items = FALSE; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3954 |
371 | 3955 return did_free; |
3956 } | |
3957 | |
3958 /* | |
3959 * Mark all lists and dicts referenced through hashtab "ht" with "copyID". | |
6565 | 3960 * "list_stack" is used to add lists to be marked. Can be NULL. |
3961 * | |
3962 * Returns TRUE if setting references failed somehow. | |
3963 */ | |
3964 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3965 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack) |
364 | 3966 { |
3967 int todo; | |
6565 | 3968 int abort = FALSE; |
364 | 3969 hashitem_T *hi; |
6565 | 3970 hashtab_T *cur_ht; |
3971 ht_stack_T *ht_stack = NULL; | |
3972 ht_stack_T *tempitem; | |
3973 | |
3974 cur_ht = ht; | |
3975 for (;;) | |
3976 { | |
3977 if (!abort) | |
3978 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3979 // 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
|
3980 // 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
|
3981 // list_stack. |
6565 | 3982 todo = (int)cur_ht->ht_used; |
3983 for (hi = cur_ht->ht_array; todo > 0; ++hi) | |
3984 if (!HASHITEM_EMPTY(hi)) | |
3985 { | |
3986 --todo; | |
3987 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID, | |
3988 &ht_stack, list_stack); | |
3989 } | |
3990 } | |
3991 | |
3992 if (ht_stack == NULL) | |
3993 break; | |
3994 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3995 // take an item from the stack |
6565 | 3996 cur_ht = ht_stack->ht; |
3997 tempitem = ht_stack; | |
3998 ht_stack = ht_stack->prev; | |
3999 free(tempitem); | |
4000 } | |
4001 | |
4002 return abort; | |
371 | 4003 } |
4004 | |
4005 /* | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4006 * 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
|
4007 * 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
|
4008 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4009 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4010 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
|
4011 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4012 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
|
4013 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4014 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
|
4015 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
|
4016 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4017 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
|
4018 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4019 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4020 /* |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4021 * 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
|
4022 * 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
|
4023 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4024 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4025 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
|
4026 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4027 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
|
4028 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4029 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
|
4030 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
|
4031 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4032 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
|
4033 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4034 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4035 /* |
371 | 4036 * Mark all lists and dicts referenced through list "l" with "copyID". |
6565 | 4037 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. |
4038 * | |
4039 * Returns TRUE if setting references failed somehow. | |
4040 */ | |
4041 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
|
4042 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack) |
6565 | 4043 { |
4044 listitem_T *li; | |
4045 int abort = FALSE; | |
4046 list_T *cur_l; | |
4047 list_stack_T *list_stack = NULL; | |
4048 list_stack_T *tempitem; | |
4049 | |
4050 cur_l = l; | |
4051 for (;;) | |
4052 { | |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
4053 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
|
4054 // 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
|
4055 // 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
|
4056 // list_stack. |
6565 | 4057 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next) |
4058 abort = abort || set_ref_in_item(&li->li_tv, copyID, | |
4059 ht_stack, &list_stack); | |
4060 if (list_stack == NULL) | |
4061 break; | |
4062 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4063 // take an item from the stack |
6565 | 4064 cur_l = list_stack->list; |
4065 tempitem = list_stack; | |
4066 list_stack = list_stack->prev; | |
4067 free(tempitem); | |
4068 } | |
4069 | |
4070 return abort; | |
371 | 4071 } |
4072 | |
4073 /* | |
4074 * Mark all lists and dicts referenced through typval "tv" with "copyID". | |
6565 | 4075 * "list_stack" is used to add lists to be marked. Can be NULL. |
4076 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. | |
4077 * | |
4078 * Returns TRUE if setting references failed somehow. | |
4079 */ | |
4080 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4081 set_ref_in_item( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4082 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4083 int copyID, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4084 ht_stack_T **ht_stack, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4085 list_stack_T **list_stack) |
364 | 4086 { |
6565 | 4087 int abort = FALSE; |
364 | 4088 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4089 if (tv->v_type == VAR_DICT) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4090 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4091 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
|
4092 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4093 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
|
4094 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4095 // 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
|
4096 dd->dv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4097 if (ht_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4098 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4099 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
|
4100 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4101 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4102 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4103 ht_stack_T *newitem = (ht_stack_T*)malloc(sizeof(ht_stack_T)); |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4104 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4105 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4106 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4107 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4108 newitem->ht = &dd->dv_hashtab; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4109 newitem->prev = *ht_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4110 *ht_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4111 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4112 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4113 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4114 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4115 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
|
4116 { |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4117 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
|
4118 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4119 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
|
4120 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4121 // 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
|
4122 ll->lv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4123 if (list_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4124 { |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4125 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
|
4126 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4127 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4128 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4129 list_stack_T *newitem = (list_stack_T*)malloc( |
6565 | 4130 sizeof(list_stack_T)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4131 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4132 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4133 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4134 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4135 newitem->list = ll; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4136 newitem->prev = *list_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4137 *list_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4138 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4139 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4140 } |
6565 | 4141 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4142 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
|
4143 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4144 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
|
4145 } |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4146 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
|
4147 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4148 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
|
4149 int i; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4150 |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4151 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
|
4152 { |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4153 // 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
|
4154 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
|
4155 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4156 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
|
4157 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4158 if (pt->pt_dict != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4159 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4160 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4161 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4162 dtv.v_type = VAR_DICT; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4163 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
|
4164 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
|
4165 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4166 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4167 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
|
4168 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
|
4169 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
|
4170 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
|
4171 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4172 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
|
4173 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4174 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
|
4175 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
|
4176 ht_stack, list_stack); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4177 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4178 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4179 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4180 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4181 #ifdef FEAT_JOB_CHANNEL |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4182 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
|
4183 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4184 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
|
4185 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4186 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4187 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
|
4188 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4189 job->jv_copyID = copyID; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4190 if (job->jv_channel != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4191 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4192 dtv.v_type = VAR_CHANNEL; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4193 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
|
4194 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
|
4195 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4196 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
|
4197 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4198 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
|
4199 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
|
4200 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
|
4201 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4202 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4203 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4204 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
|
4205 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4206 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
|
4207 ch_part_T part; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4208 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4209 jsonq_T *jq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4210 cbq_T *cq; |
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 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
|
4213 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4214 ch->ch_copyID = copyID; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10235
diff
changeset
|
4215 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
|
4216 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4217 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
|
4218 jq = jq->jq_next) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4219 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
|
4220 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
|
4221 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
|
4222 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
|
4223 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4224 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
|
4225 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
|
4226 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
|
4227 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4228 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
|
4229 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4230 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
|
4231 dtv.vval.v_partial = |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4232 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
|
4233 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
|
4234 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4235 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4236 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
|
4237 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4238 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
|
4239 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
|
4240 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
|
4241 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4242 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
|
4243 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4244 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
|
4245 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
|
4246 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
|
4247 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4248 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4249 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4250 #endif |
6565 | 4251 return abort; |
364 | 4252 } |
4253 | |
100 | 4254 /* |
56 | 4255 * Return a string with the string representation of a variable. |
4256 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
80 | 4257 * "numbuf" is used for a number. |
634 | 4258 * 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
|
4259 * 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
|
4260 * 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
|
4261 * ":echo" displays values. |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4262 * 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
|
4263 * are replaced with "...". |
1360 | 4264 * May return NULL. |
56 | 4265 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4266 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4267 echo_string_core( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4268 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4269 char_u **tofree, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4270 char_u *numbuf, |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4271 int copyID, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4272 int echo_style, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4273 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
|
4274 int composite_val) |
56 | 4275 { |
104 | 4276 static int recurse = 0; |
4277 char_u *r = NULL; | |
4278 | |
137 | 4279 if (recurse >= DICT_MAXNEST) |
104 | 4280 { |
5973 | 4281 if (!did_echo_string_emsg) |
4282 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4283 // 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
|
4284 // 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
|
4285 // and dicts. |
5973 | 4286 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
|
4287 emsg(_("E724: variable nested too deep for displaying")); |
5973 | 4288 } |
104 | 4289 *tofree = NULL; |
5973 | 4290 return (char_u *)"{E724}"; |
104 | 4291 } |
4292 ++recurse; | |
4293 | |
56 | 4294 switch (tv->v_type) |
4295 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4296 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
|
4297 if (echo_style && !composite_val) |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4298 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4299 *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
|
4300 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
|
4301 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
|
4302 r = (char_u *)""; |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4303 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4304 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4305 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4306 *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
|
4307 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4308 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4309 break; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4310 |
56 | 4311 case VAR_FUNC: |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4312 if (echo_style) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4313 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4314 *tofree = NULL; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4315 r = tv->vval.v_string; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4316 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4317 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4318 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4319 *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
|
4320 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4321 } |
104 | 4322 break; |
634 | 4323 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4324 case VAR_PARTIAL: |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4325 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4326 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
|
4327 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
|
4328 : partial_name(pt), FALSE); |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4329 garray_T ga; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4330 int i; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4331 char_u *tf; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4332 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4333 ga_init2(&ga, 1, 100); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4334 ga_concat(&ga, (char_u *)"function("); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4335 if (fname != NULL) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4336 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4337 ga_concat(&ga, fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4338 vim_free(fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4339 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4340 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
|
4341 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4342 ga_concat(&ga, (char_u *)", ["); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4343 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
|
4344 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4345 if (i > 0) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4346 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4347 ga_concat(&ga, |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4348 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
|
4349 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4350 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4351 ga_concat(&ga, (char_u *)"]"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4352 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4353 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
|
4354 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4355 typval_T dtv; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4356 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4357 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4358 dtv.v_type = VAR_DICT; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4359 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
|
4360 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
|
4361 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4362 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4363 ga_concat(&ga, (char_u *)")"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4364 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4365 *tofree = ga.ga_data; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4366 r = *tofree; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4367 break; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4368 } |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4369 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4370 case VAR_BLOB: |
15466
435fcefd2c8e
patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15464
diff
changeset
|
4371 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
|
4372 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4373 |
56 | 4374 case VAR_LIST: |
634 | 4375 if (tv->vval.v_list == NULL) |
4376 { | |
20126
831b1ea43020
patch 8.2.0618: echoing a null list results in no output
Bram Moolenaar <Bram@vim.org>
parents:
20111
diff
changeset
|
4377 // NULL list is equivalent to empty list. |
634 | 4378 *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
|
4379 r = (char_u *)"[]"; |
634 | 4380 } |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4381 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
|
4382 && tv->vval.v_list->lv_len > 0) |
634 | 4383 { |
4384 *tofree = NULL; | |
4385 r = (char_u *)"[...]"; | |
4386 } | |
4387 else | |
4388 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4389 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
|
4390 |
634 | 4391 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
|
4392 *tofree = list2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4393 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4394 tv->vval.v_list->lv_copyID = old_copyID; |
634 | 4395 r = *tofree; |
4396 } | |
4397 break; | |
4398 | |
100 | 4399 case VAR_DICT: |
634 | 4400 if (tv->vval.v_dict == NULL) |
4401 { | |
20128
0b35a7ffceb2
patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents:
20126
diff
changeset
|
4402 // NULL dict is equivalent to empty dict. |
634 | 4403 *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
|
4404 r = (char_u *)"{}"; |
634 | 4405 } |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4406 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
|
4407 && tv->vval.v_dict->dv_hashtab.ht_used != 0) |
634 | 4408 { |
4409 *tofree = NULL; | |
4410 r = (char_u *)"{...}"; | |
4411 } | |
4412 else | |
4413 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4414 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
|
4415 |
634 | 4416 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
|
4417 *tofree = dict2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4418 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4419 tv->vval.v_dict->dv_copyID = old_copyID; |
634 | 4420 r = *tofree; |
4421 } | |
4422 break; | |
4423 | |
71 | 4424 case VAR_NUMBER: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4425 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
|
4426 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
|
4427 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
|
4428 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4429 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
|
4430 break; |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4431 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4432 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
4433 case VAR_CHANNEL: |
104 | 4434 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4435 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
|
4436 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
|
4437 { |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4438 *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
|
4439 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
|
4440 } |
71 | 4441 break; |
634 | 4442 |
1624 | 4443 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4444 #ifdef FEAT_FLOAT |
1624 | 4445 *tofree = NULL; |
4446 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float); | |
4447 r = numbuf; | |
4448 break; | |
4449 #endif | |
4450 | |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
4451 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4452 case VAR_SPECIAL: |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4453 *tofree = NULL; |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
4454 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
|
4455 break; |
104 | 4456 } |
4457 | |
5973 | 4458 if (--recurse == 0) |
4459 did_echo_string_emsg = FALSE; | |
104 | 4460 return r; |
97 | 4461 } |
4462 | |
4463 /* | |
4464 * Return a string with the string representation of a variable. | |
4465 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
4466 * "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
|
4467 * 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
|
4468 * 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
|
4469 * May return NULL. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4470 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4471 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4472 echo_string( |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4473 typval_T *tv, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4474 char_u **tofree, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4475 char_u *numbuf, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4476 int copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4477 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4478 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
|
4479 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4480 |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4481 /* |
137 | 4482 * Return string "str" in ' quotes, doubling ' characters. |
4483 * If "str" is NULL an empty string is assumed. | |
100 | 4484 * If "function" is TRUE make it function('string'). |
97 | 4485 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4486 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4487 string_quote(char_u *str, int function) |
97 | 4488 { |
137 | 4489 unsigned len; |
97 | 4490 char_u *p, *r, *s; |
4491 | |
137 | 4492 len = (function ? 13 : 3); |
4493 if (str != NULL) | |
4494 { | |
835 | 4495 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
|
4496 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
137 | 4497 if (*p == '\'') |
4498 ++len; | |
4499 } | |
97 | 4500 s = r = alloc(len); |
4501 if (r != NULL) | |
4502 { | |
4503 if (function) | |
4504 { | |
100 | 4505 STRCPY(r, "function('"); |
97 | 4506 r += 10; |
4507 } | |
4508 else | |
100 | 4509 *r++ = '\''; |
137 | 4510 if (str != NULL) |
4511 for (p = str; *p != NUL; ) | |
4512 { | |
4513 if (*p == '\'') | |
4514 *r++ = '\''; | |
4515 MB_COPY_CHAR(p, r); | |
4516 } | |
100 | 4517 *r++ = '\''; |
97 | 4518 if (function) |
4519 *r++ = ')'; | |
4520 *r++ = NUL; | |
4521 } | |
4522 return s; | |
4523 } | |
4524 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4525 #if defined(FEAT_FLOAT) || defined(PROTO) |
1624 | 4526 /* |
4527 * Convert the string "text" to a floating point number. | |
4528 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure | |
4529 * this always uses a decimal point. | |
4530 * Returns the length of the text that was consumed. | |
4531 */ | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4532 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4533 string2float( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4534 char_u *text, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4535 float_T *value) // result stored here |
1624 | 4536 { |
4537 char *s = (char *)text; | |
4538 float_T f; | |
4539 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4540 // 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
|
4541 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
|
4542 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4543 *value = INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4544 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4545 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4546 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
|
4547 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4548 *value = -INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4549 return 4; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4550 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4551 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
|
4552 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4553 *value = NAN; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4554 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4555 } |
1624 | 4556 f = strtod(s, &s); |
4557 *value = f; | |
4558 return (int)((char_u *)s - text); | |
4559 } | |
4560 #endif | |
4561 | |
97 | 4562 /* |
7 | 4563 * Translate a String variable into a position. |
685 | 4564 * Returns NULL when there is an error. |
7 | 4565 */ |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4566 pos_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4567 var2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4568 typval_T *varp, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4569 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
|
4570 int *fnum) // set to fnum for '0, 'A, etc. |
7 | 4571 { |
700 | 4572 char_u *name; |
7 | 4573 static pos_T pos; |
700 | 4574 pos_T *pp; |
7 | 4575 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4576 // Argument can be [lnum, col, coladd]. |
685 | 4577 if (varp->v_type == VAR_LIST) |
4578 { | |
4579 list_T *l; | |
4580 int len; | |
705 | 4581 int error = FALSE; |
1317 | 4582 listitem_T *li; |
685 | 4583 |
4584 l = varp->vval.v_list; | |
4585 if (l == NULL) | |
4586 return NULL; | |
4587 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4588 // Get the line number |
705 | 4589 pos.lnum = list_find_nr(l, 0L, &error); |
4590 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
|
4591 return NULL; // invalid line number |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4592 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4593 // Get the column number |
705 | 4594 pos.col = list_find_nr(l, 1L, &error); |
4595 if (error) | |
685 | 4596 return NULL; |
4597 len = (long)STRLEN(ml_get(pos.lnum)); | |
1317 | 4598 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4599 // We accept "$" for the column number: last column. |
1317 | 4600 li = list_find(l, 1L); |
4601 if (li != NULL && li->li_tv.v_type == VAR_STRING | |
4602 && li->li_tv.vval.v_string != NULL | |
4603 && STRCMP(li->li_tv.vval.v_string, "$") == 0) | |
4604 pos.col = len + 1; | |
4605 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4606 // Accept a position up to the NUL after the line. |
826 | 4607 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
|
4608 return NULL; // invalid column number |
705 | 4609 --pos.col; |
4610 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4611 // Get the virtual offset. Defaults to zero. |
705 | 4612 pos.coladd = list_find_nr(l, 2L, &error); |
4613 if (error) | |
4614 pos.coladd = 0; | |
4615 | |
685 | 4616 return &pos; |
4617 } | |
4618 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4619 name = tv_get_string_chk(varp); |
323 | 4620 if (name == NULL) |
4621 return NULL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4622 if (name[0] == '.') // cursor |
7 | 4623 return &curwin->w_cursor; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4624 if (name[0] == 'v' && name[1] == NUL) // Visual start |
1609 | 4625 { |
4626 if (VIsual_active) | |
4627 return &VIsual; | |
4628 return &curwin->w_cursor; | |
4629 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4630 if (name[0] == '\'') // mark |
7 | 4631 { |
4043 | 4632 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); |
7 | 4633 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) |
4634 return NULL; | |
4635 return pp; | |
4636 } | |
705 | 4637 |
4638 pos.coladd = 0; | |
4639 | |
1317 | 4640 if (name[0] == 'w' && dollar_lnum) |
666 | 4641 { |
4642 pos.col = 0; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4643 if (name[1] == '0') // "w0": first visible line |
666 | 4644 { |
671 | 4645 update_topline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4646 // 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
|
4647 // 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
|
4648 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; |
666 | 4649 return &pos; |
4650 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4651 else if (name[1] == '$') // "w$": last visible line |
666 | 4652 { |
671 | 4653 validate_botline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4654 // 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
|
4655 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; |
666 | 4656 return &pos; |
4657 } | |
4658 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4659 else if (name[0] == '$') // last column or line |
7 | 4660 { |
1317 | 4661 if (dollar_lnum) |
7 | 4662 { |
4663 pos.lnum = curbuf->b_ml.ml_line_count; | |
4664 pos.col = 0; | |
4665 } | |
4666 else | |
4667 { | |
4668 pos.lnum = curwin->w_cursor.lnum; | |
4669 pos.col = (colnr_T)STRLEN(ml_get_curline()); | |
4670 } | |
4671 return &pos; | |
4672 } | |
4673 return NULL; | |
4674 } | |
4675 | |
4676 /* | |
709 | 4677 * Convert list in "arg" into a position and optional file number. |
4678 * When "fnump" is NULL there is no file number, only 3 items. | |
4679 * Note that the column is passed on as-is, the caller may want to decrement | |
4680 * it to use 1 for the first column. | |
4681 * Return FAIL when conversion is not possible, doesn't check the position for | |
4682 * validity. | |
4683 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4684 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4685 list2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4686 typval_T *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4687 pos_T *posp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4688 int *fnump, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4689 colnr_T *curswantp) |
709 | 4690 { |
4691 list_T *l = arg->vval.v_list; | |
4692 long i = 0; | |
4693 long n; | |
4694 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4695 // 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
|
4696 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional. |
915 | 4697 if (arg->v_type != VAR_LIST |
4698 || l == NULL | |
4699 || l->lv_len < (fnump == NULL ? 2 : 3) | |
5938 | 4700 || l->lv_len > (fnump == NULL ? 4 : 5)) |
709 | 4701 return FAIL; |
4702 | |
4703 if (fnump != NULL) | |
4704 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4705 n = list_find_nr(l, i++, NULL); // fnum |
709 | 4706 if (n < 0) |
4707 return FAIL; | |
4708 if (n == 0) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4709 n = curbuf->b_fnum; // current buffer |
709 | 4710 *fnump = n; |
4711 } | |
4712 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4713 n = list_find_nr(l, i++, NULL); // lnum |
709 | 4714 if (n < 0) |
4715 return FAIL; | |
4716 posp->lnum = n; | |
4717 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4718 n = list_find_nr(l, i++, NULL); // col |
709 | 4719 if (n < 0) |
4720 return FAIL; | |
4721 posp->col = n; | |
4722 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4723 n = list_find_nr(l, i, NULL); // off |
709 | 4724 if (n < 0) |
915 | 4725 posp->coladd = 0; |
4726 else | |
4727 posp->coladd = n; | |
709 | 4728 |
5938 | 4729 if (curswantp != NULL) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4730 *curswantp = list_find_nr(l, i + 1, NULL); // curswant |
5938 | 4731 |
709 | 4732 return OK; |
4733 } | |
4734 | |
4735 /* | |
7 | 4736 * Get the length of an environment variable name. |
4737 * Advance "arg" to the first character after the name. | |
4738 * Return 0 for error. | |
4739 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
4740 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4741 get_env_len(char_u **arg) |
7 | 4742 { |
4743 char_u *p; | |
4744 int len; | |
4745 | |
4746 for (p = *arg; vim_isIDc(*p); ++p) | |
4747 ; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4748 if (p == *arg) // no name found |
7 | 4749 return 0; |
4750 | |
4751 len = (int)(p - *arg); | |
4752 *arg = p; | |
4753 return len; | |
4754 } | |
4755 | |
4756 /* | |
4757 * Get the length of the name of a function or internal variable. | |
4758 * "arg" is advanced to the first non-white character after the name. | |
4759 * Return 0 if something is wrong. | |
4760 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4761 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4762 get_id_len(char_u **arg) |
7 | 4763 { |
4764 char_u *p; | |
4765 int len; | |
4766 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4767 // Find the end of the name. |
7 | 4768 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
|
4769 { |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4770 if (*p == ':') |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4771 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4772 // "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
|
4773 // 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
|
4774 len = (int)(p - *arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4775 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
|
4776 || len > 1) |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4777 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4778 } |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4779 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4780 if (p == *arg) // no name found |
7 | 4781 return 0; |
4782 | |
4783 len = (int)(p - *arg); | |
4784 *arg = skipwhite(p); | |
4785 | |
4786 return len; | |
4787 } | |
4788 | |
4789 /* | |
124 | 4790 * Get the length of the name of a variable or function. |
4791 * Only the name is recognized, does not handle ".key" or "[idx]". | |
7 | 4792 * "arg" is advanced to the first non-white character after the name. |
159 | 4793 * Return -1 if curly braces expansion failed. |
4794 * Return 0 if something else is wrong. | |
7 | 4795 * If the name contains 'magic' {}'s, expand them and return the |
4796 * expanded name in an allocated string via 'alias' - caller must free. | |
4797 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
4798 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4799 get_name_len( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4800 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4801 char_u **alias, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4802 int evaluate, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4803 int verbose) |
7 | 4804 { |
4805 int len; | |
4806 char_u *p; | |
4807 char_u *expr_start; | |
4808 char_u *expr_end; | |
4809 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4810 *alias = NULL; // default to no alias |
7 | 4811 |
4812 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA | |
4813 && (*arg)[2] == (int)KE_SNR) | |
4814 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4815 // hard coded <SNR>, already translated |
7 | 4816 *arg += 3; |
4817 return get_id_len(arg) + 3; | |
4818 } | |
4819 len = eval_fname_script(*arg); | |
4820 if (len > 0) | |
4821 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4822 // literal "<SID>", "s:" or "<SNR>" |
7 | 4823 *arg += len; |
4824 } | |
4825 | |
4826 /* | |
71 | 4827 * Find the end of the name; check for {} construction. |
7 | 4828 */ |
271 | 4829 p = find_name_end(*arg, &expr_start, &expr_end, |
4830 len > 0 ? 0 : FNE_CHECK_START); | |
7 | 4831 if (expr_start != NULL) |
4832 { | |
4833 char_u *temp_string; | |
4834 | |
4835 if (!evaluate) | |
4836 { | |
4837 len += (int)(p - *arg); | |
4838 *arg = skipwhite(p); | |
4839 return len; | |
4840 } | |
4841 | |
4842 /* | |
4843 * Include any <SID> etc in the expanded string: | |
4844 * Thus the -len here. | |
4845 */ | |
4846 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p); | |
4847 if (temp_string == NULL) | |
159 | 4848 return -1; |
7 | 4849 *alias = temp_string; |
4850 *arg = skipwhite(p); | |
4851 return (int)STRLEN(temp_string); | |
4852 } | |
4853 | |
4854 len += get_id_len(arg); | |
15464
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
4855 // 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
|
4856 // reported at a higher level. |
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
4857 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
|
4858 semsg(_(e_invexpr2), *arg); |
7 | 4859 |
4860 return len; | |
4861 } | |
4862 | |
71 | 4863 /* |
4864 * Find the end of a variable or function name, taking care of magic braces. | |
4865 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the | |
4866 * start and end of the first magic braces item. | |
271 | 4867 * "flags" can have FNE_INCL_BR and FNE_CHECK_START. |
71 | 4868 * Return a pointer to just after the name. Equal to "arg" if there is no |
4869 * valid name. | |
4870 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4871 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4872 find_name_end( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4873 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4874 char_u **expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4875 char_u **expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4876 int flags) |
71 | 4877 { |
4878 int mb_nest = 0; | |
4879 int br_nest = 0; | |
7 | 4880 char_u *p; |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4881 int len; |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
4882 int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; |
7 | 4883 |
71 | 4884 if (expr_start != NULL) |
4885 { | |
4886 *expr_start = NULL; | |
4887 *expr_end = NULL; | |
4888 } | |
4889 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4890 // 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
|
4891 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
|
4892 && (*arg != '{' || vim9script)) |
271 | 4893 return arg; |
4894 | |
71 | 4895 for (p = arg; *p != NUL |
4896 && (eval_isnamec(*p) | |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
4897 || (*p == '{' && !vim9script) |
271 | 4898 || ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.')) |
71 | 4899 || mb_nest != 0 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
4900 || br_nest != 0); MB_PTR_ADV(p)) |
468 | 4901 { |
4902 if (*p == '\'') | |
4903 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4904 // 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
|
4905 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) |
468 | 4906 ; |
4907 if (*p == NUL) | |
4908 break; | |
4909 } | |
4910 else if (*p == '"') | |
4911 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4912 // 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
|
4913 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
468 | 4914 if (*p == '\\' && p[1] != NUL) |
4915 ++p; | |
4916 if (*p == NUL) | |
4917 break; | |
4918 } | |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4919 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
|
4920 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4921 // "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
|
4922 // 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
|
4923 len = (int)(p - arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4924 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
|
4925 || (len > 1 && p[-1] != '}')) |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4926 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4927 } |
468 | 4928 |
71 | 4929 if (mb_nest == 0) |
4930 { | |
4931 if (*p == '[') | |
4932 ++br_nest; | |
4933 else if (*p == ']') | |
4934 --br_nest; | |
4935 } | |
468 | 4936 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
4937 if (br_nest == 0 && !vim9script) |
71 | 4938 { |
4939 if (*p == '{') | |
4940 { | |
4941 mb_nest++; | |
4942 if (expr_start != NULL && *expr_start == NULL) | |
4943 *expr_start = p; | |
4944 } | |
4945 else if (*p == '}') | |
4946 { | |
4947 mb_nest--; | |
4948 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) | |
4949 *expr_end = p; | |
4950 } | |
4951 } | |
7 | 4952 } |
4953 | |
4954 return p; | |
4955 } | |
4956 | |
4957 /* | |
159 | 4958 * Expands out the 'magic' {}'s in a variable/function name. |
4959 * Note that this can call itself recursively, to deal with | |
4960 * constructs like foo{bar}{baz}{bam} | |
4961 * The four pointer arguments point to "foo{expre}ss{ion}bar" | |
4962 * "in_start" ^ | |
4963 * "expr_start" ^ | |
4964 * "expr_end" ^ | |
4965 * "in_end" ^ | |
4966 * | |
4967 * Returns a new allocated string, which the caller must free. | |
4968 * Returns NULL for failure. | |
4969 */ | |
4970 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4971 make_expanded_name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4972 char_u *in_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4973 char_u *expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4974 char_u *expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4975 char_u *in_end) |
159 | 4976 { |
4977 char_u c1; | |
4978 char_u *retval = NULL; | |
4979 char_u *temp_result; | |
4980 | |
4981 if (expr_end == NULL || in_end == NULL) | |
4982 return NULL; | |
4983 *expr_start = NUL; | |
4984 *expr_end = NUL; | |
4985 c1 = *in_end; | |
4986 *in_end = NUL; | |
4987 | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
4988 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
|
4989 if (temp_result != NULL) |
159 | 4990 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
4991 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
|
4992 + (in_end - expr_end) + 1); |
159 | 4993 if (retval != NULL) |
4994 { | |
4995 STRCPY(retval, in_start); | |
4996 STRCAT(retval, temp_result); | |
4997 STRCAT(retval, expr_end + 1); | |
4998 } | |
4999 } | |
5000 vim_free(temp_result); | |
5001 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5002 *in_end = c1; // put char back for error messages |
159 | 5003 *expr_start = '{'; |
5004 *expr_end = '}'; | |
5005 | |
5006 if (retval != NULL) | |
5007 { | |
271 | 5008 temp_result = find_name_end(retval, &expr_start, &expr_end, 0); |
159 | 5009 if (expr_start != NULL) |
5010 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5011 // Further expansion! |
159 | 5012 temp_result = make_expanded_name(retval, expr_start, |
5013 expr_end, temp_result); | |
5014 vim_free(retval); | |
5015 retval = temp_result; | |
5016 } | |
5017 } | |
5018 | |
5019 return retval; | |
5020 } | |
5021 | |
5022 /* | |
7 | 5023 * Return TRUE if character "c" can be used in a variable or function name. |
104 | 5024 * Does not include '{' or '}' for magic braces. |
7 | 5025 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5026 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5027 eval_isnamec(int c) |
7 | 5028 { |
271 | 5029 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); |
5030 } | |
5031 | |
5032 /* | |
5033 * Return TRUE if character "c" can be used as the first character in a | |
5034 * variable or function name (excluding '{' and '}'). | |
5035 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5036 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5037 eval_isnamec1(int c) |
271 | 5038 { |
5039 return (ASCII_ISALPHA(c) || c == '_'); | |
7 | 5040 } |
5041 | |
5042 /* | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5043 * Handle: |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5044 * - 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
|
5045 * - ".name" lookup |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5046 * - 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
|
5047 * - method call: var->method() |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5048 * |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5049 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len() |
159 | 5050 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5051 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5052 handle_subscript( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5053 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5054 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
|
5055 evalarg_T *evalarg, |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
5056 int verbose) // give error messages |
159 | 5057 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
5058 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
|
5059 && (evalarg->eval_flags & EVAL_EVALUATE); |
159 | 5060 int ret = OK; |
5061 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
|
5062 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
|
5063 int getnext; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5064 char_u *p; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5065 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5066 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
|
5067 { |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5068 // 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
|
5069 // 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
|
5070 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
|
5071 if (getnext |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5072 && ((rettv->v_type == VAR_DICT && *p == '.' |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5073 && ASCII_ISALPHA(p[1])) |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5074 || (*p == '-' && p[1] == '>' |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5075 && (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
|
5076 { |
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
5077 *arg = eval_next_line(evalarg); |
165cea61e974
patch 8.2.1122: Vim9: line continuation in dict member not recognized
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
5078 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
|
5079 } |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5080 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5081 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
|
5082 || 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
|
5083 && (!check_white || !VIM_ISWHITE(*(*arg - 1)))) |
159 | 5084 { |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21104
diff
changeset
|
5085 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
|
5086 selfdict, NULL); |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5087 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5088 // 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
|
5089 // 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
|
5090 // but not caught. |
159 | 5091 if (aborting()) |
5092 { | |
5093 if (ret == OK) | |
5094 clear_tv(rettv); | |
5095 ret = FAIL; | |
5096 } | |
5097 dict_unref(selfdict); | |
5098 selfdict = NULL; | |
5099 } | |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5100 else if (**arg == '-' && (*arg)[1] == '>') |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5101 { |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5102 if (ret == OK) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5103 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5104 if ((*arg)[2] == '{') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5105 // 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
|
5106 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
|
5107 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5108 // 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
|
5109 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
|
5110 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5111 } |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5112 // "." 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
|
5113 // 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
|
5114 else if (**arg == '[' |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5115 || (**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
|
5116 || (!evaluate |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5117 && (*arg)[1] != '.' |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5118 && current_sctx.sc_version >= 2)))) |
159 | 5119 { |
5120 dict_unref(selfdict); | |
5121 if (rettv->v_type == VAR_DICT) | |
5122 { | |
5123 selfdict = rettv->vval.v_dict; | |
5124 if (selfdict != NULL) | |
5125 ++selfdict->dv_refcount; | |
5126 } | |
5127 else | |
5128 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
|
5129 if (eval_index(arg, rettv, evalarg, verbose) == FAIL) |
159 | 5130 { |
5131 clear_tv(rettv); | |
5132 ret = FAIL; | |
5133 } | |
5134 } | |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5135 else |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
5136 break; |
159 | 5137 } |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5138 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5139 // 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
|
5140 // 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
|
5141 // explicitly (pt_auto is FALSE). |
9104
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5142 if (selfdict != NULL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5143 && (rettv->v_type == VAR_FUNC |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5144 || (rettv->v_type == VAR_PARTIAL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5145 && (rettv->vval.v_partial->pt_auto |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5146 || 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
|
5147 selfdict = make_partial(selfdict, rettv); |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5148 |
159 | 5149 dict_unref(selfdict); |
5150 return ret; | |
5151 } | |
5152 | |
5153 /* | |
104 | 5154 * Make a copy of an item. |
5155 * Lists and Dictionaries are also copied. A deep copy if "deep" is set. | |
165 | 5156 * For deepcopy() "copyID" is zero for a full copy or the ID for when a |
5157 * reference to an already copied list/dict can be used. | |
5158 * Returns FAIL or OK. | |
5159 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
5160 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5161 item_copy( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5162 typval_T *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5163 typval_T *to, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5164 int deep, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5165 int copyID) |
104 | 5166 { |
5167 static int recurse = 0; | |
165 | 5168 int ret = OK; |
104 | 5169 |
137 | 5170 if (recurse >= DICT_MAXNEST) |
104 | 5171 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5172 emsg(_("E698: variable nested too deep for making a copy")); |
165 | 5173 return FAIL; |
104 | 5174 } |
5175 ++recurse; | |
5176 | |
5177 switch (from->v_type) | |
5178 { | |
5179 case VAR_NUMBER: | |
1624 | 5180 case VAR_FLOAT: |
104 | 5181 case VAR_STRING: |
5182 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5183 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
|
5184 case VAR_BOOL: |
7862
d4fec9208e7e
commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5185 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5186 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5187 case VAR_CHANNEL: |
104 | 5188 copy_tv(from, to); |
5189 break; | |
5190 case VAR_LIST: | |
5191 to->v_type = VAR_LIST; | |
151 | 5192 to->v_lock = 0; |
165 | 5193 if (from->vval.v_list == NULL) |
5194 to->vval.v_list = NULL; | |
5195 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID) | |
5196 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5197 // use the copy made earlier |
165 | 5198 to->vval.v_list = from->vval.v_list->lv_copylist; |
5199 ++to->vval.v_list->lv_refcount; | |
5200 } | |
5201 else | |
5202 to->vval.v_list = list_copy(from->vval.v_list, deep, copyID); | |
5203 if (to->vval.v_list == NULL) | |
5204 ret = FAIL; | |
104 | 5205 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
|
5206 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
|
5207 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
|
5208 break; |
104 | 5209 case VAR_DICT: |
5210 to->v_type = VAR_DICT; | |
151 | 5211 to->v_lock = 0; |
165 | 5212 if (from->vval.v_dict == NULL) |
5213 to->vval.v_dict = NULL; | |
5214 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID) | |
5215 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5216 // use the copy made earlier |
165 | 5217 to->vval.v_dict = from->vval.v_dict->dv_copydict; |
5218 ++to->vval.v_dict->dv_refcount; | |
5219 } | |
5220 else | |
5221 to->vval.v_dict = dict_copy(from->vval.v_dict, deep, copyID); | |
5222 if (to->vval.v_dict == NULL) | |
5223 ret = FAIL; | |
104 | 5224 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5225 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
|
5226 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
|
5227 case VAR_VOID: |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
5228 internal_error_no_abort("item_copy(UNKNOWN)"); |
165 | 5229 ret = FAIL; |
104 | 5230 } |
5231 --recurse; | |
165 | 5232 return ret; |
104 | 5233 } |
5234 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5235 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5236 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
|
5237 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5238 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
|
5239 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
|
5240 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
|
5241 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5242 if (*atstart) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5243 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5244 *atstart = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5245 // 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
|
5246 // 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
|
5247 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
|
5248 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5249 // 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
|
5250 // 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
|
5251 // 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
|
5252 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
|
5253 msg_start(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5254 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5255 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5256 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
|
5257 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
|
5258 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5259 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
|
5260 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
|
5261 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5262 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
|
5263 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5264 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
|
5265 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5266 // 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
|
5267 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
|
5268 *needclr = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5269 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5270 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
|
5271 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5272 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5273 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5274 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
|
5275 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5276 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
|
5277 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5278 (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
|
5279 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
|
5280 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5281 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5282 (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
|
5283 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5284 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5285 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
|
5286 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5287 |
104 | 5288 /* |
7 | 5289 * ":echo expr1 ..." print each argument separated with a space, add a |
5290 * newline at the end. | |
5291 * ":echon expr1 ..." print each argument plain. | |
5292 */ | |
5293 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5294 ex_echo(exarg_T *eap) |
7 | 5295 { |
5296 char_u *arg = eap->arg; | |
137 | 5297 typval_T rettv; |
7 | 5298 char_u *p; |
5299 int needclr = TRUE; | |
5300 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
|
5301 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
|
5302 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
|
5303 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
|
5304 |
21104
f8ec5a7a9cf6
patch 8.2.1103: Coverity reports an unnecessary NULL check
Bram Moolenaar <Bram@vim.org>
parents:
21098
diff
changeset
|
5305 fill_evalarg_from_eap(&evalarg, eap, eap->skip); |
7 | 5306 |
5307 if (eap->skip) | |
5308 ++emsg_skip; | |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5309 while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int) |
7 | 5310 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5311 // 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
|
5312 // still need to be cleared. E.g., "echo 22,44". |
1624 | 5313 need_clr_eos = needclr; |
5314 | |
7 | 5315 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
|
5316 if (eval1(&arg, &rettv, &evalarg) == FAIL) |
7 | 5317 { |
5318 /* | |
5319 * Report the invalid expression unless the expression evaluation | |
5320 * has been cancelled due to an aborting error, an interrupt, or an | |
5321 * exception. | |
5322 */ | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5323 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
|
5324 && 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
|
5325 semsg(_(e_invexpr2), p); |
1624 | 5326 need_clr_eos = FALSE; |
5327 break; | |
5328 } | |
5329 need_clr_eos = FALSE; | |
5330 | |
7 | 5331 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
|
5332 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
|
5333 |
71 | 5334 clear_tv(&rettv); |
7 | 5335 arg = skipwhite(arg); |
5336 } | |
5337 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
|
5338 clear_evalarg(&evalarg, eap); |
7 | 5339 |
5340 if (eap->skip) | |
5341 --emsg_skip; | |
5342 else | |
5343 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5344 // remove text that may still be there from the command |
7 | 5345 if (needclr) |
5346 msg_clr_eos(); | |
5347 if (eap->cmdidx == CMD_echo) | |
5348 msg_end(); | |
5349 } | |
5350 } | |
5351 | |
5352 /* | |
5353 * ":echohl {name}". | |
5354 */ | |
5355 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5356 ex_echohl(exarg_T *eap) |
7 | 5357 { |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
5358 echo_attr = syn_name2attr(eap->arg); |
7 | 5359 } |
5360 | |
5361 /* | |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5362 * 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
|
5363 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5364 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5365 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
|
5366 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5367 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
|
5368 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5369 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5370 /* |
7 | 5371 * ":execute expr1 ..." execute the result of an expression. |
5372 * ":echomsg expr1 ..." Print a message | |
5373 * ":echoerr expr1 ..." Print an error | |
5374 * Each gets spaces around each argument and a newline at the end for | |
5375 * echo commands | |
5376 */ | |
5377 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5378 ex_execute(exarg_T *eap) |
7 | 5379 { |
5380 char_u *arg = eap->arg; | |
137 | 5381 typval_T rettv; |
7 | 5382 int ret = OK; |
5383 char_u *p; | |
5384 garray_T ga; | |
5385 int len; | |
5386 | |
5387 ga_init2(&ga, 1, 80); | |
5388 | |
5389 if (eap->skip) | |
5390 ++emsg_skip; | |
20061
6e6a75800884
patch 8.2.0586: Vim9: # comment not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20059
diff
changeset
|
5391 while (!ends_excmd2(eap->cmd, arg) || *arg == '"') |
7 | 5392 { |
21098
e88b0daa2fcb
patch 8.2.1100: Vim9: cannot use line break in :execute argument
Bram Moolenaar <Bram@vim.org>
parents:
21096
diff
changeset
|
5393 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
|
5394 if (ret == FAIL) |
7 | 5395 break; |
5396 | |
5397 if (!eap->skip) | |
5398 { | |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5399 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
|
5400 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5401 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
|
5402 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5403 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
|
5404 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5405 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
|
5406 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
|
5407 } |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5408 else |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5409 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
|
5410 } |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5411 else |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5412 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
|
5413 if (p == NULL) |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5414 { |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5415 clear_tv(&rettv); |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5416 ret = FAIL; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5417 break; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5418 } |
7 | 5419 len = (int)STRLEN(p); |
5420 if (ga_grow(&ga, len + 2) == FAIL) | |
5421 { | |
71 | 5422 clear_tv(&rettv); |
7 | 5423 ret = FAIL; |
5424 break; | |
5425 } | |
5426 if (ga.ga_len) | |
5427 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' '; | |
5428 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p); | |
5429 ga.ga_len += len; | |
5430 } | |
5431 | |
71 | 5432 clear_tv(&rettv); |
7 | 5433 arg = skipwhite(arg); |
5434 } | |
5435 | |
5436 if (ret != FAIL && ga.ga_data != NULL) | |
5437 { | |
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
|
5438 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
|
5439 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5440 // 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
|
5441 // 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
|
5442 // 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
|
5443 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
|
5444 } |
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5445 |
7 | 5446 if (eap->cmdidx == CMD_echomsg) |
625 | 5447 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
5448 msg_attr(ga.ga_data, echo_attr); |
625 | 5449 out_flush(); |
5450 } | |
7 | 5451 else if (eap->cmdidx == CMD_echoerr) |
5452 { | |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20128
diff
changeset
|
5453 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
|
5454 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5455 // 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
|
5456 emsg(ga.ga_data); |
7 | 5457 if (!force_abort) |
5458 did_emsg = save_did_emsg; | |
5459 } | |
5460 else if (eap->cmdidx == CMD_execute) | |
5461 do_cmdline((char_u *)ga.ga_data, | |
5462 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); | |
5463 } | |
5464 | |
5465 ga_clear(&ga); | |
5466 | |
5467 if (eap->skip) | |
5468 --emsg_skip; | |
5469 | |
5470 eap->nextcmd = check_nextcmd(arg); | |
5471 } | |
5472 | |
5473 /* | |
5474 * Skip over the name of an option: "&option", "&g:option" or "&l:option". | |
5475 * "arg" points to the "&" or '+' when called, to "option" when returning. | |
5476 * Returns NULL when no option name found. Otherwise pointer to the char | |
5477 * after the option name. | |
5478 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
5479 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5480 find_option_end(char_u **arg, int *opt_flags) |
7 | 5481 { |
5482 char_u *p = *arg; | |
5483 | |
5484 ++p; | |
5485 if (*p == 'g' && p[1] == ':') | |
5486 { | |
5487 *opt_flags = OPT_GLOBAL; | |
5488 p += 2; | |
5489 } | |
5490 else if (*p == 'l' && p[1] == ':') | |
5491 { | |
5492 *opt_flags = OPT_LOCAL; | |
5493 p += 2; | |
5494 } | |
5495 else | |
5496 *opt_flags = 0; | |
5497 | |
5498 if (!ASCII_ISALPHA(*p)) | |
5499 return NULL; | |
5500 *arg = p; | |
5501 | |
5502 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
|
5503 p += 4; // termcap option |
7 | 5504 else |
5505 while (ASCII_ISALPHA(*p)) | |
5506 ++p; | |
5507 return p; | |
5508 } | |
5509 | |
5510 /* | |
448 | 5511 * Display script name where an item was last set. |
5512 * Should only be invoked when 'verbose' is non-zero. | |
5513 */ | |
5514 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
|
5515 last_set_msg(sctx_T script_ctx) |
448 | 5516 { |
507 | 5517 char_u *p; |
5518 | |
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
|
5519 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
|
5520 { |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
5521 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); |
507 | 5522 if (p != NULL) |
5523 { | |
5524 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
5525 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
|
5526 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
|
5527 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
|
5528 { |
18939
25ebc35e104f
patch 8.2.0030: "gF" does not work on output of "verbose command"
Bram Moolenaar <Bram@vim.org>
parents:
18851
diff
changeset
|
5529 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
|
5530 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
|
5531 } |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
5532 verbose_leave(); |
507 | 5533 vim_free(p); |
5534 } | |
448 | 5535 } |
5536 } | |
5537 | |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
5538 #endif // FEAT_EVAL |
7 | 5539 |
5540 /* | |
5541 * 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
|
5542 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL. |
7 | 5543 * "flags" can be "g" to do a global substitute. |
5544 * Returns an allocated string, NULL for error. | |
5545 */ | |
5546 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5547 do_string_sub( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5548 char_u *str, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5549 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5550 char_u *sub, |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5551 typval_T *expr, |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5552 char_u *flags) |
7 | 5553 { |
5554 int sublen; | |
5555 regmatch_T regmatch; | |
5556 int i; | |
5557 int do_all; | |
5558 char_u *tail; | |
6332 | 5559 char_u *end; |
7 | 5560 garray_T ga; |
5561 char_u *ret; | |
5562 char_u *save_cpo; | |
5623 | 5563 char_u *zero_width = NULL; |
7 | 5564 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5565 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here |
7 | 5566 save_cpo = p_cpo; |
1672 | 5567 p_cpo = empty_option; |
7 | 5568 |
5569 ga_init2(&ga, 1, 200); | |
5570 | |
5571 do_all = (flags[0] == 'g'); | |
5572 | |
5573 regmatch.rm_ic = p_ic; | |
5574 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | |
5575 if (regmatch.regprog != NULL) | |
5576 { | |
5577 tail = str; | |
6332 | 5578 end = str + STRLEN(str); |
7 | 5579 while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) |
5580 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5581 // Skip empty match except for first match. |
5623 | 5582 if (regmatch.startp[0] == regmatch.endp[0]) |
5583 { | |
5584 if (zero_width == regmatch.startp[0]) | |
5585 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5586 // 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
|
5587 i = mb_ptr2len(tail); |
5964 | 5588 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, |
5589 (size_t)i); | |
5590 ga.ga_len += i; | |
5591 tail += i; | |
5623 | 5592 continue; |
5593 } | |
5594 zero_width = regmatch.startp[0]; | |
5595 } | |
5596 | |
7 | 5597 /* |
5598 * Get some space for a temporary buffer to do the substitution | |
5599 * into. It will contain: | |
5600 * - The text up to where the match is. | |
5601 * - The substituted text. | |
5602 * - The text after the match. | |
5603 */ | |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5604 sublen = vim_regsub(®match, sub, expr, tail, FALSE, TRUE, FALSE); |
6332 | 5605 if (ga_grow(&ga, (int)((end - tail) + sublen - |
7 | 5606 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL) |
5607 { | |
5608 ga_clear(&ga); | |
5609 break; | |
5610 } | |
5611 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5612 // copy the text up to where the match is |
7 | 5613 i = (int)(regmatch.startp[0] - tail); |
5614 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
|
5615 // add the substituted text |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5616 (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data |
7 | 5617 + ga.ga_len + i, TRUE, TRUE, FALSE); |
5618 ga.ga_len += i + sublen - 1; | |
5388 | 5619 tail = regmatch.endp[0]; |
5620 if (*tail == NUL) | |
5621 break; | |
7 | 5622 if (!do_all) |
5623 break; | |
5624 } | |
5625 | |
5626 if (ga.ga_data != NULL) | |
5627 STRCPY((char *)ga.ga_data + ga.ga_len, tail); | |
5628 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4778
diff
changeset
|
5629 vim_regfree(regmatch.regprog); |
7 | 5630 } |
5631 | |
5632 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data); | |
5633 ga_clear(&ga); | |
1672 | 5634 if (p_cpo == empty_option) |
5635 p_cpo = save_cpo; | |
5636 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5637 // Darn, evaluating {sub} expression or {expr} changed the value. |
1672 | 5638 free_string_option(save_cpo); |
7 | 5639 |
5640 return ret; | |
5641 } |