Mercurial > vim
annotate src/eval.c @ 21094:376b520312d6 v8.2.1098
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Commit: https://github.com/vim/vim/commit/006ad48b8a15c3bace741d8caaf3195e592fbe78
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 30 20:55:15 2020 +0200
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Problem: Vim9: cannot use line break in :throw argument.
Solution: Check for line break.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 30 Jun 2020 21:00:03 +0200 |
parents | 794bf2be08be |
children | 74e5e212e550 |
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 |
7 | 156 /* |
157 * Top level evaluation function, returning a boolean. | |
158 * Sets "error" to TRUE if there was an error. | |
159 * Return TRUE or FALSE. | |
160 */ | |
161 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
162 eval_to_bool( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
163 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
164 int *error, |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
165 exarg_T *eap, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
166 int skip) // only parse, don't execute |
7 | 167 { |
137 | 168 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
169 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
|
170 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
|
171 |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
172 CLEAR_FIELD(evalarg); |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
173 evalarg.eval_flags = skip ? 0 : EVAL_EVALUATE; |
21056
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
174 if (eap != NULL && getline_equal(eap->getline, eap->cookie, getsourceline)) |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
175 { |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
176 evalarg.eval_getline = eap->getline; |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
177 evalarg.eval_cookie = eap->cookie; |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
178 } |
7 | 179 |
180 if (skip) | |
181 ++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
|
182 if (eval0(arg, &tv, eap, &evalarg) == FAIL) |
7 | 183 *error = TRUE; |
184 else | |
185 { | |
186 *error = FALSE; | |
187 if (!skip) | |
188 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
189 retval = (tv_get_number_chk(&tv, error) != 0); |
71 | 190 clear_tv(&tv); |
7 | 191 } |
192 } | |
193 if (skip) | |
194 --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
|
195 clear_evalarg(&evalarg, eap); |
7 | 196 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
197 return (int)retval; |
7 | 198 } |
199 | |
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
|
200 /* |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
201 * 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
|
202 */ |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
203 static int |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
204 eval1_emsg(char_u **arg, typval_T *rettv, int evaluate) |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
205 { |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 int called_emsg_before = called_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
|
210 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
211 ret = eval1(arg, rettv, evaluate ? &EVALARG_EVALUATE : NULL); |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
212 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
|
213 { |
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 // 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
|
215 // 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
|
216 // 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
|
217 // 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
|
218 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
|
219 && called_emsg == called_emsg_before) |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
220 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
|
221 } |
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 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
|
223 } |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
224 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
225 /* |
20731
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
226 * 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
|
227 * 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
|
228 */ |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
229 int |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
230 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
|
231 { |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
232 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
|
233 && (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
|
234 || (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
|
235 } |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
236 |
ab27db64f1fb
patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
237 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
238 * 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
|
239 * 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
|
240 * 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
|
241 */ |
16231
0761a4c111a7
patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
242 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
|
243 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
|
244 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
249 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
|
250 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
251 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
|
252 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
|
253 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
254 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
|
255 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
256 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
|
257 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
|
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 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
|
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 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
|
262 |
20156
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
263 if (partial == NULL) |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
264 return FAIL; |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
265 |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20526
diff
changeset
|
266 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
|
267 && 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
|
268 { |
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
|
269 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
|
270 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
|
271 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
272 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
273 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
274 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
275 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
|
276 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
|
277 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 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
|
282 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
283 } |
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
|
284 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
285 else |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
286 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
287 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
|
288 if (s == NULL) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
289 return FAIL; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
290 s = skipwhite(s); |
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
|
291 if (eval1_emsg(&s, rettv, TRUE) == FAIL) |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
292 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
293 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
|
294 { |
14331
f8280e1bfc84
patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
295 clear_tv(rettv); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
296 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
|
297 return FAIL; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
298 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
299 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
300 return OK; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
301 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
302 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
303 /* |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
304 * Like eval_to_bool() but using a typval_T instead of a string. |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
305 * Works for string, funcref and partial. |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
306 */ |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
307 int |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
308 eval_expr_to_bool(typval_T *expr, int *error) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
309 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
310 typval_T rettv; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
311 int res; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
312 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
313 if (eval_expr_typval(expr, NULL, 0, &rettv) == FAIL) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
314 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
315 *error = TRUE; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
316 return FALSE; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
317 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
318 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
|
319 clear_tv(&rettv); |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
320 return res; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
321 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
322 |
7 | 323 /* |
324 * Top level evaluation function, returning a string. If "skip" is TRUE, | |
325 * only parsing to "nextcmd" is done, without reporting errors. Return | |
326 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE. | |
327 */ | |
328 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
329 eval_to_string_skip( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
330 char_u *arg, |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
331 exarg_T *eap, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
332 int skip) // only parse, don't execute |
7 | 333 { |
137 | 334 typval_T tv; |
7 | 335 char_u *retval; |
21094
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
336 evalarg_T evalarg; |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
337 |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
338 CLEAR_FIELD(evalarg); |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
339 evalarg.eval_flags = skip ? 0 : EVAL_EVALUATE; |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
340 if (eap != NULL && getline_equal(eap->getline, eap->cookie, getsourceline)) |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
341 { |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
342 evalarg.eval_getline = eap->getline; |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
343 evalarg.eval_cookie = eap->cookie; |
376b520312d6
patch 8.2.1098: Vim9: cannot use line break in :throw argument
Bram Moolenaar <Bram@vim.org>
parents:
21077
diff
changeset
|
344 } |
7 | 345 if (skip) |
346 ++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
|
347 if (eval0(arg, &tv, eap, &evalarg) == FAIL || skip) |
7 | 348 retval = NULL; |
349 else | |
350 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
351 retval = vim_strsave(tv_get_string(&tv)); |
71 | 352 clear_tv(&tv); |
7 | 353 } |
354 if (skip) | |
355 --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
|
356 clear_evalarg(&evalarg, eap); |
7 | 357 |
358 return retval; | |
359 } | |
360 | |
361 /* | |
9 | 362 * Skip over an expression at "*pp". |
363 * Return FAIL for an error, OK otherwise. | |
364 */ | |
365 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
366 skip_expr(char_u **pp) |
9 | 367 { |
137 | 368 typval_T rettv; |
9 | 369 |
370 *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
|
371 return eval1(pp, &rettv, NULL); |
9 | 372 } |
373 | |
374 /* | |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
375 * 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
|
376 * 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
|
377 * 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
|
378 * 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
|
379 */ |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
380 int |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
381 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
|
382 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
383 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
|
384 int res; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
389 if (vim9script && evalarg->eval_cookie != NULL) |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
390 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
391 ga_init2(gap, sizeof(char_u *), 10); |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
392 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
|
393 // leave room for "start" |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
394 ++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
|
395 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
396 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
397 // 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
|
398 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
|
399 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
|
400 *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
|
401 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
|
402 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
|
403 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
|
404 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
405 if (vim9script && evalarg->eval_cookie != NULL |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
406 && evalarg->eval_ga.ga_len > 1) |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
407 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
408 char_u *p; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
409 size_t endoff = STRLEN(*end); |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
410 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
411 // Line breaks encountered, concatenate all the lines. |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
412 *((char_u **)gap->ga_data) = *start; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
413 p = ga_concat_strings(gap, ""); |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
414 *((char_u **)gap->ga_data) = NULL; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
415 ga_clear_strings(gap); |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
416 gap->ga_itemsize = 0; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
417 if (p == NULL) |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
418 return FAIL; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
419 *start = p; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
420 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
|
421 evalarg->eval_tofree = p; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
422 // Compute "end" relative to the end. |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
423 *end = *start + STRLEN(*start) - endoff; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
424 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
425 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
426 return res; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
427 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
428 |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
429 /* |
7 | 430 * Top level evaluation function, returning a string. |
1713 | 431 * When "convert" is TRUE convert a List into a sequence of lines and convert |
432 * a Float to a String. | |
7 | 433 * Return pointer to allocated memory, or NULL for failure. |
434 */ | |
435 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
436 eval_to_string( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
437 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
438 int convert) |
7 | 439 { |
137 | 440 typval_T tv; |
7 | 441 char_u *retval; |
714 | 442 garray_T ga; |
1851 | 443 #ifdef FEAT_FLOAT |
1713 | 444 char_u numbuf[NUMBUFLEN]; |
1851 | 445 #endif |
7 | 446 |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
447 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) |
7 | 448 retval = NULL; |
449 else | |
450 { | |
1713 | 451 if (convert && tv.v_type == VAR_LIST) |
714 | 452 { |
453 ga_init2(&ga, (int)sizeof(char), 80); | |
1690 | 454 if (tv.vval.v_list != NULL) |
3000 | 455 { |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
456 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0); |
3000 | 457 if (tv.vval.v_list->lv_len > 0) |
458 ga_append(&ga, NL); | |
459 } | |
714 | 460 ga_append(&ga, NUL); |
461 retval = (char_u *)ga.ga_data; | |
462 } | |
1713 | 463 #ifdef FEAT_FLOAT |
464 else if (convert && tv.v_type == VAR_FLOAT) | |
465 { | |
466 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float); | |
467 retval = vim_strsave(numbuf); | |
468 } | |
469 #endif | |
714 | 470 else |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
471 retval = vim_strsave(tv_get_string(&tv)); |
71 | 472 clear_tv(&tv); |
7 | 473 } |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
474 clear_evalarg(&EVALARG_EVALUATE, NULL); |
7 | 475 |
476 return retval; | |
477 } | |
478 | |
479 /* | |
634 | 480 * 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
|
481 * textwinlock. When "use_sandbox" is TRUE use the sandbox. |
7 | 482 */ |
483 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
484 eval_to_string_safe( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
485 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
486 int use_sandbox) |
7 | 487 { |
488 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
|
489 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
|
490 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
491 save_funccal(&funccal_entry); |
634 | 492 if (use_sandbox) |
493 ++sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
494 ++textwinlock; |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
495 retval = eval_to_string(arg, FALSE); |
634 | 496 if (use_sandbox) |
497 --sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
498 --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
|
499 restore_funccal(); |
7 | 500 return retval; |
501 } | |
502 | |
503 /* | |
504 * Top level evaluation function, returning a number. | |
505 * Evaluates "expr" silently. | |
506 * Returns -1 for an error. | |
507 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
508 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
509 eval_to_number(char_u *expr) |
7 | 510 { |
137 | 511 typval_T rettv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
512 varnumber_T retval; |
97 | 513 char_u *p = skipwhite(expr); |
7 | 514 |
515 ++emsg_off; | |
516 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
517 if (eval1(&p, &rettv, &EVALARG_EVALUATE) == FAIL) |
7 | 518 retval = -1; |
519 else | |
520 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
521 retval = tv_get_number_chk(&rettv, NULL); |
71 | 522 clear_tv(&rettv); |
7 | 523 } |
524 --emsg_off; | |
525 | |
526 return retval; | |
527 } | |
528 | |
446 | 529 /* |
625 | 530 * Top level evaluation function. |
531 * Returns an allocated typval_T with the result. | |
532 * Returns NULL when there is an error. | |
446 | 533 */ |
534 typval_T * | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
535 eval_expr(char_u *arg, exarg_T *eap) |
446 | 536 { |
537 typval_T *tv; | |
538 | |
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
|
539 tv = ALLOC_ONE(typval_T); |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
540 if (tv != NULL && eval0(arg, tv, eap, &EVALARG_EVALUATE) == FAIL) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
541 VIM_CLEAR(tv); |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
542 clear_evalarg(&EVALARG_EVALUATE, eap); |
446 | 543 |
544 return tv; | |
545 } | |
546 | |
7 | 547 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
548 * 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
|
549 * 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
|
550 * should have type VAR_UNKNOWN. |
408 | 551 * Returns OK or FAIL. |
552 */ | |
3078 | 553 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
554 call_vim_function( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
555 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
556 int argc, |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
557 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
|
558 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
|
559 { |
408 | 560 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
561 funcexe_T funcexe; |
7 | 562 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 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
|
567 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
568 ret = call_func(func, -1, rettv, argc, argv, &funcexe); |
408 | 569 if (ret == FAIL) |
570 clear_tv(rettv); | |
571 | |
572 return ret; | |
573 } | |
574 | |
4133 | 575 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
576 * Call Vim script function "func" and return the result as a number. |
4133 | 577 * 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
|
578 * 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
|
579 * have type VAR_UNKNOWN. |
4133 | 580 */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
581 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
582 call_func_retnr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
583 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
584 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
|
585 typval_T *argv) |
4133 | 586 { |
587 typval_T rettv; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
588 varnumber_T retval; |
4133 | 589 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
590 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
4133 | 591 return -1; |
592 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
593 retval = tv_get_number_chk(&rettv, NULL); |
4133 | 594 clear_tv(&rettv); |
595 return retval; | |
596 } | |
597 | |
408 | 598 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
599 * Call Vim script function "func" and return the result as a string. |
453 | 600 * 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
|
601 * 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
|
602 * have type VAR_UNKNOWN. |
408 | 603 */ |
604 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
605 call_func_retstr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
606 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
607 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
|
608 typval_T *argv) |
408 | 609 { |
610 typval_T rettv; | |
453 | 611 char_u *retval; |
408 | 612 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
613 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 614 return NULL; |
615 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
616 retval = vim_strsave(tv_get_string(&rettv)); |
408 | 617 clear_tv(&rettv); |
7 | 618 return retval; |
619 } | |
1322 | 620 |
453 | 621 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
622 * 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
|
623 * 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
|
624 * have type VAR_UNKNOWN. |
1690 | 625 * Returns NULL when there is something wrong. |
408 | 626 */ |
627 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
628 call_func_retlist( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
629 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
630 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
|
631 typval_T *argv) |
408 | 632 { |
633 typval_T rettv; | |
634 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
635 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 636 return NULL; |
637 | |
638 if (rettv.v_type != VAR_LIST) | |
639 { | |
640 clear_tv(&rettv); | |
641 return NULL; | |
642 } | |
643 | |
644 return rettv.vval.v_list; | |
645 } | |
1322 | 646 |
7 | 647 #ifdef FEAT_FOLDING |
648 /* | |
649 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding | |
650 * it in "*cp". Doesn't give error messages. | |
651 */ | |
652 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
653 eval_foldexpr(char_u *arg, int *cp) |
7 | 654 { |
137 | 655 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
656 varnumber_T retval; |
7 | 657 char_u *s; |
681 | 658 int use_sandbox = was_set_insecurely((char_u *)"foldexpr", |
659 OPT_LOCAL); | |
7 | 660 |
661 ++emsg_off; | |
634 | 662 if (use_sandbox) |
663 ++sandbox; | |
20229
06a1dd50463e
patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
664 ++textwinlock; |
7 | 665 *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
|
666 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) |
7 | 667 retval = 0; |
668 else | |
669 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
670 // If the result is a number, just return the number. |
71 | 671 if (tv.v_type == VAR_NUMBER) |
672 retval = tv.vval.v_number; | |
156 | 673 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL) |
7 | 674 retval = 0; |
675 else | |
676 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
677 // 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
|
678 // the number. |
71 | 679 s = tv.vval.v_string; |
7 | 680 if (!VIM_ISDIGIT(*s) && *s != '-') |
681 *cp = *s++; | |
682 retval = atol((char *)s); | |
683 } | |
71 | 684 clear_tv(&tv); |
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; |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
690 clear_evalarg(&EVALARG_EVALUATE, NULL); |
7 | 691 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
692 return (int)retval; |
7 | 693 } |
694 #endif | |
695 | |
696 /* | |
110 | 697 * Get an lval: variable, Dict item or List item that can be assigned a value |
698 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]", | |
699 * "name.key", "name.key[expr]" etc. | |
700 * Indexing only works if "name" is an existing List or Dictionary. | |
701 * "name" points to the start of the name. | |
702 * If "rettv" is not NULL it points to the value to be assigned. | |
703 * "unlet" is TRUE for ":unlet": slightly different behavior when something is | |
704 * wrong; must end in space or cmd separator. | |
705 * | |
5604 | 706 * flags: |
707 * 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
|
708 * GLV_READ_ONLY: will not change the variable |
5604 | 709 * GLV_NO_AUTOLOAD: do not use script autoloading |
710 * | |
110 | 711 * Returns a pointer to just after the name, including indexes. |
124 | 712 * When an evaluation error occurs "lp->ll_name" is NULL; |
110 | 713 * Returns NULL for a parsing error. Still need to free items in "lp"! |
71 | 714 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
715 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
716 get_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
717 char_u *name, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
718 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
719 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
720 int unlet, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
721 int skip, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
722 int flags, // GLV_ values |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
723 int fne_flags) // flags for find_name_end() |
110 | 724 { |
725 char_u *p; | |
726 char_u *expr_start, *expr_end; | |
727 int cc; | |
137 | 728 dictitem_T *v; |
729 typval_T var1; | |
730 typval_T var2; | |
110 | 731 int empty1 = FALSE; |
137 | 732 listitem_T *ni; |
100 | 733 char_u *key = NULL; |
734 int len; | |
137 | 735 hashtab_T *ht; |
5604 | 736 int quiet = flags & GLV_QUIET; |
71 | 737 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
738 // Clear everything in "lp". |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
739 CLEAR_POINTER(lp); |
110 | 740 |
741 if (skip) | |
742 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
743 // When skipping just find the end of the name. |
110 | 744 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
|
745 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
|
746 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
|
747 return lp->ll_name_end; |
110 | 748 } |
749 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
750 // Find the end of the name. |
271 | 751 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
|
752 lp->ll_name_end = p; |
110 | 753 if (expr_start != NULL) |
754 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
755 // 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
|
756 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p) |
110 | 757 && *p != '[' && *p != '.') |
758 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
759 emsg(_(e_trailing)); |
110 | 760 return NULL; |
761 } | |
762 | |
763 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); | |
764 if (lp->ll_exp_name == NULL) | |
765 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
766 // 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
|
767 // 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
|
768 // aborting error, an interrupt, or an exception. |
110 | 769 if (!aborting() && !quiet) |
770 { | |
121 | 771 emsg_severe = TRUE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
772 semsg(_(e_invarg2), name); |
110 | 773 return NULL; |
774 } | |
775 } | |
776 lp->ll_name = lp->ll_exp_name; | |
777 } | |
778 else | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
779 { |
110 | 780 lp->ll_name = name; |
781 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
782 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
|
783 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
784 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
|
785 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
|
786 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
787 // 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
|
788 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
|
789 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
|
790 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
791 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
792 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
793 // Without [idx] or .key we are done. |
110 | 794 if ((*p != '[' && *p != '.') || lp->ll_name == NULL) |
795 return p; | |
796 | |
797 cc = *p; | |
798 *p = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
799 // 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
|
800 // 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
|
801 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
|
802 flags & GLV_NO_AUTOLOAD); |
110 | 803 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
|
804 semsg(_(e_undefvar), lp->ll_name); |
110 | 805 *p = cc; |
71 | 806 if (v == NULL) |
807 return NULL; | |
808 | |
110 | 809 /* |
810 * Loop until no more [idx] or .key is following. | |
811 */ | |
137 | 812 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
|
813 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
|
814 var2.v_type = VAR_UNKNOWN; |
110 | 815 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) |
816 { | |
817 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) | |
818 && !(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
|
819 && 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
|
820 && !(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
|
821 && lp->ll_tv->vval.v_blob != NULL)) |
110 | 822 { |
823 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
824 emsg(_("E689: Can only index a List, Dictionary or Blob")); |
110 | 825 return NULL; |
826 } | |
827 if (lp->ll_range) | |
828 { | |
829 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
830 emsg(_("E708: [:] must come last")); |
110 | 831 return NULL; |
71 | 832 } |
88 | 833 |
100 | 834 len = -1; |
835 if (*p == '.') | |
836 { | |
837 key = p + 1; | |
838 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
839 ; | |
840 if (len == 0) | |
841 { | |
110 | 842 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
843 emsg(_(e_emptykey)); |
110 | 844 return NULL; |
88 | 845 } |
100 | 846 p = key + len; |
847 } | |
848 else | |
849 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
850 // Get the index [expr] or the first index [expr: ]. |
88 | 851 p = skipwhite(p + 1); |
100 | 852 if (*p == ':') |
853 empty1 = TRUE; | |
88 | 854 else |
855 { | |
100 | 856 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
|
857 if (eval1(&p, &var1, &EVALARG_EVALUATE) == FAIL) // recursive! |
110 | 858 return NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
859 if (tv_get_string_chk(&var1) == NULL) |
323 | 860 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
861 // not a number or string |
323 | 862 clear_tv(&var1); |
863 return NULL; | |
864 } | |
100 | 865 } |
866 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
867 // Optionally get the second index [ :expr]. |
100 | 868 if (*p == ':') |
869 { | |
110 | 870 if (lp->ll_tv->v_type == VAR_DICT) |
871 { | |
872 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
873 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
|
874 clear_tv(&var1); |
110 | 875 return NULL; |
876 } | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
877 if (rettv != NULL |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
878 && !(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
|
879 && rettv->vval.v_list != NULL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
880 && !(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
|
881 && rettv->vval.v_blob != NULL)) |
110 | 882 { |
883 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
884 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
|
885 clear_tv(&var1); |
110 | 886 return NULL; |
88 | 887 } |
100 | 888 p = skipwhite(p + 1); |
889 if (*p == ']') | |
110 | 890 lp->ll_empty2 = TRUE; |
100 | 891 else |
892 { | |
110 | 893 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
|
894 // 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
|
895 if (eval1(&p, &var2, &EVALARG_EVALUATE) == FAIL) |
100 | 896 { |
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
|
897 clear_tv(&var1); |
110 | 898 return NULL; |
100 | 899 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
900 if (tv_get_string_chk(&var2) == NULL) |
323 | 901 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
902 // 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
|
903 clear_tv(&var1); |
323 | 904 clear_tv(&var2); |
905 return NULL; | |
906 } | |
100 | 907 } |
110 | 908 lp->ll_range = TRUE; |
100 | 909 } |
910 else | |
110 | 911 lp->ll_range = FALSE; |
100 | 912 |
913 if (*p != ']') | |
914 { | |
110 | 915 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
916 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
|
917 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
|
918 clear_tv(&var2); |
110 | 919 return NULL; |
100 | 920 } |
921 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
922 // Skip to past ']'. |
100 | 923 ++p; |
924 } | |
925 | |
110 | 926 if (lp->ll_tv->v_type == VAR_DICT) |
100 | 927 { |
928 if (len == -1) | |
929 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
930 // "[key]": get key from "var1" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
931 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
|
932 if (key == NULL) |
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
933 { |
100 | 934 clear_tv(&var1); |
110 | 935 return NULL; |
936 } | |
937 } | |
117 | 938 lp->ll_list = NULL; |
939 lp->ll_dict = lp->ll_tv->vval.v_dict; | |
121 | 940 lp->ll_di = dict_find(lp->ll_dict, key, len); |
2739 | 941 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
942 // 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
|
943 // 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
|
944 // g: dictionary). Disallow overwriting a builtin function. |
3687 | 945 if (rettv != NULL && lp->ll_dict->dv_scope != 0) |
946 { | |
947 int prevval; | |
948 int wrong; | |
949 | |
950 if (len != -1) | |
951 { | |
952 prevval = key[len]; | |
953 key[len] = NUL; | |
954 } | |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
955 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
956 prevval = 0; // avoid compiler warning |
3687 | 957 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE |
958 && rettv->v_type == VAR_FUNC | |
2739 | 959 && var_check_func_name(key, lp->ll_di == NULL)) |
3687 | 960 || !valid_varname(key); |
961 if (len != -1) | |
962 key[len] = prevval; | |
963 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
|
964 { |
0b35a7ffceb2
patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents:
20126
diff
changeset
|
965 clear_tv(&var1); |
2739 | 966 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
|
967 } |
2739 | 968 } |
969 | |
110 | 970 if (lp->ll_di == NULL) |
100 | 971 { |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
972 // 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
|
973 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
|
974 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht()) |
2739 | 975 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
976 semsg(_(e_illvar), name); |
16013
93b08b92a049
patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents:
15969
diff
changeset
|
977 clear_tv(&var1); |
2739 | 978 return NULL; |
979 } | |
980 | |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
981 // Key does not exist in dict: may need to add it. |
110 | 982 if (*p == '[' || *p == '.' || unlet) |
983 { | |
984 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
985 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
|
986 clear_tv(&var1); |
110 | 987 return NULL; |
100 | 988 } |
989 if (len == -1) | |
110 | 990 lp->ll_newkey = vim_strsave(key); |
100 | 991 else |
110 | 992 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
|
993 clear_tv(&var1); |
110 | 994 if (lp->ll_newkey == NULL) |
100 | 995 p = NULL; |
996 break; | |
997 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
998 // 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
|
999 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
|
1000 && 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
|
1001 { |
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
1002 clear_tv(&var1); |
2739 | 1003 return NULL; |
10910
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
1004 } |
2739 | 1005 |
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
|
1006 clear_tv(&var1); |
110 | 1007 lp->ll_tv = &lp->ll_di->di_tv; |
100 | 1008 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1009 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
|
1010 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1011 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
|
1012 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1013 /* |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1014 * 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
|
1015 */ |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1016 if (empty1) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1017 lp->ll_n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1018 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1019 // is number or string |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1020 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
|
1021 clear_tv(&var1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1022 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1023 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
|
1024 || lp->ll_n1 > bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1025 || (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
|
1026 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1027 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1028 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
|
1029 clear_tv(&var2); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1030 return NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1031 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1032 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
|
1033 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1034 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
|
1035 clear_tv(&var2); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1036 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
|
1037 || lp->ll_n2 >= bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1038 || 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
|
1039 { |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1040 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1041 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
|
1042 return NULL; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1043 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1044 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1045 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
|
1046 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
|
1047 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1048 } |
100 | 1049 else |
1050 { | |
1051 /* | |
1052 * Get the number and item for the only or first index of the List. | |
1053 */ | |
1054 if (empty1) | |
110 | 1055 lp->ll_n1 = 0; |
100 | 1056 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1057 // 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
|
1058 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
|
1059 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
|
1060 |
117 | 1061 lp->ll_dict = NULL; |
110 | 1062 lp->ll_list = lp->ll_tv->vval.v_list; |
1063 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
1064 if (lp->ll_li == NULL) | |
1065 { | |
842 | 1066 if (lp->ll_n1 < 0) |
1067 { | |
1068 lp->ll_n1 = 0; | |
1069 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
1070 } | |
1071 } | |
1072 if (lp->ll_li == NULL) | |
1073 { | |
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
|
1074 clear_tv(&var2); |
2772 | 1075 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1076 semsg(_(e_listidx), lp->ll_n1); |
110 | 1077 return NULL; |
100 | 1078 } |
1079 | |
1080 /* | |
1081 * May need to find the item or absolute index for the second | |
1082 * index of a range. | |
110 | 1083 * When no index given: "lp->ll_empty2" is TRUE. |
1084 * Otherwise "lp->ll_n2" is set to the second index. | |
100 | 1085 */ |
110 | 1086 if (lp->ll_range && !lp->ll_empty2) |
1087 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1088 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
|
1089 // is number or string |
88 | 1090 clear_tv(&var2); |
110 | 1091 if (lp->ll_n2 < 0) |
1092 { | |
1093 ni = list_find(lp->ll_list, lp->ll_n2); | |
100 | 1094 if (ni == NULL) |
2772 | 1095 { |
1096 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1097 semsg(_(e_listidx), lp->ll_n2); |
110 | 1098 return NULL; |
2772 | 1099 } |
110 | 1100 lp->ll_n2 = list_idx_of_item(lp->ll_list, ni); |
1101 } | |
1102 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1103 // Check that lp->ll_n2 isn't before lp->ll_n1. |
110 | 1104 if (lp->ll_n1 < 0) |
1105 lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li); | |
1106 if (lp->ll_n2 < lp->ll_n1) | |
2772 | 1107 { |
1108 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1109 semsg(_(e_listidx), lp->ll_n2); |
110 | 1110 return NULL; |
2772 | 1111 } |
110 | 1112 } |
1113 | |
1114 lp->ll_tv = &lp->ll_li->li_tv; | |
1115 } | |
1116 } | |
1117 | |
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
|
1118 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
|
1119 lp->ll_name_end = p; |
110 | 1120 return p; |
1121 } | |
1122 | |
1123 /* | |
137 | 1124 * Clear lval "lp" that was filled by get_lval(). |
110 | 1125 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1126 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1127 clear_lval(lval_T *lp) |
110 | 1128 { |
1129 vim_free(lp->ll_exp_name); | |
1130 vim_free(lp->ll_newkey); | |
1131 } | |
1132 | |
1133 /* | |
151 | 1134 * Set a variable that was parsed by get_lval() to "rettv". |
110 | 1135 * "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
|
1136 * "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
|
1137 * "%" for "%=", "." for ".=" or "=" for "=". |
117 | 1138 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
1139 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1140 set_var_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1141 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1142 char_u *endp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1143 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1144 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
|
1145 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
|
1146 char_u *op) |
110 | 1147 { |
1148 int cc; | |
137 | 1149 listitem_T *ri; |
1150 dictitem_T *di; | |
110 | 1151 |
1152 if (lp->ll_tv == NULL) | |
1153 { | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1154 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
|
1155 *endp = NUL; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1156 if (lp->ll_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1157 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1158 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
|
1159 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1160 if (op != NULL && *op != '=') |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1161 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1162 semsg(_(e_letwrong), op); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1163 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1164 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1165 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1166 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
|
1167 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1168 int il, ir; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1169 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1170 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1171 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
|
1172 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1173 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
|
1174 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1175 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
|
1176 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1177 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1178 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1179 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
|
1180 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1181 ir = 0; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1182 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
|
1183 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
|
1184 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
|
1185 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1186 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1187 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1188 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
|
1189 if (!error) |
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 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
|
1192 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1193 // 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
|
1194 // the end is an error otherwise. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1195 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
|
1196 || (lp->ll_n1 == gap->ga_len |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1197 && 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
|
1198 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1199 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
|
1200 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
|
1201 ++gap->ga_len; |
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 // 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
|
1204 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1205 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1206 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1207 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
|
1208 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1209 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
|
1210 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1211 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
|
1212 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1213 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
|
1214 *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
|
1215 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1216 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1217 |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1218 // 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
|
1219 di = NULL; |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1220 if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name), |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1221 &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
|
1222 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1223 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
|
1224 || (!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
|
1225 && !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
|
1226 && 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
|
1227 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
|
1228 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
|
1229 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1230 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1231 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1232 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
|
1233 *endp = cc; |
110 | 1234 } |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1235 else if (var_check_lock(lp->ll_newkey == NULL |
151 | 1236 ? lp->ll_tv->v_lock |
6773 | 1237 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE)) |
151 | 1238 ; |
110 | 1239 else if (lp->ll_range) |
1240 { | |
6166 | 1241 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
|
1242 int ll_n1 = lp->ll_n1; |
6166 | 1243 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1244 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
|
1245 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1246 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
|
1247 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1248 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1249 |
6166 | 1250 /* |
1251 * Check whether any of the list items is locked | |
1252 */ | |
6422 | 1253 for (ri = rettv->vval.v_list->lv_first; ri != NULL && ll_li != NULL; ) |
6166 | 1254 { |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1255 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE)) |
6166 | 1256 return; |
1257 ri = ri->li_next; | |
1258 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == ll_n1)) | |
1259 break; | |
1260 ll_li = ll_li->li_next; | |
1261 ++ll_n1; | |
1262 } | |
1263 | |
110 | 1264 /* |
1265 * Assign the List values to the list items. | |
1266 */ | |
1267 for (ri = rettv->vval.v_list->lv_first; ri != NULL; ) | |
1268 { | |
117 | 1269 if (op != NULL && *op != '=') |
1270 tv_op(&lp->ll_li->li_tv, &ri->li_tv, op); | |
1271 else | |
1272 { | |
1273 clear_tv(&lp->ll_li->li_tv); | |
1274 copy_tv(&ri->li_tv, &lp->ll_li->li_tv); | |
1275 } | |
110 | 1276 ri = ri->li_next; |
1277 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1)) | |
1278 break; | |
1279 if (lp->ll_li->li_next == NULL) | |
1280 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1281 // Need to add an empty item. |
533 | 1282 if (list_append_number(lp->ll_list, 0) == FAIL) |
110 | 1283 { |
1284 ri = NULL; | |
88 | 1285 break; |
110 | 1286 } |
1287 } | |
1288 lp->ll_li = lp->ll_li->li_next; | |
1289 ++lp->ll_n1; | |
1290 } | |
1291 if (ri != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1292 emsg(_("E710: List value has more items than target")); |
117 | 1293 else if (lp->ll_empty2 |
1294 ? (lp->ll_li != NULL && lp->ll_li->li_next != NULL) | |
110 | 1295 : 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
|
1296 emsg(_("E711: List value has not enough items")); |
110 | 1297 } |
1298 else | |
1299 { | |
1300 /* | |
1301 * Assign to a List or Dictionary item. | |
1302 */ | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1303 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
|
1304 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1305 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
|
1306 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1307 } |
110 | 1308 if (lp->ll_newkey != NULL) |
1309 { | |
117 | 1310 if (op != NULL && *op != '=') |
1311 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1312 semsg(_(e_letwrong), op); |
117 | 1313 return; |
1314 } | |
1315 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1316 // Need to add an item to the Dictionary. |
121 | 1317 di = dictitem_alloc(lp->ll_newkey); |
110 | 1318 if (di == NULL) |
1319 return; | |
121 | 1320 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL) |
1321 { | |
1322 vim_free(di); | |
1323 return; | |
1324 } | |
110 | 1325 lp->ll_tv = &di->di_tv; |
1326 } | |
117 | 1327 else if (op != NULL && *op != '=') |
1328 { | |
1329 tv_op(lp->ll_tv, rettv, op); | |
1330 return; | |
1331 } | |
110 | 1332 else |
1333 clear_tv(lp->ll_tv); | |
1334 | |
1335 /* | |
1336 * Assign the value to the variable or list item. | |
1337 */ | |
1338 if (copy) | |
1339 copy_tv(rettv, lp->ll_tv); | |
1340 else | |
1341 { | |
1342 *lp->ll_tv = *rettv; | |
156 | 1343 lp->ll_tv->v_lock = 0; |
110 | 1344 init_tv(rettv); |
1345 } | |
1346 } | |
7 | 1347 } |
1348 | |
76 | 1349 /* |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1350 * 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
|
1351 * and "tv1 .= tv2" |
117 | 1352 * Returns OK or FAIL. |
1353 */ | |
1354 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1355 tv_op(typval_T *tv1, typval_T *tv2, char_u *op) |
117 | 1356 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1357 varnumber_T n; |
117 | 1358 char_u numbuf[NUMBUFLEN]; |
1359 char_u *s; | |
1360 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1361 // 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
|
1362 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
|
1363 && tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL) |
117 | 1364 { |
1365 switch (tv1->v_type) | |
1366 { | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1367 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
|
1368 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
|
1369 case VAR_VOID: |
117 | 1370 case VAR_DICT: |
1371 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1372 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
|
1373 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1374 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1375 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
1376 case VAR_CHANNEL: |
117 | 1377 break; |
1378 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1379 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1380 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
|
1381 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1382 // BLOB += BLOB |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1383 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
|
1384 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1385 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
|
1386 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
|
1387 int i, len = blob_len(b2); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1388 for (i = 0; i < len; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1389 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
|
1390 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1391 return OK; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1392 |
117 | 1393 case VAR_LIST: |
1394 if (*op != '+' || tv2->v_type != VAR_LIST) | |
1395 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1396 // List += List |
117 | 1397 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL) |
1398 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL); | |
1399 return OK; | |
1400 | |
1401 case VAR_NUMBER: | |
1402 case VAR_STRING: | |
1403 if (tv2->v_type == VAR_LIST) | |
1404 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1405 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
|
1406 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1407 // 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
|
1408 n = tv_get_number(tv1); |
1624 | 1409 #ifdef FEAT_FLOAT |
1410 if (tv2->v_type == VAR_FLOAT) | |
1411 { | |
1412 float_T f = n; | |
1413 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1414 if (*op == '%') |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1415 break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1416 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1417 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1418 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
|
1419 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
|
1420 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
|
1421 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
|
1422 } |
1624 | 1423 clear_tv(tv1); |
1424 tv1->v_type = VAR_FLOAT; | |
1425 tv1->vval.v_float = f; | |
1426 } | |
117 | 1427 else |
1624 | 1428 #endif |
1429 { | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1430 switch (*op) |
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 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
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 } |
1624 | 1438 clear_tv(tv1); |
1439 tv1->v_type = VAR_NUMBER; | |
1440 tv1->vval.v_number = n; | |
1441 } | |
1442 } | |
1443 else | |
1444 { | |
1445 if (tv2->v_type == VAR_FLOAT) | |
1446 break; | |
1447 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1448 // str .= str |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1449 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
|
1450 s = concat_str(s, tv_get_string_buf(tv2, numbuf)); |
117 | 1451 clear_tv(tv1); |
1452 tv1->v_type = VAR_STRING; | |
1453 tv1->vval.v_string = s; | |
1454 } | |
1455 return OK; | |
1624 | 1456 |
1457 case VAR_FLOAT: | |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1458 #ifdef FEAT_FLOAT |
1624 | 1459 { |
1460 float_T f; | |
1461 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1462 if (*op == '%' || *op == '.' |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1463 || (tv2->v_type != VAR_FLOAT |
1624 | 1464 && tv2->v_type != VAR_NUMBER |
1465 && tv2->v_type != VAR_STRING)) | |
1466 break; | |
1467 if (tv2->v_type == VAR_FLOAT) | |
1468 f = tv2->vval.v_float; | |
1469 else | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1470 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
|
1471 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1472 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1473 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
|
1474 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
|
1475 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
|
1476 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
|
1477 } |
1624 | 1478 } |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1479 #endif |
1624 | 1480 return OK; |
117 | 1481 } |
1482 } | |
1483 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1484 semsg(_(e_letwrong), op); |
117 | 1485 return FAIL; |
1486 } | |
1487 | |
1488 /* | |
76 | 1489 * Evaluate the expression used in a ":for var in expr" command. |
1490 * "arg" points to "var". | |
1491 * Set "*errp" to TRUE for an error, FALSE otherwise; | |
1492 * Return a pointer that holds the info. Null when there is an error. | |
1493 */ | |
1494 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1495 eval_for_line( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1496 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1497 int *errp, |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1498 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
|
1499 evalarg_T *evalarg) |
76 | 1500 { |
137 | 1501 forinfo_T *fi; |
76 | 1502 char_u *expr; |
137 | 1503 typval_T tv; |
1504 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
|
1505 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
|
1506 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1507 *errp = TRUE; // default: there is an error |
76 | 1508 |
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
|
1509 fi = ALLOC_CLEAR_ONE(forinfo_T); |
76 | 1510 if (fi == NULL) |
1511 return NULL; | |
1512 | |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
1513 expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon, FALSE); |
76 | 1514 if (expr == NULL) |
1515 return fi; | |
1516 | |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1517 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
|
1518 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
|
1519 || !(expr[2] == NUL || VIM_ISWHITE(expr[2]))) |
76 | 1520 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1521 emsg(_(e_missing_in)); |
76 | 1522 return fi; |
1523 } | |
1524 | |
1525 if (skip) | |
1526 ++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
|
1527 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
|
1528 if (eval0(expr, &tv, eap, evalarg) == OK) |
76 | 1529 { |
1530 *errp = FALSE; | |
1531 if (!skip) | |
1532 { | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1533 if (tv.v_type == VAR_LIST) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1534 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1535 l = tv.vval.v_list; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1536 if (l == NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1537 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1538 // 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
|
1539 clear_tv(&tv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1540 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1541 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1542 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1543 // 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
|
1544 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
|
1545 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1546 // 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
|
1547 // the list being used in "tv". |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1548 fi->fi_list = l; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1549 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
|
1550 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
|
1551 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1552 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1553 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
|
1554 { |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1555 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
|
1556 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
|
1557 { |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1558 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
|
1559 |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1560 // 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
|
1561 // 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
|
1562 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
|
1563 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
|
1564 } |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1565 clear_tv(&tv); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1566 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1567 else |
359 | 1568 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1569 emsg(_(e_listreq)); |
359 | 1570 clear_tv(&tv); |
1571 } | |
76 | 1572 } |
1573 } | |
1574 if (skip) | |
1575 --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
|
1576 fi->fi_break_count = evalarg->eval_break_count; |
76 | 1577 |
1578 return fi; | |
1579 } | |
1580 | |
1581 /* | |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1582 * 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
|
1583 */ |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1584 void |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1585 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
|
1586 { |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1587 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
|
1588 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
|
1589 |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1590 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
|
1591 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
|
1592 } |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1593 |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1594 /* |
76 | 1595 * Use the first item in a ":for" list. Advance to the next. |
1596 * Assign the values to the variable (list). "arg" points to the first one. | |
1597 * Return TRUE when a valid item was found, FALSE when at end of list or | |
1598 * something wrong. | |
1599 */ | |
1600 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1601 next_for_item(void *fi_void, char_u *arg) |
76 | 1602 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
1603 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1604 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
|
1605 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
|
1606 LET_NO_COMMAND : 0; |
137 | 1607 listitem_T *item; |
76 | 1608 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1609 if (fi->fi_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1610 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1611 typval_T tv; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1612 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1613 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
|
1614 return FALSE; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1615 tv.v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1616 tv.v_lock = VAR_FIXED; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1617 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
|
1618 ++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
|
1619 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
|
1620 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
|
1621 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1622 |
76 | 1623 item = fi->fi_lw.lw_item; |
1624 if (item == NULL) | |
1625 result = FALSE; | |
1626 else | |
1627 { | |
1628 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
|
1629 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
|
1630 fi->fi_varcount, flag, NULL) == OK); |
76 | 1631 } |
1632 return result; | |
1633 } | |
1634 | |
1635 /* | |
1636 * Free the structure used to store info used by ":for". | |
1637 */ | |
1638 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1639 free_for_info(void *fi_void) |
76 | 1640 { |
137 | 1641 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1642 |
92 | 1643 if (fi != NULL && fi->fi_list != NULL) |
359 | 1644 { |
76 | 1645 list_rem_watch(fi->fi_list, &fi->fi_lw); |
359 | 1646 list_unref(fi->fi_list); |
1647 } | |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
1648 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
|
1649 blob_unref(fi->fi_blob); |
76 | 1650 vim_free(fi); |
1651 } | |
1652 | |
7 | 1653 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1654 set_context_for_expression( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1655 expand_T *xp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1656 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1657 cmdidx_T cmdidx) |
7 | 1658 { |
1659 int got_eq = FALSE; | |
1660 int c; | |
76 | 1661 char_u *p; |
1662 | |
18713
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1663 if (cmdidx == CMD_let || cmdidx == CMD_const) |
76 | 1664 { |
1665 xp->xp_context = EXPAND_USER_VARS; | |
159 | 1666 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) |
76 | 1667 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1668 // ":let var1 var2 ...": find last space. |
159 | 1669 for (p = arg + STRLEN(arg); p >= arg; ) |
76 | 1670 { |
1671 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
|
1672 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
|
1673 if (VIM_ISWHITE(*p)) |
76 | 1674 break; |
1675 } | |
1676 return; | |
1677 } | |
1678 } | |
1679 else | |
1680 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS | |
1681 : EXPAND_EXPRESSION; | |
7 | 1682 while ((xp->xp_pattern = vim_strpbrk(arg, |
1683 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) | |
1684 { | |
1685 c = *xp->xp_pattern; | |
1686 if (c == '&') | |
1687 { | |
1688 c = xp->xp_pattern[1]; | |
1689 if (c == '&') | |
1690 { | |
1691 ++xp->xp_pattern; | |
1692 xp->xp_context = cmdidx != CMD_let || got_eq | |
1693 ? EXPAND_EXPRESSION : EXPAND_NOTHING; | |
1694 } | |
1695 else if (c != ' ') | |
201 | 1696 { |
7 | 1697 xp->xp_context = EXPAND_SETTINGS; |
201 | 1698 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') |
1699 xp->xp_pattern += 2; | |
1700 | |
1701 } | |
7 | 1702 } |
1703 else if (c == '$') | |
1704 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1705 // environment variable |
7 | 1706 xp->xp_context = EXPAND_ENV_VARS; |
1707 } | |
1708 else if (c == '=') | |
1709 { | |
1710 got_eq = TRUE; | |
1711 xp->xp_context = EXPAND_EXPRESSION; | |
1712 } | |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1713 else if (c == '#' |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1714 && xp->xp_context == EXPAND_EXPRESSION) |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1715 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1716 // Autoload function/variable contains '#'. |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1717 break; |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1718 } |
6367 | 1719 else if ((c == '<' || c == '#') |
7 | 1720 && xp->xp_context == EXPAND_FUNCTIONS |
1721 && vim_strchr(xp->xp_pattern, '(') == NULL) | |
1722 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1723 // Function name can start with "<SNR>" and contain '#'. |
7 | 1724 break; |
1725 } | |
1726 else if (cmdidx != CMD_let || got_eq) | |
1727 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1728 if (c == '"') // string |
7 | 1729 { |
1730 while ((c = *++xp->xp_pattern) != NUL && c != '"') | |
1731 if (c == '\\' && xp->xp_pattern[1] != NUL) | |
1732 ++xp->xp_pattern; | |
1733 xp->xp_context = EXPAND_NOTHING; | |
1734 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1735 else if (c == '\'') // literal string |
7 | 1736 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1737 // Trick: '' is like stopping and starting a literal string. |
7 | 1738 while ((c = *++xp->xp_pattern) != NUL && c != '\'') |
1739 /* skip */ ; | |
1740 xp->xp_context = EXPAND_NOTHING; | |
1741 } | |
1742 else if (c == '|') | |
1743 { | |
1744 if (xp->xp_pattern[1] == '|') | |
1745 { | |
1746 ++xp->xp_pattern; | |
1747 xp->xp_context = EXPAND_EXPRESSION; | |
1748 } | |
1749 else | |
1750 xp->xp_context = EXPAND_COMMANDS; | |
1751 } | |
1752 else | |
1753 xp->xp_context = EXPAND_EXPRESSION; | |
1754 } | |
1755 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1756 // 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
|
1757 // anyway. |
76 | 1758 xp->xp_context = EXPAND_EXPRESSION; |
7 | 1759 arg = xp->xp_pattern; |
1760 if (*arg != NUL) | |
1761 while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) | |
1762 /* skip */ ; | |
1763 } | |
1764 xp->xp_pattern = arg; | |
1765 } | |
1766 | |
1767 /* | |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1768 * Return TRUE if "pat" matches "text". |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1769 * 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
|
1770 */ |
17377
cb008de2a6ec
patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17375
diff
changeset
|
1771 int |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1772 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
|
1773 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1774 int matches = FALSE; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1775 char_u *save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1776 regmatch_T regmatch; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1777 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1778 // avoid 'l' flag in 'cpoptions' |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1779 save_cpo = p_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1780 p_cpo = (char_u *)""; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1781 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
|
1782 if (regmatch.regprog != NULL) |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1783 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1784 regmatch.rm_ic = ic; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1785 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
|
1786 vim_regfree(regmatch.regprog); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1787 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1788 p_cpo = save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1789 return matches; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1790 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1791 |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1792 /* |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1793 * 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
|
1794 * "expr->name(arg)". |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1795 * Returns OK or FAIL. |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1796 */ |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1797 static int |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1798 eval_func( |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1799 char_u **arg, // points to "(", will be advanced |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1800 char_u *name, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1801 int name_len, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1802 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
|
1803 int flags, |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1804 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
|
1805 { |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1806 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
|
1807 char_u *s = name; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1808 int len = name_len; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1809 partial_T *partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1810 int ret = OK; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1811 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1812 if (!evaluate) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1813 check_vars(s, len); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1814 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1815 // 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
|
1816 // use its contents. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1817 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
|
1818 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1819 // 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
|
1820 // the name invalid. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1821 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
|
1822 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
|
1823 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1824 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1825 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1826 funcexe_T funcexe; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1827 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1828 // Invoke the function. |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1829 CLEAR_FIELD(funcexe); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1830 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
|
1831 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
|
1832 funcexe.evaluate = evaluate; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1833 funcexe.partial = partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1834 funcexe.basetv = basetv; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1835 ret = get_func_tv(s, len, rettv, arg, &funcexe); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1836 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1837 vim_free(s); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1838 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1839 // 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
|
1840 // 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
|
1841 // 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
|
1842 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
|
1843 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1844 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
|
1845 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
|
1846 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1847 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1848 // 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
|
1849 // 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
|
1850 // 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
|
1851 if (evaluate && aborting()) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1852 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1853 if (ret == OK) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1854 clear_tv(rettv); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1855 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1856 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1857 return ret; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1858 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1859 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1860 /* |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1861 * If inside Vim9 script, "arg" points to the end of a line (ignoring comments) |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1862 * and there is a next line, return the next line (skipping blanks) and set |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1863 * "getnext". |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1864 * 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
|
1865 * "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
|
1866 */ |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21026
diff
changeset
|
1867 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
|
1868 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
|
1869 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1870 *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
|
1871 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
|
1872 && 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
|
1873 && evalarg->eval_cookie != NULL |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1874 && (*arg == NUL || (VIM_ISWHITE(arg[-1]) |
21056
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
1875 && (*arg == '"' || *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
|
1876 { |
21056
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
1877 char_u *p = getline_peek(evalarg->eval_getline, evalarg->eval_cookie); |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1878 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1879 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
|
1880 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1881 *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
|
1882 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
|
1883 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1884 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1885 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
|
1886 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1887 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
1888 /* |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1889 * 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
|
1890 */ |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21026
diff
changeset
|
1891 char_u * |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1892 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
|
1893 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1894 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
|
1895 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
|
1896 |
21056
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
1897 line = evalarg->eval_getline(0, evalarg->eval_cookie, 0, 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
|
1898 ++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
|
1899 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
|
1900 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1901 // 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
|
1902 ((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
|
1903 ++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
|
1904 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1905 else |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1906 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1907 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
|
1908 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
|
1909 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
1910 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
|
1911 } |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1912 |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1913 char_u * |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1914 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
|
1915 { |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1916 int getnext; |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1917 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
|
1918 |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1919 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
|
1920 if (getnext) |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1921 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
|
1922 return p; |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1923 } |
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
1924 |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1925 /* |
21050
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1926 * 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
|
1927 */ |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1928 void |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1929 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
|
1930 { |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1931 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
|
1932 { |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1933 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
|
1934 { |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1935 // 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
|
1936 // ":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
|
1937 // 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
|
1938 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
|
1939 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
|
1940 *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
|
1941 } |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1942 else |
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1943 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
|
1944 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
|
1945 } |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1946 } |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1947 |
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21048
diff
changeset
|
1948 /* |
7 | 1949 * The "evaluate" argument: When FALSE, the argument is only parsed but not |
71 | 1950 * executed. The function may return OK, but the rettv will be of type |
7 | 1951 * VAR_UNKNOWN. The function still returns FAIL for a syntax error. |
1952 */ | |
1953 | |
1954 /* | |
1955 * Handle zero level expression. | |
1956 * This calls eval1() and handles error message and nextcmd. | |
71 | 1957 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. |
533 | 1958 * 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
|
1959 * "evalarg" can be NULL, EVALARG_EVALUATE or a pointer. |
7 | 1960 * Return OK or FAIL. |
1961 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1962 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1963 eval0( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1964 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1965 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
|
1966 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
|
1967 evalarg_T *evalarg) |
7 | 1968 { |
1969 int ret; | |
1970 char_u *p; | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1971 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
|
1972 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
|
1973 int flags = evalarg == NULL ? 0 : evalarg->eval_flags; |
7 | 1974 |
1975 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
|
1976 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
|
1977 |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1978 if (ret == FAIL || !ends_excmd2(arg, p)) |
7 | 1979 { |
1980 if (ret != FAIL) | |
71 | 1981 clear_tv(rettv); |
7 | 1982 /* |
1983 * Report the invalid expression unless the expression evaluation has | |
1984 * 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
|
1985 * 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
|
1986 * Also check called_emsg for when using assert_fails(). |
7 | 1987 */ |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1988 if (!aborting() |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1989 && 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
|
1990 && 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
|
1991 && (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
|
1992 semsg(_(e_invexpr2), arg); |
7 | 1993 ret = FAIL; |
1994 } | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1995 |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1996 if (eap != NULL) |
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1997 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
|
1998 |
7 | 1999 return ret; |
2000 } | |
2001 | |
2002 /* | |
2003 * Handle top level expression: | |
1800 | 2004 * expr2 ? expr1 : expr1 |
7 | 2005 * |
2006 * "arg" must point to the first non-white of the expression. | |
2007 * "arg" is advanced to the next non-white after the recognized expression. | |
2008 * | |
533 | 2009 * Note: "rettv.v_lock" is not set. |
2010 * | |
7 | 2011 * Return OK or FAIL. |
2012 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
2013 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
|
2014 eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2015 { |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2016 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
|
2017 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
|
2018 |
7 | 2019 /* |
2020 * Get the first variable. | |
2021 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2022 if (eval2(arg, rettv, evalarg) == FAIL) |
7 | 2023 return FAIL; |
2024 | |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2025 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
|
2026 if (*p == '?') |
7 | 2027 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2028 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
|
2029 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
|
2030 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
|
2031 int orig_flags; |
21002
4852db420162
patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2032 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
|
2033 |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2034 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
|
2035 *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
|
2036 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2037 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
|
2038 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2039 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
|
2040 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
|
2041 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2042 else |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2043 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2044 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
|
2045 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
|
2046 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2047 |
21002
4852db420162
patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2048 evaluate = nested_evalarg.eval_flags & EVAL_EVALUATE; |
7 | 2049 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
|
2050 if (evaluate) |
7 | 2051 { |
323 | 2052 int error = FALSE; |
2053 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2054 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 2055 result = TRUE; |
71 | 2056 clear_tv(rettv); |
323 | 2057 if (error) |
2058 return FAIL; | |
7 | 2059 } |
2060 | |
2061 /* | |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2062 * Get the second variable. Recursive! |
7 | 2063 */ |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2064 *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
|
2065 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
|
2066 : 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
|
2067 if (eval1(arg, rettv, &nested_evalarg) == FAIL) |
7 | 2068 return FAIL; |
2069 | |
2070 /* | |
2071 * Check for the ":". | |
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 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
|
2074 if (*p != ':') |
7 | 2075 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2076 emsg(_(e_missing_colon)); |
7 | 2077 if (evaluate && result) |
71 | 2078 clear_tv(rettv); |
7 | 2079 return FAIL; |
2080 } | |
21022
9d8634e91d1b
patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents:
21002
diff
changeset
|
2081 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
|
2082 *arg = eval_next_line(evalarg); |
7 | 2083 |
2084 /* | |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2085 * Get the third variable. Recursive! |
7 | 2086 */ |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2087 *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
|
2088 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
|
2089 : 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
|
2090 if (eval1(arg, &var2, &nested_evalarg) == FAIL) |
7 | 2091 { |
2092 if (evaluate && result) | |
71 | 2093 clear_tv(rettv); |
7 | 2094 return FAIL; |
2095 } | |
2096 if (evaluate && !result) | |
71 | 2097 *rettv = var2; |
7 | 2098 } |
2099 | |
2100 return OK; | |
2101 } | |
2102 | |
2103 /* | |
2104 * Handle first level expression: | |
2105 * expr2 || expr2 || expr2 logical OR | |
2106 * | |
2107 * "arg" must point to the first non-white of the expression. | |
2108 * "arg" is advanced to the next non-white after the recognized expression. | |
2109 * | |
2110 * Return OK or FAIL. | |
2111 */ | |
2112 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
|
2113 eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2114 { |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2115 char_u *p; |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2116 int getnext; |
137 | 2117 typval_T var2; |
7 | 2118 long result; |
2119 int first; | |
323 | 2120 int error = FALSE; |
7 | 2121 |
2122 /* | |
2123 * Get the first variable. | |
2124 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2125 if (eval3(arg, rettv, evalarg) == FAIL) |
7 | 2126 return FAIL; |
2127 | |
2128 /* | |
2129 * Repeat until there is no following "||". | |
2130 */ | |
2131 first = TRUE; | |
2132 result = FALSE; | |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2133 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
|
2134 while (p[0] == '|' && p[1] == '|') |
7 | 2135 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2136 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
|
2137 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
|
2138 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
|
2139 |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2140 if (getnext) |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2141 *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
|
2142 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2143 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
|
2144 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2145 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
|
2146 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
|
2147 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
|
2148 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2149 else |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2150 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2151 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
|
2152 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
|
2153 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
|
2154 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2155 |
7 | 2156 if (evaluate && first) |
2157 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2158 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 2159 result = TRUE; |
71 | 2160 clear_tv(rettv); |
323 | 2161 if (error) |
2162 return FAIL; | |
7 | 2163 first = FALSE; |
2164 } | |
2165 | |
2166 /* | |
2167 * Get the second variable. | |
2168 */ | |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2169 *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
|
2170 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
|
2171 : 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
|
2172 if (eval3(arg, &var2, &nested_evalarg) == FAIL) |
7 | 2173 return FAIL; |
2174 | |
2175 /* | |
2176 * Compute the result. | |
2177 */ | |
2178 if (evaluate && !result) | |
2179 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2180 if (tv_get_number_chk(&var2, &error) != 0) |
7 | 2181 result = TRUE; |
71 | 2182 clear_tv(&var2); |
323 | 2183 if (error) |
2184 return FAIL; | |
7 | 2185 } |
2186 if (evaluate) | |
2187 { | |
71 | 2188 rettv->v_type = VAR_NUMBER; |
2189 rettv->vval.v_number = result; | |
7 | 2190 } |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2191 |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2192 p = eval_next_non_blank(*arg, evalarg, &getnext); |
7 | 2193 } |
2194 | |
2195 return OK; | |
2196 } | |
2197 | |
2198 /* | |
2199 * Handle second level expression: | |
2200 * expr3 && expr3 && expr3 logical AND | |
2201 * | |
2202 * "arg" must point to the first non-white of the expression. | |
2203 * "arg" is advanced to the next non-white after the recognized expression. | |
2204 * | |
2205 * Return OK or FAIL. | |
2206 */ | |
2207 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
|
2208 eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2209 { |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2210 char_u *p; |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2211 int getnext; |
137 | 2212 typval_T var2; |
7 | 2213 long result; |
2214 int first; | |
323 | 2215 int error = FALSE; |
7 | 2216 |
2217 /* | |
2218 * Get the first variable. | |
2219 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2220 if (eval4(arg, rettv, evalarg) == FAIL) |
7 | 2221 return FAIL; |
2222 | |
2223 /* | |
2224 * Repeat until there is no following "&&". | |
2225 */ | |
2226 first = TRUE; | |
2227 result = TRUE; | |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2228 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
|
2229 while (p[0] == '&' && p[1] == '&') |
7 | 2230 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2231 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
|
2232 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
|
2233 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
|
2234 |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2235 if (getnext) |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2236 *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
|
2237 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2238 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
|
2239 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2240 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
|
2241 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
|
2242 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
|
2243 } |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2244 else |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2245 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2246 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
|
2247 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
|
2248 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
|
2249 } |
7 | 2250 if (evaluate && first) |
2251 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2252 if (tv_get_number_chk(rettv, &error) == 0) |
7 | 2253 result = FALSE; |
71 | 2254 clear_tv(rettv); |
323 | 2255 if (error) |
2256 return FAIL; | |
7 | 2257 first = FALSE; |
2258 } | |
2259 | |
2260 /* | |
2261 * Get the second variable. | |
2262 */ | |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2263 *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
|
2264 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
|
2265 : 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
|
2266 if (eval4(arg, &var2, &nested_evalarg) == FAIL) |
7 | 2267 return FAIL; |
2268 | |
2269 /* | |
2270 * Compute the result. | |
2271 */ | |
2272 if (evaluate && result) | |
2273 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2274 if (tv_get_number_chk(&var2, &error) == 0) |
7 | 2275 result = FALSE; |
71 | 2276 clear_tv(&var2); |
323 | 2277 if (error) |
2278 return FAIL; | |
7 | 2279 } |
2280 if (evaluate) | |
2281 { | |
71 | 2282 rettv->v_type = VAR_NUMBER; |
2283 rettv->vval.v_number = result; | |
7 | 2284 } |
21024
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2285 |
02b03915855d
patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents:
21022
diff
changeset
|
2286 p = eval_next_non_blank(*arg, evalarg, &getnext); |
7 | 2287 } |
2288 | |
2289 return OK; | |
2290 } | |
2291 | |
2292 /* | |
2293 * Handle third level expression: | |
2294 * var1 == var2 | |
2295 * var1 =~ var2 | |
2296 * var1 != var2 | |
2297 * var1 !~ var2 | |
2298 * var1 > var2 | |
2299 * var1 >= var2 | |
2300 * var1 < var2 | |
2301 * var1 <= var2 | |
80 | 2302 * var1 is var2 |
2303 * var1 isnot var2 | |
7 | 2304 * |
2305 * "arg" must point to the first non-white of the expression. | |
2306 * "arg" is advanced to the next non-white after the recognized expression. | |
2307 * | |
2308 * Return OK or FAIL. | |
2309 */ | |
2310 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
|
2311 eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2312 { |
137 | 2313 typval_T var2; |
7 | 2314 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
|
2315 int getnext; |
7 | 2316 int i; |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2317 exptype_T type = EXPR_UNKNOWN; |
7 | 2318 int len = 2; |
2319 int ic; | |
2320 | |
2321 /* | |
2322 * Get the first variable. | |
2323 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2324 if (eval5(arg, rettv, evalarg) == FAIL) |
7 | 2325 return FAIL; |
2326 | |
21026
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2327 p = eval_next_non_blank(*arg, evalarg, &getnext); |
7 | 2328 switch (p[0]) |
2329 { | |
2330 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
|
2331 type = EXPR_EQUAL; |
7 | 2332 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
|
2333 type = EXPR_MATCH; |
7 | 2334 break; |
2335 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
|
2336 type = EXPR_NEQUAL; |
7 | 2337 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
|
2338 type = EXPR_NOMATCH; |
7 | 2339 break; |
2340 case '>': if (p[1] != '=') | |
2341 { | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2342 type = EXPR_GREATER; |
7 | 2343 len = 1; |
2344 } | |
2345 else | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2346 type = EXPR_GEQUAL; |
7 | 2347 break; |
2348 case '<': if (p[1] != '=') | |
2349 { | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2350 type = EXPR_SMALLER; |
7 | 2351 len = 1; |
2352 } | |
2353 else | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2354 type = EXPR_SEQUAL; |
7 | 2355 break; |
80 | 2356 case 'i': if (p[1] == 's') |
2357 { | |
2358 if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') | |
2359 len = 5; | |
7064
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2360 i = p[len]; |
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2361 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
|
2362 type = len == 2 ? EXPR_IS : EXPR_ISNOT; |
80 | 2363 } |
2364 break; | |
7 | 2365 } |
2366 | |
2367 /* | |
1624 | 2368 * If there is a comparative operator, use it. |
7 | 2369 */ |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2370 if (type != EXPR_UNKNOWN) |
7 | 2371 { |
21026
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2372 if (getnext) |
fe2ed85db946
patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents:
21024
diff
changeset
|
2373 *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
|
2374 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2375 // extra question mark appended: ignore case |
7 | 2376 if (p[len] == '?') |
2377 { | |
2378 ic = TRUE; | |
2379 ++len; | |
2380 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2381 // extra '#' appended: match case |
7 | 2382 else if (p[len] == '#') |
2383 { | |
2384 ic = FALSE; | |
2385 ++len; | |
2386 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2387 // nothing appended: use 'ignorecase' |
7 | 2388 else |
2389 ic = p_ic; | |
2390 | |
2391 /* | |
2392 * Get the second variable. | |
2393 */ | |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2394 *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
|
2395 if (eval5(arg, &var2, evalarg) == FAIL) |
7 | 2396 { |
71 | 2397 clear_tv(rettv); |
7 | 2398 return FAIL; |
2399 } | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2400 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
|
2401 { |
18966
6bd715870e32
patch 8.2.0044: expression type is used inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
18939
diff
changeset
|
2402 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
|
2403 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2404 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
|
2405 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
|
2406 } |
7 | 2407 } |
2408 | |
2409 return OK; | |
2410 } | |
2411 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2412 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2413 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
|
2414 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2415 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
|
2416 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
|
2417 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
|
2418 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2419 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2420 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
|
2421 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2422 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
|
2423 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
|
2424 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
|
2425 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
|
2426 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2427 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
|
2428 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
|
2429 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2430 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2431 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2432 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2433 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
|
2434 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2435 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
|
2436 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2437 // concatenate Lists |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2438 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
|
2439 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2440 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
|
2441 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
|
2442 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2443 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2444 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
|
2445 *tv1 = var3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2446 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2447 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2448 |
7 | 2449 /* |
2450 * Handle fourth level expression: | |
2451 * + number addition | |
2452 * - number subtraction | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2453 * . 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
|
2454 * .. string concatenation |
7 | 2455 * |
2456 * "arg" must point to the first non-white of the expression. | |
2457 * "arg" is advanced to the next non-white after the recognized expression. | |
2458 * | |
2459 * Return OK or FAIL. | |
2460 */ | |
2461 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
|
2462 eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg) |
7 | 2463 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2464 int evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE); |
7 | 2465 |
2466 /* | |
2467 * Get the first variable. | |
2468 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2469 if (eval6(arg, rettv, evalarg, FALSE) == FAIL) |
7 | 2470 return FAIL; |
2471 | |
2472 /* | |
2473 * Repeat computing, until no '+', '-' or '.' is following. | |
2474 */ | |
2475 for (;;) | |
2476 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2477 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
|
2478 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
|
2479 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
|
2480 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
|
2481 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
|
2482 |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2483 // "." 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
|
2484 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
|
2485 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
|
2486 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
|
2487 if (op != '+' && op != '-' && !concat) |
7 | 2488 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
|
2489 if (getnext) |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2490 *arg = eval_next_line(evalarg); |
7 | 2491 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2492 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
|
2493 && rettv->v_type != VAR_BLOB)) |
1624 | 2494 #ifdef FEAT_FLOAT |
2495 && (op == '.' || rettv->v_type != VAR_FLOAT) | |
2496 #endif | |
2497 ) | |
323 | 2498 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2499 // 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
|
2500 // 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
|
2501 // 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
|
2502 // 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
|
2503 // 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
|
2504 // 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
|
2505 // 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
|
2506 if (evaluate && tv_get_string_chk(rettv) == NULL) |
323 | 2507 { |
2508 clear_tv(rettv); | |
2509 return FAIL; | |
2510 } | |
2511 } | |
2512 | |
7 | 2513 /* |
2514 * Get the second variable. | |
2515 */ | |
16219
bd49e1656c72
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents:
16170
diff
changeset
|
2516 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
|
2517 ++*arg; |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2518 *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
|
2519 if (eval6(arg, &var2, evalarg, op == '.') == FAIL) |
7 | 2520 { |
71 | 2521 clear_tv(rettv); |
7 | 2522 return FAIL; |
2523 } | |
2524 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2525 if (evaluate) |
7 | 2526 { |
2527 /* | |
2528 * Compute the result. | |
2529 */ | |
2530 if (op == '.') | |
2531 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2532 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
|
2533 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
|
2534 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
|
2535 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2536 if (s2 == NULL) // type error ? |
323 | 2537 { |
2538 clear_tv(rettv); | |
2539 clear_tv(&var2); | |
2540 return FAIL; | |
2541 } | |
117 | 2542 p = concat_str(s1, s2); |
71 | 2543 clear_tv(rettv); |
2544 rettv->v_type = VAR_STRING; | |
2545 rettv->vval.v_string = p; | |
7 | 2546 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2547 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
|
2548 && 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
|
2549 eval_addblob(rettv, &var2); |
104 | 2550 else if (op == '+' && rettv->v_type == VAR_LIST |
2551 && var2.v_type == VAR_LIST) | |
80 | 2552 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2553 if (eval_addlist(rettv, &var2) == FAIL) |
80 | 2554 return FAIL; |
2555 } | |
7 | 2556 else |
2557 { | |
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 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
|
2559 varnumber_T n1, n2; |
1624 | 2560 #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
|
2561 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
|
2562 |
1624 | 2563 if (rettv->v_type == VAR_FLOAT) |
2564 { | |
2565 f1 = rettv->vval.v_float; | |
2566 n1 = 0; | |
2567 } | |
2568 else | |
2569 #endif | |
2570 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2571 n1 = tv_get_number_chk(rettv, &error); |
1624 | 2572 if (error) |
2573 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2574 // 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
|
2575 // "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
|
2576 // before evaluating the 2nd operand. |
1624 | 2577 clear_tv(rettv); |
2578 return FAIL; | |
2579 } | |
2580 #ifdef FEAT_FLOAT | |
2581 if (var2.v_type == VAR_FLOAT) | |
2582 f1 = n1; | |
2583 #endif | |
2584 } | |
2585 #ifdef FEAT_FLOAT | |
2586 if (var2.v_type == VAR_FLOAT) | |
2587 { | |
2588 f2 = var2.vval.v_float; | |
2589 n2 = 0; | |
2590 } | |
2591 else | |
2592 #endif | |
2593 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2594 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2595 if (error) |
2596 { | |
2597 clear_tv(rettv); | |
2598 clear_tv(&var2); | |
2599 return FAIL; | |
2600 } | |
2601 #ifdef FEAT_FLOAT | |
2602 if (rettv->v_type == VAR_FLOAT) | |
2603 f2 = n2; | |
2604 #endif | |
323 | 2605 } |
71 | 2606 clear_tv(rettv); |
1624 | 2607 |
2608 #ifdef FEAT_FLOAT | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2609 // If there is a float on either side the result is a float. |
1624 | 2610 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) |
2611 { | |
2612 if (op == '+') | |
2613 f1 = f1 + f2; | |
2614 else | |
2615 f1 = f1 - f2; | |
2616 rettv->v_type = VAR_FLOAT; | |
2617 rettv->vval.v_float = f1; | |
2618 } | |
2619 else | |
2620 #endif | |
2621 { | |
2622 if (op == '+') | |
2623 n1 = n1 + n2; | |
2624 else | |
2625 n1 = n1 - n2; | |
2626 rettv->v_type = VAR_NUMBER; | |
2627 rettv->vval.v_number = n1; | |
2628 } | |
71 | 2629 } |
2630 clear_tv(&var2); | |
7 | 2631 } |
2632 } | |
2633 return OK; | |
2634 } | |
2635 | |
2636 /* | |
2637 * Handle fifth level expression: | |
2638 * * number multiplication | |
2639 * / number division | |
2640 * % number modulo | |
2641 * | |
2642 * "arg" must point to the first non-white of the expression. | |
2643 * "arg" is advanced to the next non-white after the recognized expression. | |
2644 * | |
2645 * Return OK or FAIL. | |
2646 */ | |
2647 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2648 eval6( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2649 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2650 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
|
2651 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2652 int want_string) // after "." operator |
7 | 2653 { |
137 | 2654 typval_T var2; |
7 | 2655 int op; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2656 varnumber_T n1, n2; |
1624 | 2657 #ifdef FEAT_FLOAT |
2658 int use_float = FALSE; | |
16405
840fa633ad64
patch 8.1.1207: some compilers give warning messages
Bram Moolenaar <Bram@vim.org>
parents:
16366
diff
changeset
|
2659 float_T f1 = 0, f2 = 0; |
1624 | 2660 #endif |
323 | 2661 int error = FALSE; |
7 | 2662 |
2663 /* | |
2664 * Get the first variable. | |
2665 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2666 if (eval7(arg, rettv, evalarg, want_string) == FAIL) |
7 | 2667 return FAIL; |
2668 | |
2669 /* | |
2670 * Repeat computing, until no '*', '/' or '%' is following. | |
2671 */ | |
2672 for (;;) | |
2673 { | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2674 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
|
2675 : (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
|
2676 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
|
2677 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2678 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
|
2679 if (op != '*' && op != '/' && op != '%') |
7 | 2680 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
|
2681 if (getnext) |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
2682 *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
|
2683 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2684 if (evaluate) |
7 | 2685 { |
1624 | 2686 #ifdef FEAT_FLOAT |
2687 if (rettv->v_type == VAR_FLOAT) | |
2688 { | |
2689 f1 = rettv->vval.v_float; | |
2690 use_float = TRUE; | |
2691 n1 = 0; | |
2692 } | |
2693 else | |
2694 #endif | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2695 n1 = tv_get_number_chk(rettv, &error); |
71 | 2696 clear_tv(rettv); |
323 | 2697 if (error) |
2698 return FAIL; | |
7 | 2699 } |
2700 else | |
2701 n1 = 0; | |
2702 | |
2703 /* | |
2704 * Get the second variable. | |
2705 */ | |
2706 *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
|
2707 if (eval7(arg, &var2, evalarg, FALSE) == FAIL) |
7 | 2708 return FAIL; |
2709 | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2710 if (evaluate) |
7 | 2711 { |
1624 | 2712 #ifdef FEAT_FLOAT |
2713 if (var2.v_type == VAR_FLOAT) | |
2714 { | |
2715 if (!use_float) | |
2716 { | |
2717 f1 = n1; | |
2718 use_float = TRUE; | |
2719 } | |
2720 f2 = var2.vval.v_float; | |
2721 n2 = 0; | |
2722 } | |
2723 else | |
2724 #endif | |
2725 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2726 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2727 clear_tv(&var2); |
2728 if (error) | |
2729 return FAIL; | |
2730 #ifdef FEAT_FLOAT | |
2731 if (use_float) | |
2732 f2 = n2; | |
2733 #endif | |
2734 } | |
7 | 2735 |
2736 /* | |
2737 * Compute the result. | |
1624 | 2738 * When either side is a float the result is a float. |
7 | 2739 */ |
1624 | 2740 #ifdef FEAT_FLOAT |
2741 if (use_float) | |
2742 { | |
2743 if (op == '*') | |
2744 f1 = f1 * f2; | |
2745 else if (op == '/') | |
2746 { | |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2747 # ifdef VMS |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2748 // 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
|
2749 if (f2 == 0.0) |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2750 { |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2751 if (f1 == 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2752 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
|
2753 else if (f1 < 0) |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2754 f1 = -1 * __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2755 else |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2756 f1 = __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2757 } |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2758 else |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2759 f1 = f1 / f2; |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2760 # else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2761 // 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
|
2762 // by zero to result in "inf" and not a crash. |
1624 | 2763 f1 = f1 / f2; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2764 # endif |
1624 | 2765 } |
2766 else | |
2767 { | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2768 emsg(_(e_modulus)); |
1624 | 2769 return FAIL; |
2770 } | |
2771 rettv->v_type = VAR_FLOAT; | |
2772 rettv->vval.v_float = f1; | |
2773 } | |
2774 else | |
2775 #endif | |
2776 { | |
2777 if (op == '*') | |
2778 n1 = n1 * n2; | |
2779 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
|
2780 n1 = num_divide(n1, n2); |
1624 | 2781 else |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
2782 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
|
2783 |
1624 | 2784 rettv->v_type = VAR_NUMBER; |
2785 rettv->vval.v_number = n1; | |
2786 } | |
7 | 2787 } |
2788 } | |
2789 | |
2790 return OK; | |
2791 } | |
2792 | |
2793 /* | |
2794 * Handle sixth level expression: | |
2795 * number number constant | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2796 * 0zFFFFFFFF Blob constant |
1228 | 2797 * "string" string constant |
2798 * 'string' literal string constant | |
7 | 2799 * &option-name option value |
2800 * @r register contents | |
2801 * identifier variable value | |
2802 * function() function call | |
2803 * $VAR environment variable | |
2804 * (expression) nested expression | |
151 | 2805 * [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
|
2806 * {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
|
2807 * {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
|
2808 * #{key: val, key: val} Dictionary with literal keys |
7 | 2809 * |
2810 * Also handle: | |
2811 * ! in front logical NOT | |
2812 * - in front unary minus | |
2813 * + in front unary plus (ignored) | |
100 | 2814 * trailing [] subscript in String or List |
2815 * 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
|
2816 * trailing ->name() method call |
7 | 2817 * |
2818 * "arg" must point to the first non-white of the expression. | |
2819 * "arg" is advanced to the next non-white after the recognized expression. | |
2820 * | |
2821 * Return OK or FAIL. | |
2822 */ | |
2823 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2824 eval7( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2825 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2826 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
|
2827 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
|
2828 int want_string) // after "." operator |
7 | 2829 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2830 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
|
2831 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
|
2832 && (evalarg->eval_flags & EVAL_EVALUATE); |
7 | 2833 int len; |
2834 char_u *s; | |
2835 char_u *start_leader, *end_leader; | |
2836 int ret = OK; | |
2837 char_u *alias; | |
2838 | |
2839 /* | |
71 | 2840 * Initialise variable so that clear_tv() can't mistake this for a |
56 | 2841 * string and free a string that isn't there. |
7 | 2842 */ |
71 | 2843 rettv->v_type = VAR_UNKNOWN; |
7 | 2844 |
2845 /* | |
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10000
diff
changeset
|
2846 * Skip '!', '-' and '+' characters. They are handled later. |
7 | 2847 */ |
2848 start_leader = *arg; | |
2849 while (**arg == '!' || **arg == '-' || **arg == '+') | |
2850 *arg = skipwhite(*arg + 1); | |
2851 end_leader = *arg; | |
2852 | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2853 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
|
2854 #ifdef FEAT_FLOAT |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2855 || 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
|
2856 #endif |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2857 )) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2858 { |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2859 semsg(_(e_invexpr2), *arg); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2860 ++*arg; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2861 return FAIL; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2862 } |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2863 |
7 | 2864 switch (**arg) |
2865 { | |
2866 /* | |
2867 * Number constant. | |
2868 */ | |
2869 case '0': | |
2870 case '1': | |
2871 case '2': | |
2872 case '3': | |
2873 case '4': | |
2874 case '5': | |
2875 case '6': | |
2876 case '7': | |
2877 case '8': | |
2878 case '9': | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2879 case '.': ret = get_number_tv(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
|
2880 |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
2881 // 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
|
2882 // "->" follows. |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
2883 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
|
2884 ret = eval7_leader(rettv, TRUE, start_leader, &end_leader); |
1624 | 2885 break; |
7 | 2886 |
2887 /* | |
2888 * String constant: "string". | |
2889 */ | |
71 | 2890 case '"': ret = get_string_tv(arg, rettv, evaluate); |
7 | 2891 break; |
2892 | |
2893 /* | |
100 | 2894 * Literal string constant: 'str''ing'. |
7 | 2895 */ |
71 | 2896 case '\'': ret = get_lit_string_tv(arg, rettv, evaluate); |
56 | 2897 break; |
2898 | |
2899 /* | |
2900 * List: [expr, expr] | |
2901 */ | |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21026
diff
changeset
|
2902 case '[': ret = get_list_tv(arg, rettv, evalarg, TRUE); |
7 | 2903 break; |
2904 | |
2905 /* | |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2906 * 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
|
2907 */ |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2908 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
|
2909 { |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2910 ++*arg; |
21034
2f8b0812819f
patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
2911 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
|
2912 } |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2913 else |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2914 ret = NOTDONE; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2915 break; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2916 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2917 /* |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2918 * 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
|
2919 * Dictionary: {'key': val, 'key': val} |
100 | 2920 */ |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
2921 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
|
2922 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
|
2923 ret = eval_dict(arg, rettv, evalarg, FALSE); |
100 | 2924 break; |
2925 | |
2926 /* | |
104 | 2927 * Option value: &name |
7 | 2928 */ |
104 | 2929 case '&': ret = get_option_tv(arg, rettv, evaluate); |
7 | 2930 break; |
2931 | |
2932 /* | |
2933 * Environment variable: $VAR. | |
2934 */ | |
71 | 2935 case '$': ret = get_env_tv(arg, rettv, evaluate); |
7 | 2936 break; |
2937 | |
2938 /* | |
2939 * Register contents: @r. | |
2940 */ | |
2941 case '@': ++*arg; | |
2942 if (evaluate) | |
2943 { | |
71 | 2944 rettv->v_type = VAR_STRING; |
5796 | 2945 rettv->vval.v_string = get_reg_contents(**arg, |
2946 GREG_EXPR_SRC); | |
7 | 2947 } |
2948 if (**arg != NUL) | |
2949 ++*arg; | |
2950 break; | |
2951 | |
2952 /* | |
2953 * nested expression: (expression). | |
2954 */ | |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2955 case '(': { |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2956 *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
|
2957 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
|
2958 |
21046
0ca7e04d39e3
patch 8.2.1074: Vim9: no line break allowed after some operators
Bram Moolenaar <Bram@vim.org>
parents:
21044
diff
changeset
|
2959 *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
|
2960 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
|
2961 ++*arg; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2962 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
|
2963 { |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2964 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
|
2965 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
|
2966 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
|
2967 } |
7 | 2968 } |
2969 break; | |
2970 | |
100 | 2971 default: ret = NOTDONE; |
2972 break; | |
2973 } | |
2974 | |
2975 if (ret == NOTDONE) | |
2976 { | |
2977 /* | |
2978 * Must be a variable or function name. | |
2979 * Can also be a curly-braces kind of name: {expr}. | |
2980 */ | |
2981 s = *arg; | |
159 | 2982 len = get_name_len(arg, &alias, evaluate, TRUE); |
100 | 2983 if (alias != NULL) |
2984 s = alias; | |
2985 | |
159 | 2986 if (len <= 0) |
100 | 2987 ret = FAIL; |
2988 else | |
2989 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2990 if (**arg == '(') // recursive! |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
2991 ret = eval_func(arg, 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
|
2992 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
|
2993 ret = FAIL; |
100 | 2994 else if (evaluate) |
6791 | 2995 ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE); |
117 | 2996 else |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2997 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2998 check_vars(s, len); |
117 | 2999 ret = OK; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3000 } |
100 | 3001 } |
2690 | 3002 vim_free(alias); |
100 | 3003 } |
3004 | |
7 | 3005 *arg = skipwhite(*arg); |
3006 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3007 // 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
|
3008 // expr(expr), expr->name(expr) |
159 | 3009 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
|
3010 ret = handle_subscript(arg, rettv, evalarg, TRUE); |
7 | 3011 |
3012 /* | |
3013 * Apply logical NOT and unary '-', from right to left, ignore '+'. | |
3014 */ | |
3015 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
|
3016 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
|
3017 return ret; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3018 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3019 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3020 /* |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3021 * 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
|
3022 * 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
|
3023 * 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
|
3024 */ |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3025 static int |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3026 eval7_leader( |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3027 typval_T *rettv, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3028 int numeric_only, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3029 char_u *start_leader, |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3030 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
|
3031 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3032 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
|
3033 int ret = OK; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3034 int error = FALSE; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3035 varnumber_T val = 0; |
1624 | 3036 #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
|
3037 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
|
3038 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3039 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
|
3040 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
|
3041 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3042 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3043 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
|
3044 if (error) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3045 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3046 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3047 ret = FAIL; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3048 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3049 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3050 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3051 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
|
3052 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3053 --end_leader; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3054 if (*end_leader == '!') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3055 { |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3056 if (numeric_only) |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3057 { |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3058 ++end_leader; |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3059 break; |
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
3060 } |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3061 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3062 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
|
3063 f = !f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3064 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3065 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3066 val = !val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3067 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3068 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
|
3069 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3070 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3071 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
|
3072 f = -f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3073 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3074 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3075 val = -val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3076 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3077 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3078 #ifdef FEAT_FLOAT |
1624 | 3079 if (rettv->v_type == VAR_FLOAT) |
323 | 3080 { |
3081 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
|
3082 rettv->vval.v_float = f; |
323 | 3083 } |
3084 else | |
1624 | 3085 #endif |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3086 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3087 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3088 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
|
3089 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
|
3090 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3091 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
3092 *end_leaderp = end_leader; |
7 | 3093 return ret; |
3094 } | |
3095 | |
3096 /* | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3097 * 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
|
3098 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3099 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3100 call_func_rettv( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3101 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3102 typval_T *rettv, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3103 int evaluate, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3104 dict_T *selfdict, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3105 typval_T *basetv) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3106 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3107 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
|
3108 funcexe_T funcexe; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3109 typval_T functv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3110 char_u *s; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3111 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3112 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3113 // 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
|
3114 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3115 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3116 functv = *rettv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3117 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
|
3118 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3119 // 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
|
3120 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
|
3121 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3122 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
|
3123 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
|
3124 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3125 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3126 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
|
3127 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3128 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3129 s = (char_u *)""; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3130 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
3131 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
|
3132 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
|
3133 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
|
3134 funcexe.evaluate = evaluate; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3135 funcexe.partial = pt; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3136 funcexe.selfdict = selfdict; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3137 funcexe.basetv = basetv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3138 ret = get_func_tv(s, -1, rettv, arg, &funcexe); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3139 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3140 // 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
|
3141 // 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
|
3142 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3143 clear_tv(&functv); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3144 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3145 return ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3146 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3147 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3148 /* |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3149 * Evaluate "->method()". |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3150 * "*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
|
3151 * 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
|
3152 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3153 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3154 eval_lambda( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3155 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3156 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
|
3157 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3158 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
|
3159 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3160 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
|
3161 && (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
|
3162 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
|
3163 int ret; |
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 // Skip over the ->. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3166 *arg += 2; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3167 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
|
3168 |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3169 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
|
3170 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
|
3171 return FAIL; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3172 else if (**arg != '(') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3173 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3174 if (verbose) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3175 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3176 if (*skipwhite(*arg) == '(') |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
3177 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
|
3178 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3179 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
|
3180 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3181 clear_tv(rettv); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3182 ret = FAIL; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3183 } |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3184 else |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3185 ret = call_func_rettv(arg, rettv, evaluate, NULL, &base); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3186 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3187 // 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
|
3188 // 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
|
3189 if (evaluate) |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3190 clear_tv(&base); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3191 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
3192 return ret; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3193 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3194 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3195 /* |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3196 * Evaluate "->method()". |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3197 * "*arg" points to the '-'. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3198 * 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
|
3199 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3200 static int |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3201 eval_method( |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3202 char_u **arg, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3203 typval_T *rettv, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3204 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3205 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
|
3206 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3207 char_u *name; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3208 long len; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3209 char_u *alias; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3210 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
|
3211 int ret; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3212 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3213 // Skip over the ->. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3214 *arg += 2; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3215 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
|
3216 |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3217 name = *arg; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3218 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
|
3219 if (alias != NULL) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3220 name = alias; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3221 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3222 if (len <= 0) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3223 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3224 if (verbose) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3225 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
|
3226 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3227 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3228 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3229 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3230 if (**arg != '(') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3231 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3232 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
|
3233 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
|
3234 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3235 } |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3236 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
|
3237 { |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3238 if (verbose) |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
3239 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
|
3240 ret = FAIL; |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
3241 } |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3242 else |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
3243 ret = eval_func(arg, name, len, rettv, |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
3244 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
|
3245 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3246 |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
3247 // 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
|
3248 // 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
|
3249 if (evaluate) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3250 clear_tv(&base); |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3251 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3252 return ret; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3253 } |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3254 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3255 /* |
829 | 3256 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". |
3257 * "*arg" points to the '[' or '.'. | |
56 | 3258 * Returns FAIL or OK. "*arg" is advanced to after the ']'. |
3259 */ | |
3260 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3261 eval_index( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3262 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3263 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
|
3264 evalarg_T *evalarg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3265 int verbose) // give error messages |
56 | 3266 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
3267 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
|
3268 && (evalarg->eval_flags & EVAL_EVALUATE); |
56 | 3269 int empty1 = FALSE, empty2 = FALSE; |
137 | 3270 typval_T var1, var2; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3271 long i; |
56 | 3272 long n1, n2 = 0; |
100 | 3273 long len = -1; |
3274 int range = FALSE; | |
56 | 3275 char_u *s; |
100 | 3276 char_u *key = NULL; |
56 | 3277 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3278 switch (rettv->v_type) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3279 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3280 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
3281 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3282 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3283 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
|
3284 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3285 case VAR_FLOAT: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3286 #ifdef FEAT_FLOAT |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3287 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3288 emsg(_(e_float_as_string)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3289 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3290 #endif |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
3291 case VAR_BOOL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3292 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3293 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3294 case VAR_CHANNEL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3295 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3296 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
|
3297 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3298 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
|
3299 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
|
3300 case VAR_VOID: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3301 if (evaluate) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3302 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3303 // FALLTHROUGH |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3304 |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3305 case VAR_STRING: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3306 case VAR_NUMBER: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3307 case VAR_LIST: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3308 case VAR_DICT: |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3309 case VAR_BLOB: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3310 break; |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3311 } |
56 | 3312 |
7046
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3313 init_tv(&var1); |
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3314 init_tv(&var2); |
100 | 3315 if (**arg == '.') |
3316 { | |
3317 /* | |
3318 * dict.name | |
3319 */ | |
3320 key = *arg + 1; | |
3321 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
3322 ; | |
3323 if (len == 0) | |
3324 return FAIL; | |
3325 *arg = skipwhite(key + len); | |
3326 } | |
3327 else | |
3328 { | |
3329 /* | |
3330 * something[idx] | |
3331 * | |
3332 * Get the (first) variable from inside the []. | |
3333 */ | |
56 | 3334 *arg = skipwhite(*arg + 1); |
100 | 3335 if (**arg == ':') |
3336 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
|
3337 else if (eval1(arg, &var1, evalarg) == FAIL) // recursive! |
56 | 3338 return FAIL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3339 else if (evaluate && tv_get_string_chk(&var1) == NULL) |
323 | 3340 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3341 // not a number or string |
323 | 3342 clear_tv(&var1); |
3343 return FAIL; | |
3344 } | |
100 | 3345 |
3346 /* | |
3347 * Get the second variable from inside the [:]. | |
3348 */ | |
3349 if (**arg == ':') | |
3350 { | |
3351 range = TRUE; | |
3352 *arg = skipwhite(*arg + 1); | |
3353 if (**arg == ']') | |
3354 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
|
3355 else if (eval1(arg, &var2, evalarg) == FAIL) // recursive! |
100 | 3356 { |
323 | 3357 if (!empty1) |
3358 clear_tv(&var1); | |
3359 return FAIL; | |
3360 } | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3361 else if (evaluate && tv_get_string_chk(&var2) == NULL) |
323 | 3362 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3363 // not a number or string |
323 | 3364 if (!empty1) |
3365 clear_tv(&var1); | |
3366 clear_tv(&var2); | |
100 | 3367 return FAIL; |
3368 } | |
3369 } | |
3370 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3371 // Check for the ']'. |
100 | 3372 if (**arg != ']') |
3373 { | |
159 | 3374 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3375 emsg(_(e_missbrac)); |
100 | 3376 clear_tv(&var1); |
3377 if (range) | |
3378 clear_tv(&var2); | |
3379 return FAIL; | |
3380 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3381 *arg = skipwhite(*arg + 1); // skip the ']' |
56 | 3382 } |
3383 | |
3384 if (evaluate) | |
3385 { | |
100 | 3386 n1 = 0; |
3387 if (!empty1 && rettv->v_type != VAR_DICT) | |
56 | 3388 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3389 n1 = tv_get_number(&var1); |
71 | 3390 clear_tv(&var1); |
56 | 3391 } |
3392 if (range) | |
3393 { | |
3394 if (empty2) | |
3395 n2 = -1; | |
3396 else | |
3397 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3398 n2 = tv_get_number(&var2); |
71 | 3399 clear_tv(&var2); |
3400 } | |
3401 } | |
3402 | |
3403 switch (rettv->v_type) | |
56 | 3404 { |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3405 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
|
3406 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
|
3407 case VAR_VOID: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3408 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
3409 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3410 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
|
3411 case VAR_BOOL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3412 case VAR_SPECIAL: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3413 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3414 case VAR_CHANNEL: |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3415 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
|
3416 |
56 | 3417 case VAR_NUMBER: |
3418 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
|
3419 s = tv_get_string(rettv); |
56 | 3420 len = (long)STRLEN(s); |
3421 if (range) | |
3422 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3423 // 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
|
3424 // are out of range the result is empty. |
56 | 3425 if (n1 < 0) |
3426 { | |
3427 n1 = len + n1; | |
3428 if (n1 < 0) | |
3429 n1 = 0; | |
3430 } | |
3431 if (n2 < 0) | |
3432 n2 = len + n2; | |
3433 else if (n2 >= len) | |
3434 n2 = len; | |
3435 if (n1 >= len || n2 < 0 || n1 > n2) | |
3436 s = NULL; | |
3437 else | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
3438 s = vim_strnsave(s + n1, n2 - n1 + 1); |
56 | 3439 } |
3440 else | |
3441 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3442 // 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
|
3443 // 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
|
3444 // result is empty. |
56 | 3445 if (n1 >= len || n1 < 0) |
3446 s = NULL; | |
3447 else | |
3448 s = vim_strnsave(s + n1, 1); | |
3449 } | |
71 | 3450 clear_tv(rettv); |
3451 rettv->v_type = VAR_STRING; | |
3452 rettv->vval.v_string = s; | |
56 | 3453 break; |
3454 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3455 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3456 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
|
3457 if (range) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3458 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
3459 // 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
|
3460 // 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
|
3461 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3462 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3463 n1 = len + n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3464 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3465 n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3466 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3467 if (n2 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3468 n2 = len + n2; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3469 else if (n2 >= len) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3470 n2 = len - 1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3471 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
|
3472 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3473 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3474 rettv->v_type = VAR_BLOB; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3475 rettv->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3476 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3477 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3478 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3479 blob_T *blob = blob_alloc(); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3480 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3481 if (blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3482 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3483 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
|
3484 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3485 blob_free(blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3486 return FAIL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3487 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3488 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
|
3489 for (i = n1; i <= n2; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3490 blob_set(blob, i - n1, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3491 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
|
3492 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3493 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3494 rettv_blob_set(rettv, blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3495 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3496 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3497 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3498 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3499 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3500 // 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
|
3501 // 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
|
3502 if (n1 < 0) |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3503 n1 = len + n1; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3504 if (n1 < len && n1 >= 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3505 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3506 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
|
3507 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3508 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3509 rettv->v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3510 rettv->vval.v_number = v; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3511 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3512 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3513 semsg(_(e_blobidx), n1); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3514 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3515 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3516 |
56 | 3517 case VAR_LIST: |
71 | 3518 len = list_len(rettv->vval.v_list); |
56 | 3519 if (n1 < 0) |
3520 n1 = len + n1; | |
3521 if (!empty1 && (n1 < 0 || n1 >= len)) | |
3522 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3523 // 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
|
3524 // list. A list index out of range is an error. |
842 | 3525 if (!range) |
3526 { | |
3527 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3528 semsg(_(e_listidx), n1); |
842 | 3529 return FAIL; |
3530 } | |
3531 n1 = len; | |
56 | 3532 } |
3533 if (range) | |
3534 { | |
137 | 3535 list_T *l; |
56 | 3536 |
3537 if (n2 < 0) | |
3538 n2 = len + n2; | |
829 | 3539 else if (n2 >= len) |
3540 n2 = len - 1; | |
3541 if (!empty2 && (n2 < 0 || n2 + 1 < n1)) | |
842 | 3542 n2 = -1; |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
3543 l = list_slice(rettv->vval.v_list, n1, n2); |
56 | 3544 if (l == NULL) |
3545 return FAIL; | |
71 | 3546 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
|
3547 rettv_list_set(rettv, l); |
56 | 3548 } |
3549 else | |
3550 { | |
842 | 3551 copy_tv(&list_find(rettv->vval.v_list, n1)->li_tv, &var1); |
71 | 3552 clear_tv(rettv); |
3553 *rettv = var1; | |
56 | 3554 } |
3555 break; | |
100 | 3556 |
3557 case VAR_DICT: | |
3558 if (range) | |
3559 { | |
159 | 3560 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3561 emsg(_(e_dictrange)); |
100 | 3562 if (len == -1) |
3563 clear_tv(&var1); | |
3564 return FAIL; | |
3565 } | |
3566 { | |
137 | 3567 dictitem_T *item; |
100 | 3568 |
3569 if (len == -1) | |
3570 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3571 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
|
3572 if (key == NULL) |
100 | 3573 { |
3574 clear_tv(&var1); | |
3575 return FAIL; | |
3576 } | |
3577 } | |
3578 | |
121 | 3579 item = dict_find(rettv->vval.v_dict, key, (int)len); |
100 | 3580 |
159 | 3581 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
|
3582 semsg(_(e_dictkey), key); |
100 | 3583 if (len == -1) |
3584 clear_tv(&var1); | |
3585 if (item == NULL) | |
3586 return FAIL; | |
3587 | |
3588 copy_tv(&item->di_tv, &var1); | |
3589 clear_tv(rettv); | |
3590 *rettv = var1; | |
3591 } | |
3592 break; | |
3593 } | |
3594 } | |
3595 | |
56 | 3596 return OK; |
3597 } | |
3598 | |
3599 /* | |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3600 * 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
|
3601 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3602 char_u * |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3603 partial_name(partial_T *pt) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3604 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3605 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3606 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
|
3607 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
|
3608 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
|
3609 return (char_u *)""; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3610 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3611 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3612 static void |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3613 partial_free(partial_T *pt) |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3614 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3615 int i; |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3616 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3617 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
|
3618 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
|
3619 vim_free(pt->pt_argv); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3620 dict_unref(pt->pt_dict); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3621 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3622 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3623 func_unref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3624 vim_free(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3625 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3626 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3627 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
|
3628 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3629 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
|
3630 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3631 // 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
|
3632 // 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
|
3633 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
|
3634 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3635 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
|
3636 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
|
3637 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3638 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
|
3639 clear_tv(stack + i); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3640 ga_clear(gap); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3641 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
|
3642 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3643 pt->pt_funcstack = NULL; |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3644 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3645 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3646 vim_free(pt); |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3647 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3648 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3649 /* |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3650 * 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
|
3651 * becomes zero. |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3652 */ |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3653 void |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3654 partial_unref(partial_T *pt) |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3655 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3656 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
|
3657 partial_free(pt); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3658 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3659 |
80 | 3660 /* |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3661 * Return the next (unique) copy ID. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3662 * Used for serializing nested structures. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3663 */ |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3664 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3665 get_copyID(void) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3666 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3667 current_copyID += COPYID_INC; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3668 return current_copyID; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3669 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3670 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3671 /* |
371 | 3672 * Garbage collection for lists and dictionaries. |
3673 * | |
3674 * We use reference counts to be able to free most items right away when they | |
3675 * are no longer used. But for composite items it's possible that it becomes | |
3676 * unused while the reference count is > 0: When there is a recursive | |
3677 * reference. Example: | |
3678 * :let l = [1, 2, 3] | |
3679 * :let d = {9: l} | |
3680 * :let l[1] = d | |
3681 * | |
3682 * Since this is quite unusual we handle this with garbage collection: every | |
3683 * once in a while find out which lists and dicts are not referenced from any | |
3684 * variable. | |
3685 * | |
3686 * Here is a good reference text about garbage collection (refers to Python | |
3687 * but it applies to all reference-counting mechanisms): | |
3688 * http://python.ca/nas/python/gc/ | |
3689 */ | |
3690 | |
3691 /* | |
3692 * 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
|
3693 * When "testing" is TRUE this is called from test_garbagecollect_now(). |
371 | 3694 * Return TRUE if some memory was freed. |
3695 */ | |
3696 int | |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3697 garbage_collect(int testing) |
371 | 3698 { |
1891 | 3699 int copyID; |
6565 | 3700 int abort = FALSE; |
371 | 3701 buf_T *buf; |
3702 win_T *wp; | |
6588 | 3703 int did_free = FALSE; |
819 | 3704 tabpage_T *tp; |
371 | 3705 |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3706 if (!testing) |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3707 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3708 // Only do this once. |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3709 want_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3710 may_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3711 garbage_collect_at_exit = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3712 } |
958 | 3713 |
19001
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3714 // 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
|
3715 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
|
3716 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3717 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
|
3718 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
|
3719 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
|
3720 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3721 // 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
|
3722 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
|
3723 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
|
3724 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
|
3725 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3726 // 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
|
3727 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
|
3728 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3729 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
|
3730 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
|
3731 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
|
3732 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
|
3733 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
|
3734 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
|
3735 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3736 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3737 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3738 // 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
|
3739 // previous_funccal. |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3740 copyID = get_copyID(); |
1891 | 3741 |
371 | 3742 /* |
3743 * 1. Go through all accessible variables and mark all lists and dicts | |
3744 * with copyID. | |
3745 */ | |
1891 | 3746 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3747 // 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
|
3748 // 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
|
3749 // 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
|
3750 abort = abort || set_ref_in_previous_funccal(copyID); |
1891 | 3751 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3752 // 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
|
3753 abort = abort || garbage_collect_scriptvars(copyID); |
371 | 3754 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3755 // buffer-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3756 FOR_ALL_BUFFERS(buf) |
6565 | 3757 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID, |
3758 NULL, NULL); | |
371 | 3759 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3760 // window-local variables |
819 | 3761 FOR_ALL_TAB_WINDOWS(tp, wp) |
6565 | 3762 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, |
3763 NULL, NULL); | |
4309 | 3764 if (aucmd_win != NULL) |
6565 | 3765 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID, |
3766 NULL, NULL); | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
3767 #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
|
3768 FOR_ALL_POPUPWINS(wp) |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3769 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
|
3770 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3771 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
|
3772 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
|
3773 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
|
3774 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3775 #endif |
371 | 3776 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3777 // tabpage-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3778 FOR_ALL_TABPAGES(tp) |
6565 | 3779 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, |
3780 NULL, NULL); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3781 // 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
|
3782 abort = abort || garbage_collect_globvars(copyID); |
371 | 3783 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3784 // function-local variables |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3785 abort = abort || set_ref_in_call_stack(copyID); |
371 | 3786 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3787 // named functions (matters for closures) |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
3788 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
|
3789 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3790 // 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
|
3791 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
|
3792 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3793 // 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
|
3794 abort = abort || garbage_collect_vimvars(copyID); |
1733 | 3795 |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3796 // callbacks in buffers |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3797 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
|
3798 |
3450 | 3799 #ifdef FEAT_LUA |
6565 | 3800 abort = abort || set_ref_in_lua(copyID); |
3450 | 3801 #endif |
3802 | |
3618 | 3803 #ifdef FEAT_PYTHON |
6565 | 3804 abort = abort || set_ref_in_python(copyID); |
3618 | 3805 #endif |
3806 | |
3807 #ifdef FEAT_PYTHON3 | |
6565 | 3808 abort = abort || set_ref_in_python3(copyID); |
3809 #endif | |
3810 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3811 #ifdef FEAT_JOB_CHANNEL |
8877
50e40f322e78
commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents:
8870
diff
changeset
|
3812 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
|
3813 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
|
3814 #endif |
9052
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
3815 #ifdef FEAT_NETBEANS_INTG |
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
3816 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
|
3817 #endif |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7895
diff
changeset
|
3818 |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3819 #ifdef FEAT_TIMERS |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3820 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
|
3821 #endif |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3822 |
11412
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3823 #ifdef FEAT_QUICKFIX |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3824 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
|
3825 #endif |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3826 |
11804
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3827 #ifdef FEAT_TERMINAL |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3828 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
|
3829 #endif |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3830 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
3831 #ifdef FEAT_PROP_POPUP |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3832 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
|
3833 #endif |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3834 |
6565 | 3835 if (!abort) |
3836 { | |
3837 /* | |
3838 * 2. Free lists and dictionaries that are not referenced. | |
3839 */ | |
3840 did_free = free_unref_items(copyID); | |
3841 | |
3842 /* | |
3843 * 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
|
3844 * This may call us back recursively. |
6565 | 3845 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3846 free_unref_funccal(copyID, testing); |
6565 | 3847 } |
3848 else if (p_verbose > 0) | |
3849 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3850 verb_msg(_("Not enough memory to set references, garbage collection aborted!")); |
6565 | 3851 } |
1891 | 3852 |
3853 return did_free; | |
3854 } | |
3855 | |
3856 /* | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3857 * Free lists, dictionaries, channels and jobs that are no longer referenced. |
1891 | 3858 */ |
3859 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3860 free_unref_items(int copyID) |
1891 | 3861 { |
3862 int did_free = FALSE; | |
3863 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3864 // 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
|
3865 // 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
|
3866 // do that here. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3867 in_free_unref_items = TRUE; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3868 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3869 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3870 * 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
|
3871 * 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
|
3872 */ |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3873 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3874 // 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
|
3875 did_free |= dict_free_nonref(copyID); |
371 | 3876 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3877 // 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
|
3878 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
|
3879 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3880 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3881 // 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
|
3882 // 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
|
3883 // 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
|
3884 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
|
3885 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3886 // 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
|
3887 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
|
3888 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3889 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3890 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3891 * PASS 2: free the items themselves. |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3892 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
3893 dict_free_items(copyID); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
9556
diff
changeset
|
3894 list_free_items(copyID); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3895 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3896 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3897 // 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
|
3898 // 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
|
3899 // 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
|
3900 free_unused_jobs(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3901 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3902 // 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
|
3903 free_unused_channels(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3904 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3905 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3906 in_free_unref_items = FALSE; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3907 |
371 | 3908 return did_free; |
3909 } | |
3910 | |
3911 /* | |
3912 * Mark all lists and dicts referenced through hashtab "ht" with "copyID". | |
6565 | 3913 * "list_stack" is used to add lists to be marked. Can be NULL. |
3914 * | |
3915 * Returns TRUE if setting references failed somehow. | |
3916 */ | |
3917 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3918 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack) |
364 | 3919 { |
3920 int todo; | |
6565 | 3921 int abort = FALSE; |
364 | 3922 hashitem_T *hi; |
6565 | 3923 hashtab_T *cur_ht; |
3924 ht_stack_T *ht_stack = NULL; | |
3925 ht_stack_T *tempitem; | |
3926 | |
3927 cur_ht = ht; | |
3928 for (;;) | |
3929 { | |
3930 if (!abort) | |
3931 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3932 // 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
|
3933 // 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
|
3934 // list_stack. |
6565 | 3935 todo = (int)cur_ht->ht_used; |
3936 for (hi = cur_ht->ht_array; todo > 0; ++hi) | |
3937 if (!HASHITEM_EMPTY(hi)) | |
3938 { | |
3939 --todo; | |
3940 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID, | |
3941 &ht_stack, list_stack); | |
3942 } | |
3943 } | |
3944 | |
3945 if (ht_stack == NULL) | |
3946 break; | |
3947 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3948 // take an item from the stack |
6565 | 3949 cur_ht = ht_stack->ht; |
3950 tempitem = ht_stack; | |
3951 ht_stack = ht_stack->prev; | |
3952 free(tempitem); | |
3953 } | |
3954 | |
3955 return abort; | |
371 | 3956 } |
3957 | |
3958 /* | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3959 * 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
|
3960 * 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
|
3961 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3962 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3963 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
|
3964 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3965 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
|
3966 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3967 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
|
3968 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
|
3969 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3970 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
|
3971 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3972 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3973 /* |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3974 * 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
|
3975 * 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
|
3976 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3977 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3978 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
|
3979 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3980 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
|
3981 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3982 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
|
3983 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
|
3984 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3985 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
|
3986 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3987 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3988 /* |
371 | 3989 * Mark all lists and dicts referenced through list "l" with "copyID". |
6565 | 3990 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. |
3991 * | |
3992 * Returns TRUE if setting references failed somehow. | |
3993 */ | |
3994 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
|
3995 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack) |
6565 | 3996 { |
3997 listitem_T *li; | |
3998 int abort = FALSE; | |
3999 list_T *cur_l; | |
4000 list_stack_T *list_stack = NULL; | |
4001 list_stack_T *tempitem; | |
4002 | |
4003 cur_l = l; | |
4004 for (;;) | |
4005 { | |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
4006 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
|
4007 // 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
|
4008 // 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
|
4009 // list_stack. |
6565 | 4010 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next) |
4011 abort = abort || set_ref_in_item(&li->li_tv, copyID, | |
4012 ht_stack, &list_stack); | |
4013 if (list_stack == NULL) | |
4014 break; | |
4015 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4016 // take an item from the stack |
6565 | 4017 cur_l = list_stack->list; |
4018 tempitem = list_stack; | |
4019 list_stack = list_stack->prev; | |
4020 free(tempitem); | |
4021 } | |
4022 | |
4023 return abort; | |
371 | 4024 } |
4025 | |
4026 /* | |
4027 * Mark all lists and dicts referenced through typval "tv" with "copyID". | |
6565 | 4028 * "list_stack" is used to add lists to be marked. Can be NULL. |
4029 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. | |
4030 * | |
4031 * Returns TRUE if setting references failed somehow. | |
4032 */ | |
4033 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4034 set_ref_in_item( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4035 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4036 int copyID, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4037 ht_stack_T **ht_stack, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4038 list_stack_T **list_stack) |
364 | 4039 { |
6565 | 4040 int abort = FALSE; |
364 | 4041 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4042 if (tv->v_type == VAR_DICT) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4043 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4044 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
|
4045 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4046 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
|
4047 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4048 // 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
|
4049 dd->dv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4050 if (ht_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4051 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4052 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
|
4053 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4054 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4055 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4056 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
|
4057 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4058 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4059 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4060 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4061 newitem->ht = &dd->dv_hashtab; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4062 newitem->prev = *ht_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4063 *ht_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4064 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4065 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4066 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4067 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4068 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
|
4069 { |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4070 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
|
4071 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4072 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
|
4073 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4074 // 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
|
4075 ll->lv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4076 if (list_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4077 { |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4078 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
|
4079 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4080 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4081 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4082 list_stack_T *newitem = (list_stack_T*)malloc( |
6565 | 4083 sizeof(list_stack_T)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4084 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4085 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4086 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4087 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4088 newitem->list = ll; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4089 newitem->prev = *list_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4090 *list_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4091 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4092 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4093 } |
6565 | 4094 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4095 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
|
4096 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4097 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
|
4098 } |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4099 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
|
4100 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4101 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
|
4102 int i; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4103 |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4104 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
|
4105 { |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4106 // 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
|
4107 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
|
4108 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4109 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
|
4110 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4111 if (pt->pt_dict != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4112 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4113 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4114 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4115 dtv.v_type = VAR_DICT; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4116 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
|
4117 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
|
4118 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4119 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4120 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
|
4121 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
|
4122 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
|
4123 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
|
4124 { |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4125 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
|
4126 |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4127 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
|
4128 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
|
4129 ht_stack, list_stack); |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4130 } |
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
4131 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4132 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4133 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4134 #ifdef FEAT_JOB_CHANNEL |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4135 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
|
4136 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4137 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
|
4138 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4139 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4140 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
|
4141 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4142 job->jv_copyID = copyID; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4143 if (job->jv_channel != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4144 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4145 dtv.v_type = VAR_CHANNEL; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4146 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
|
4147 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
|
4148 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4149 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
|
4150 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4151 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
|
4152 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
|
4153 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
|
4154 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4155 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4156 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4157 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
|
4158 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4159 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
|
4160 ch_part_T part; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4161 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4162 jsonq_T *jq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4163 cbq_T *cq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4164 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4165 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
|
4166 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4167 ch->ch_copyID = copyID; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10235
diff
changeset
|
4168 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
|
4169 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4170 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
|
4171 jq = jq->jq_next) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4172 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
|
4173 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
|
4174 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
|
4175 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
|
4176 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4177 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
|
4178 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
|
4179 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
|
4180 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4181 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
|
4182 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4183 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
|
4184 dtv.vval.v_partial = |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4185 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
|
4186 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
|
4187 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4188 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4189 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
|
4190 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4191 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
|
4192 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
|
4193 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
|
4194 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4195 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
|
4196 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4197 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
|
4198 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
|
4199 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
|
4200 } |
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 #endif |
6565 | 4204 return abort; |
364 | 4205 } |
4206 | |
100 | 4207 /* |
56 | 4208 * Return a string with the string representation of a variable. |
4209 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
80 | 4210 * "numbuf" is used for a number. |
634 | 4211 * 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
|
4212 * 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
|
4213 * 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
|
4214 * ":echo" displays values. |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4215 * 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
|
4216 * are replaced with "...". |
1360 | 4217 * May return NULL. |
56 | 4218 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4219 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4220 echo_string_core( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4221 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4222 char_u **tofree, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4223 char_u *numbuf, |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4224 int copyID, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4225 int echo_style, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4226 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
|
4227 int composite_val) |
56 | 4228 { |
104 | 4229 static int recurse = 0; |
4230 char_u *r = NULL; | |
4231 | |
137 | 4232 if (recurse >= DICT_MAXNEST) |
104 | 4233 { |
5973 | 4234 if (!did_echo_string_emsg) |
4235 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4236 // 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
|
4237 // 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
|
4238 // and dicts. |
5973 | 4239 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
|
4240 emsg(_("E724: variable nested too deep for displaying")); |
5973 | 4241 } |
104 | 4242 *tofree = NULL; |
5973 | 4243 return (char_u *)"{E724}"; |
104 | 4244 } |
4245 ++recurse; | |
4246 | |
56 | 4247 switch (tv->v_type) |
4248 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4249 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
|
4250 if (echo_style && !composite_val) |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4251 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4252 *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
|
4253 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
|
4254 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
|
4255 r = (char_u *)""; |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4256 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4257 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4258 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4259 *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
|
4260 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4261 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4262 break; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4263 |
56 | 4264 case VAR_FUNC: |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4265 if (echo_style) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4266 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4267 *tofree = NULL; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4268 r = tv->vval.v_string; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4269 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4270 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4271 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4272 *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
|
4273 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4274 } |
104 | 4275 break; |
634 | 4276 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4277 case VAR_PARTIAL: |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4278 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4279 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
|
4280 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
|
4281 : partial_name(pt), FALSE); |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4282 garray_T ga; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4283 int i; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4284 char_u *tf; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4285 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4286 ga_init2(&ga, 1, 100); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4287 ga_concat(&ga, (char_u *)"function("); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4288 if (fname != NULL) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4289 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4290 ga_concat(&ga, fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4291 vim_free(fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4292 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4293 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
|
4294 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4295 ga_concat(&ga, (char_u *)", ["); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4296 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
|
4297 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4298 if (i > 0) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4299 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4300 ga_concat(&ga, |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4301 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
|
4302 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4303 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4304 ga_concat(&ga, (char_u *)"]"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4305 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4306 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
|
4307 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4308 typval_T dtv; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4309 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4310 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4311 dtv.v_type = VAR_DICT; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4312 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
|
4313 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
|
4314 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4315 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4316 ga_concat(&ga, (char_u *)")"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4317 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4318 *tofree = ga.ga_data; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4319 r = *tofree; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4320 break; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4321 } |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4322 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4323 case VAR_BLOB: |
15466
435fcefd2c8e
patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15464
diff
changeset
|
4324 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
|
4325 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4326 |
56 | 4327 case VAR_LIST: |
634 | 4328 if (tv->vval.v_list == NULL) |
4329 { | |
20126
831b1ea43020
patch 8.2.0618: echoing a null list results in no output
Bram Moolenaar <Bram@vim.org>
parents:
20111
diff
changeset
|
4330 // NULL list is equivalent to empty list. |
634 | 4331 *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
|
4332 r = (char_u *)"[]"; |
634 | 4333 } |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4334 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
|
4335 && tv->vval.v_list->lv_len > 0) |
634 | 4336 { |
4337 *tofree = NULL; | |
4338 r = (char_u *)"[...]"; | |
4339 } | |
4340 else | |
4341 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4342 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
|
4343 |
634 | 4344 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
|
4345 *tofree = list2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4346 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4347 tv->vval.v_list->lv_copyID = old_copyID; |
634 | 4348 r = *tofree; |
4349 } | |
4350 break; | |
4351 | |
100 | 4352 case VAR_DICT: |
634 | 4353 if (tv->vval.v_dict == NULL) |
4354 { | |
20128
0b35a7ffceb2
patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents:
20126
diff
changeset
|
4355 // NULL dict is equivalent to empty dict. |
634 | 4356 *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
|
4357 r = (char_u *)"{}"; |
634 | 4358 } |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4359 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
|
4360 && tv->vval.v_dict->dv_hashtab.ht_used != 0) |
634 | 4361 { |
4362 *tofree = NULL; | |
4363 r = (char_u *)"{...}"; | |
4364 } | |
4365 else | |
4366 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4367 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
|
4368 |
634 | 4369 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
|
4370 *tofree = dict2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4371 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4372 tv->vval.v_dict->dv_copyID = old_copyID; |
634 | 4373 r = *tofree; |
4374 } | |
4375 break; | |
4376 | |
71 | 4377 case VAR_NUMBER: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4378 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
|
4379 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
|
4380 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
|
4381 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4382 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
|
4383 break; |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4384 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4385 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
4386 case VAR_CHANNEL: |
104 | 4387 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4388 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
|
4389 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
|
4390 { |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4391 *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
|
4392 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
|
4393 } |
71 | 4394 break; |
634 | 4395 |
1624 | 4396 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4397 #ifdef FEAT_FLOAT |
1624 | 4398 *tofree = NULL; |
4399 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float); | |
4400 r = numbuf; | |
4401 break; | |
4402 #endif | |
4403 | |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
4404 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4405 case VAR_SPECIAL: |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4406 *tofree = NULL; |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
4407 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
|
4408 break; |
104 | 4409 } |
4410 | |
5973 | 4411 if (--recurse == 0) |
4412 did_echo_string_emsg = FALSE; | |
104 | 4413 return r; |
97 | 4414 } |
4415 | |
4416 /* | |
4417 * Return a string with the string representation of a variable. | |
4418 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
4419 * "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
|
4420 * 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
|
4421 * 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
|
4422 * May return NULL. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4423 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4424 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4425 echo_string( |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4426 typval_T *tv, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4427 char_u **tofree, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4428 char_u *numbuf, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4429 int copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4430 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4431 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
|
4432 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4433 |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4434 /* |
137 | 4435 * Return string "str" in ' quotes, doubling ' characters. |
4436 * If "str" is NULL an empty string is assumed. | |
100 | 4437 * If "function" is TRUE make it function('string'). |
97 | 4438 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4439 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4440 string_quote(char_u *str, int function) |
97 | 4441 { |
137 | 4442 unsigned len; |
97 | 4443 char_u *p, *r, *s; |
4444 | |
137 | 4445 len = (function ? 13 : 3); |
4446 if (str != NULL) | |
4447 { | |
835 | 4448 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
|
4449 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
137 | 4450 if (*p == '\'') |
4451 ++len; | |
4452 } | |
97 | 4453 s = r = alloc(len); |
4454 if (r != NULL) | |
4455 { | |
4456 if (function) | |
4457 { | |
100 | 4458 STRCPY(r, "function('"); |
97 | 4459 r += 10; |
4460 } | |
4461 else | |
100 | 4462 *r++ = '\''; |
137 | 4463 if (str != NULL) |
4464 for (p = str; *p != NUL; ) | |
4465 { | |
4466 if (*p == '\'') | |
4467 *r++ = '\''; | |
4468 MB_COPY_CHAR(p, r); | |
4469 } | |
100 | 4470 *r++ = '\''; |
97 | 4471 if (function) |
4472 *r++ = ')'; | |
4473 *r++ = NUL; | |
4474 } | |
4475 return s; | |
4476 } | |
4477 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4478 #if defined(FEAT_FLOAT) || defined(PROTO) |
1624 | 4479 /* |
4480 * Convert the string "text" to a floating point number. | |
4481 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure | |
4482 * this always uses a decimal point. | |
4483 * Returns the length of the text that was consumed. | |
4484 */ | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4485 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4486 string2float( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4487 char_u *text, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4488 float_T *value) // result stored here |
1624 | 4489 { |
4490 char *s = (char *)text; | |
4491 float_T f; | |
4492 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4493 // 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
|
4494 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
|
4495 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4496 *value = INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4497 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4498 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4499 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
|
4500 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4501 *value = -INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4502 return 4; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4503 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4504 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
|
4505 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4506 *value = NAN; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4507 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4508 } |
1624 | 4509 f = strtod(s, &s); |
4510 *value = f; | |
4511 return (int)((char_u *)s - text); | |
4512 } | |
4513 #endif | |
4514 | |
97 | 4515 /* |
7 | 4516 * Translate a String variable into a position. |
685 | 4517 * Returns NULL when there is an error. |
7 | 4518 */ |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4519 pos_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4520 var2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4521 typval_T *varp, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4522 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
|
4523 int *fnum) // set to fnum for '0, 'A, etc. |
7 | 4524 { |
700 | 4525 char_u *name; |
7 | 4526 static pos_T pos; |
700 | 4527 pos_T *pp; |
7 | 4528 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4529 // Argument can be [lnum, col, coladd]. |
685 | 4530 if (varp->v_type == VAR_LIST) |
4531 { | |
4532 list_T *l; | |
4533 int len; | |
705 | 4534 int error = FALSE; |
1317 | 4535 listitem_T *li; |
685 | 4536 |
4537 l = varp->vval.v_list; | |
4538 if (l == NULL) | |
4539 return NULL; | |
4540 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4541 // Get the line number |
705 | 4542 pos.lnum = list_find_nr(l, 0L, &error); |
4543 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
|
4544 return NULL; // invalid line number |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4545 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4546 // Get the column number |
705 | 4547 pos.col = list_find_nr(l, 1L, &error); |
4548 if (error) | |
685 | 4549 return NULL; |
4550 len = (long)STRLEN(ml_get(pos.lnum)); | |
1317 | 4551 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4552 // We accept "$" for the column number: last column. |
1317 | 4553 li = list_find(l, 1L); |
4554 if (li != NULL && li->li_tv.v_type == VAR_STRING | |
4555 && li->li_tv.vval.v_string != NULL | |
4556 && STRCMP(li->li_tv.vval.v_string, "$") == 0) | |
4557 pos.col = len + 1; | |
4558 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4559 // Accept a position up to the NUL after the line. |
826 | 4560 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
|
4561 return NULL; // invalid column number |
705 | 4562 --pos.col; |
4563 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4564 // Get the virtual offset. Defaults to zero. |
705 | 4565 pos.coladd = list_find_nr(l, 2L, &error); |
4566 if (error) | |
4567 pos.coladd = 0; | |
4568 | |
685 | 4569 return &pos; |
4570 } | |
4571 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4572 name = tv_get_string_chk(varp); |
323 | 4573 if (name == NULL) |
4574 return NULL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4575 if (name[0] == '.') // cursor |
7 | 4576 return &curwin->w_cursor; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4577 if (name[0] == 'v' && name[1] == NUL) // Visual start |
1609 | 4578 { |
4579 if (VIsual_active) | |
4580 return &VIsual; | |
4581 return &curwin->w_cursor; | |
4582 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4583 if (name[0] == '\'') // mark |
7 | 4584 { |
4043 | 4585 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); |
7 | 4586 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) |
4587 return NULL; | |
4588 return pp; | |
4589 } | |
705 | 4590 |
4591 pos.coladd = 0; | |
4592 | |
1317 | 4593 if (name[0] == 'w' && dollar_lnum) |
666 | 4594 { |
4595 pos.col = 0; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4596 if (name[1] == '0') // "w0": first visible line |
666 | 4597 { |
671 | 4598 update_topline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4599 // 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
|
4600 // 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
|
4601 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; |
666 | 4602 return &pos; |
4603 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4604 else if (name[1] == '$') // "w$": last visible line |
666 | 4605 { |
671 | 4606 validate_botline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4607 // 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
|
4608 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; |
666 | 4609 return &pos; |
4610 } | |
4611 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4612 else if (name[0] == '$') // last column or line |
7 | 4613 { |
1317 | 4614 if (dollar_lnum) |
7 | 4615 { |
4616 pos.lnum = curbuf->b_ml.ml_line_count; | |
4617 pos.col = 0; | |
4618 } | |
4619 else | |
4620 { | |
4621 pos.lnum = curwin->w_cursor.lnum; | |
4622 pos.col = (colnr_T)STRLEN(ml_get_curline()); | |
4623 } | |
4624 return &pos; | |
4625 } | |
4626 return NULL; | |
4627 } | |
4628 | |
4629 /* | |
709 | 4630 * Convert list in "arg" into a position and optional file number. |
4631 * When "fnump" is NULL there is no file number, only 3 items. | |
4632 * Note that the column is passed on as-is, the caller may want to decrement | |
4633 * it to use 1 for the first column. | |
4634 * Return FAIL when conversion is not possible, doesn't check the position for | |
4635 * validity. | |
4636 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4637 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4638 list2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4639 typval_T *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4640 pos_T *posp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4641 int *fnump, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4642 colnr_T *curswantp) |
709 | 4643 { |
4644 list_T *l = arg->vval.v_list; | |
4645 long i = 0; | |
4646 long n; | |
4647 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4648 // 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
|
4649 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional. |
915 | 4650 if (arg->v_type != VAR_LIST |
4651 || l == NULL | |
4652 || l->lv_len < (fnump == NULL ? 2 : 3) | |
5938 | 4653 || l->lv_len > (fnump == NULL ? 4 : 5)) |
709 | 4654 return FAIL; |
4655 | |
4656 if (fnump != NULL) | |
4657 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4658 n = list_find_nr(l, i++, NULL); // fnum |
709 | 4659 if (n < 0) |
4660 return FAIL; | |
4661 if (n == 0) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4662 n = curbuf->b_fnum; // current buffer |
709 | 4663 *fnump = n; |
4664 } | |
4665 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4666 n = list_find_nr(l, i++, NULL); // lnum |
709 | 4667 if (n < 0) |
4668 return FAIL; | |
4669 posp->lnum = n; | |
4670 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4671 n = list_find_nr(l, i++, NULL); // col |
709 | 4672 if (n < 0) |
4673 return FAIL; | |
4674 posp->col = n; | |
4675 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4676 n = list_find_nr(l, i, NULL); // off |
709 | 4677 if (n < 0) |
915 | 4678 posp->coladd = 0; |
4679 else | |
4680 posp->coladd = n; | |
709 | 4681 |
5938 | 4682 if (curswantp != NULL) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4683 *curswantp = list_find_nr(l, i + 1, NULL); // curswant |
5938 | 4684 |
709 | 4685 return OK; |
4686 } | |
4687 | |
4688 /* | |
7 | 4689 * Get the length of an environment variable name. |
4690 * Advance "arg" to the first character after the name. | |
4691 * Return 0 for error. | |
4692 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
4693 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4694 get_env_len(char_u **arg) |
7 | 4695 { |
4696 char_u *p; | |
4697 int len; | |
4698 | |
4699 for (p = *arg; vim_isIDc(*p); ++p) | |
4700 ; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4701 if (p == *arg) // no name found |
7 | 4702 return 0; |
4703 | |
4704 len = (int)(p - *arg); | |
4705 *arg = p; | |
4706 return len; | |
4707 } | |
4708 | |
4709 /* | |
4710 * Get the length of the name of a function or internal variable. | |
4711 * "arg" is advanced to the first non-white character after the name. | |
4712 * Return 0 if something is wrong. | |
4713 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4714 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4715 get_id_len(char_u **arg) |
7 | 4716 { |
4717 char_u *p; | |
4718 int len; | |
4719 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4720 // Find the end of the name. |
7 | 4721 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
|
4722 { |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4723 if (*p == ':') |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4724 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4725 // "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
|
4726 // 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
|
4727 len = (int)(p - *arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4728 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
|
4729 || len > 1) |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4730 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4731 } |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4732 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4733 if (p == *arg) // no name found |
7 | 4734 return 0; |
4735 | |
4736 len = (int)(p - *arg); | |
4737 *arg = skipwhite(p); | |
4738 | |
4739 return len; | |
4740 } | |
4741 | |
4742 /* | |
124 | 4743 * Get the length of the name of a variable or function. |
4744 * Only the name is recognized, does not handle ".key" or "[idx]". | |
7 | 4745 * "arg" is advanced to the first non-white character after the name. |
159 | 4746 * Return -1 if curly braces expansion failed. |
4747 * Return 0 if something else is wrong. | |
7 | 4748 * If the name contains 'magic' {}'s, expand them and return the |
4749 * expanded name in an allocated string via 'alias' - caller must free. | |
4750 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
4751 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4752 get_name_len( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4753 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4754 char_u **alias, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4755 int evaluate, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4756 int verbose) |
7 | 4757 { |
4758 int len; | |
4759 char_u *p; | |
4760 char_u *expr_start; | |
4761 char_u *expr_end; | |
4762 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4763 *alias = NULL; // default to no alias |
7 | 4764 |
4765 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA | |
4766 && (*arg)[2] == (int)KE_SNR) | |
4767 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4768 // hard coded <SNR>, already translated |
7 | 4769 *arg += 3; |
4770 return get_id_len(arg) + 3; | |
4771 } | |
4772 len = eval_fname_script(*arg); | |
4773 if (len > 0) | |
4774 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4775 // literal "<SID>", "s:" or "<SNR>" |
7 | 4776 *arg += len; |
4777 } | |
4778 | |
4779 /* | |
71 | 4780 * Find the end of the name; check for {} construction. |
7 | 4781 */ |
271 | 4782 p = find_name_end(*arg, &expr_start, &expr_end, |
4783 len > 0 ? 0 : FNE_CHECK_START); | |
7 | 4784 if (expr_start != NULL) |
4785 { | |
4786 char_u *temp_string; | |
4787 | |
4788 if (!evaluate) | |
4789 { | |
4790 len += (int)(p - *arg); | |
4791 *arg = skipwhite(p); | |
4792 return len; | |
4793 } | |
4794 | |
4795 /* | |
4796 * Include any <SID> etc in the expanded string: | |
4797 * Thus the -len here. | |
4798 */ | |
4799 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p); | |
4800 if (temp_string == NULL) | |
159 | 4801 return -1; |
7 | 4802 *alias = temp_string; |
4803 *arg = skipwhite(p); | |
4804 return (int)STRLEN(temp_string); | |
4805 } | |
4806 | |
4807 len += get_id_len(arg); | |
15464
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
4808 // 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
|
4809 // reported at a higher level. |
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
4810 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
|
4811 semsg(_(e_invexpr2), *arg); |
7 | 4812 |
4813 return len; | |
4814 } | |
4815 | |
71 | 4816 /* |
4817 * Find the end of a variable or function name, taking care of magic braces. | |
4818 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the | |
4819 * start and end of the first magic braces item. | |
271 | 4820 * "flags" can have FNE_INCL_BR and FNE_CHECK_START. |
71 | 4821 * Return a pointer to just after the name. Equal to "arg" if there is no |
4822 * valid name. | |
4823 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4824 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4825 find_name_end( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4826 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4827 char_u **expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4828 char_u **expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4829 int flags) |
71 | 4830 { |
4831 int mb_nest = 0; | |
4832 int br_nest = 0; | |
7 | 4833 char_u *p; |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4834 int len; |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
4835 int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; |
7 | 4836 |
71 | 4837 if (expr_start != NULL) |
4838 { | |
4839 *expr_start = NULL; | |
4840 *expr_end = NULL; | |
4841 } | |
4842 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4843 // 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
|
4844 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
|
4845 && (*arg != '{' || vim9script)) |
271 | 4846 return arg; |
4847 | |
71 | 4848 for (p = arg; *p != NUL |
4849 && (eval_isnamec(*p) | |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
4850 || (*p == '{' && !vim9script) |
271 | 4851 || ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.')) |
71 | 4852 || mb_nest != 0 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
4853 || br_nest != 0); MB_PTR_ADV(p)) |
468 | 4854 { |
4855 if (*p == '\'') | |
4856 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4857 // 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
|
4858 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) |
468 | 4859 ; |
4860 if (*p == NUL) | |
4861 break; | |
4862 } | |
4863 else if (*p == '"') | |
4864 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4865 // 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
|
4866 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
468 | 4867 if (*p == '\\' && p[1] != NUL) |
4868 ++p; | |
4869 if (*p == NUL) | |
4870 break; | |
4871 } | |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4872 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
|
4873 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4874 // "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
|
4875 // 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
|
4876 len = (int)(p - arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4877 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
|
4878 || (len > 1 && p[-1] != '}')) |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4879 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4880 } |
468 | 4881 |
71 | 4882 if (mb_nest == 0) |
4883 { | |
4884 if (*p == '[') | |
4885 ++br_nest; | |
4886 else if (*p == ']') | |
4887 --br_nest; | |
4888 } | |
468 | 4889 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
4890 if (br_nest == 0 && !vim9script) |
71 | 4891 { |
4892 if (*p == '{') | |
4893 { | |
4894 mb_nest++; | |
4895 if (expr_start != NULL && *expr_start == NULL) | |
4896 *expr_start = p; | |
4897 } | |
4898 else if (*p == '}') | |
4899 { | |
4900 mb_nest--; | |
4901 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) | |
4902 *expr_end = p; | |
4903 } | |
4904 } | |
7 | 4905 } |
4906 | |
4907 return p; | |
4908 } | |
4909 | |
4910 /* | |
159 | 4911 * Expands out the 'magic' {}'s in a variable/function name. |
4912 * Note that this can call itself recursively, to deal with | |
4913 * constructs like foo{bar}{baz}{bam} | |
4914 * The four pointer arguments point to "foo{expre}ss{ion}bar" | |
4915 * "in_start" ^ | |
4916 * "expr_start" ^ | |
4917 * "expr_end" ^ | |
4918 * "in_end" ^ | |
4919 * | |
4920 * Returns a new allocated string, which the caller must free. | |
4921 * Returns NULL for failure. | |
4922 */ | |
4923 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4924 make_expanded_name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4925 char_u *in_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4926 char_u *expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4927 char_u *expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4928 char_u *in_end) |
159 | 4929 { |
4930 char_u c1; | |
4931 char_u *retval = NULL; | |
4932 char_u *temp_result; | |
4933 | |
4934 if (expr_end == NULL || in_end == NULL) | |
4935 return NULL; | |
4936 *expr_start = NUL; | |
4937 *expr_end = NUL; | |
4938 c1 = *in_end; | |
4939 *in_end = NUL; | |
4940 | |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
4941 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
|
4942 if (temp_result != NULL) |
159 | 4943 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
4944 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
|
4945 + (in_end - expr_end) + 1); |
159 | 4946 if (retval != NULL) |
4947 { | |
4948 STRCPY(retval, in_start); | |
4949 STRCAT(retval, temp_result); | |
4950 STRCAT(retval, expr_end + 1); | |
4951 } | |
4952 } | |
4953 vim_free(temp_result); | |
4954 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4955 *in_end = c1; // put char back for error messages |
159 | 4956 *expr_start = '{'; |
4957 *expr_end = '}'; | |
4958 | |
4959 if (retval != NULL) | |
4960 { | |
271 | 4961 temp_result = find_name_end(retval, &expr_start, &expr_end, 0); |
159 | 4962 if (expr_start != NULL) |
4963 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4964 // Further expansion! |
159 | 4965 temp_result = make_expanded_name(retval, expr_start, |
4966 expr_end, temp_result); | |
4967 vim_free(retval); | |
4968 retval = temp_result; | |
4969 } | |
4970 } | |
4971 | |
4972 return retval; | |
4973 } | |
4974 | |
4975 /* | |
7 | 4976 * Return TRUE if character "c" can be used in a variable or function name. |
104 | 4977 * Does not include '{' or '}' for magic braces. |
7 | 4978 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4979 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4980 eval_isnamec(int c) |
7 | 4981 { |
271 | 4982 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); |
4983 } | |
4984 | |
4985 /* | |
4986 * Return TRUE if character "c" can be used as the first character in a | |
4987 * variable or function name (excluding '{' and '}'). | |
4988 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4989 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4990 eval_isnamec1(int c) |
271 | 4991 { |
4992 return (ASCII_ISALPHA(c) || c == '_'); | |
7 | 4993 } |
4994 | |
4995 /* | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
4996 * Handle: |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
4997 * - 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
|
4998 * - ".name" lookup |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
4999 * - 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
|
5000 * - method call: var->method() |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5001 * |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5002 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len() |
159 | 5003 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5004 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5005 handle_subscript( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5006 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5007 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
|
5008 evalarg_T *evalarg, |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
5009 int verbose) // give error messages |
159 | 5010 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
5011 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
|
5012 && (evalarg->eval_flags & EVAL_EVALUATE); |
159 | 5013 int ret = OK; |
5014 dict_T *selfdict = NULL; | |
5015 | |
17448
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5016 // "." is ".name" lookup when we found a dict or when evaluating and |
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5017 // scriptversion is at least 2, where string concatenation is "..". |
159 | 5018 while (ret == OK |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5019 && (((**arg == '[' |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5020 || (**arg == '.' && (rettv->v_type == VAR_DICT |
17448
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5021 || (!evaluate |
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5022 && (*arg)[1] != '.' |
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5023 && current_sctx.sc_version >= 2))) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5024 || (**arg == '(' && (!evaluate || rettv->v_type == VAR_FUNC |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5025 || rettv->v_type == VAR_PARTIAL))) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5026 && !VIM_ISWHITE(*(*arg - 1))) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5027 || (**arg == '-' && (*arg)[1] == '>'))) |
159 | 5028 { |
5029 if (**arg == '(') | |
5030 { | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5031 ret = call_func_rettv(arg, rettv, evaluate, selfdict, NULL); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5032 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5033 // 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
|
5034 // 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
|
5035 // but not caught. |
159 | 5036 if (aborting()) |
5037 { | |
5038 if (ret == OK) | |
5039 clear_tv(rettv); | |
5040 ret = FAIL; | |
5041 } | |
5042 dict_unref(selfdict); | |
5043 selfdict = NULL; | |
5044 } | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5045 else if (**arg == '-') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5046 { |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5047 if (ret == OK) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5048 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5049 if ((*arg)[2] == '{') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5050 // 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
|
5051 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
|
5052 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5053 // expr->name() |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5054 ret = eval_method(arg, rettv, evaluate, verbose); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5055 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5056 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5057 else // **arg == '[' || **arg == '.' |
159 | 5058 { |
5059 dict_unref(selfdict); | |
5060 if (rettv->v_type == VAR_DICT) | |
5061 { | |
5062 selfdict = rettv->vval.v_dict; | |
5063 if (selfdict != NULL) | |
5064 ++selfdict->dv_refcount; | |
5065 } | |
5066 else | |
5067 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
|
5068 if (eval_index(arg, rettv, evalarg, verbose) == FAIL) |
159 | 5069 { |
5070 clear_tv(rettv); | |
5071 ret = FAIL; | |
5072 } | |
5073 } | |
5074 } | |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5075 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5076 // 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
|
5077 // 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
|
5078 // explicitly (pt_auto is FALSE). |
9104
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5079 if (selfdict != NULL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5080 && (rettv->v_type == VAR_FUNC |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5081 || (rettv->v_type == VAR_PARTIAL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5082 && (rettv->vval.v_partial->pt_auto |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5083 || 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
|
5084 selfdict = make_partial(selfdict, rettv); |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5085 |
159 | 5086 dict_unref(selfdict); |
5087 return ret; | |
5088 } | |
5089 | |
5090 /* | |
104 | 5091 * Make a copy of an item. |
5092 * Lists and Dictionaries are also copied. A deep copy if "deep" is set. | |
165 | 5093 * For deepcopy() "copyID" is zero for a full copy or the ID for when a |
5094 * reference to an already copied list/dict can be used. | |
5095 * Returns FAIL or OK. | |
5096 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
5097 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5098 item_copy( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5099 typval_T *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5100 typval_T *to, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5101 int deep, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5102 int copyID) |
104 | 5103 { |
5104 static int recurse = 0; | |
165 | 5105 int ret = OK; |
104 | 5106 |
137 | 5107 if (recurse >= DICT_MAXNEST) |
104 | 5108 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5109 emsg(_("E698: variable nested too deep for making a copy")); |
165 | 5110 return FAIL; |
104 | 5111 } |
5112 ++recurse; | |
5113 | |
5114 switch (from->v_type) | |
5115 { | |
5116 case VAR_NUMBER: | |
1624 | 5117 case VAR_FLOAT: |
104 | 5118 case VAR_STRING: |
5119 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5120 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
|
5121 case VAR_BOOL: |
7862
d4fec9208e7e
commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5122 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5123 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5124 case VAR_CHANNEL: |
104 | 5125 copy_tv(from, to); |
5126 break; | |
5127 case VAR_LIST: | |
5128 to->v_type = VAR_LIST; | |
151 | 5129 to->v_lock = 0; |
165 | 5130 if (from->vval.v_list == NULL) |
5131 to->vval.v_list = NULL; | |
5132 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID) | |
5133 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5134 // use the copy made earlier |
165 | 5135 to->vval.v_list = from->vval.v_list->lv_copylist; |
5136 ++to->vval.v_list->lv_refcount; | |
5137 } | |
5138 else | |
5139 to->vval.v_list = list_copy(from->vval.v_list, deep, copyID); | |
5140 if (to->vval.v_list == NULL) | |
5141 ret = FAIL; | |
104 | 5142 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
|
5143 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
|
5144 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
|
5145 break; |
104 | 5146 case VAR_DICT: |
5147 to->v_type = VAR_DICT; | |
151 | 5148 to->v_lock = 0; |
165 | 5149 if (from->vval.v_dict == NULL) |
5150 to->vval.v_dict = NULL; | |
5151 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID) | |
5152 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5153 // use the copy made earlier |
165 | 5154 to->vval.v_dict = from->vval.v_dict->dv_copydict; |
5155 ++to->vval.v_dict->dv_refcount; | |
5156 } | |
5157 else | |
5158 to->vval.v_dict = dict_copy(from->vval.v_dict, deep, copyID); | |
5159 if (to->vval.v_dict == NULL) | |
5160 ret = FAIL; | |
104 | 5161 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5162 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
|
5163 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
|
5164 case VAR_VOID: |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
5165 internal_error_no_abort("item_copy(UNKNOWN)"); |
165 | 5166 ret = FAIL; |
104 | 5167 } |
5168 --recurse; | |
165 | 5169 return ret; |
104 | 5170 } |
5171 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5172 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5173 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
|
5174 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5175 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
|
5176 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
|
5177 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
|
5178 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5179 if (*atstart) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5180 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5181 *atstart = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5182 // 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
|
5183 // 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
|
5184 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
|
5185 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5186 // 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
|
5187 // 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
|
5188 // 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
|
5189 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
|
5190 msg_start(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5191 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5192 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5193 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
|
5194 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
|
5195 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5196 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
|
5197 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
|
5198 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5199 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
|
5200 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5201 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
|
5202 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5203 // 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
|
5204 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
|
5205 *needclr = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5206 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5207 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
|
5208 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5209 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5210 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5211 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
|
5212 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5213 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
|
5214 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5215 (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
|
5216 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
|
5217 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5218 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5219 (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
|
5220 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5221 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5222 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
|
5223 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5224 |
104 | 5225 /* |
7 | 5226 * ":echo expr1 ..." print each argument separated with a space, add a |
5227 * newline at the end. | |
5228 * ":echon expr1 ..." print each argument plain. | |
5229 */ | |
5230 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5231 ex_echo(exarg_T *eap) |
7 | 5232 { |
5233 char_u *arg = eap->arg; | |
137 | 5234 typval_T rettv; |
7 | 5235 char_u *p; |
5236 int needclr = TRUE; | |
5237 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
|
5238 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
|
5239 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
|
5240 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
|
5241 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
5242 CLEAR_FIELD(evalarg); |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
5243 evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE; |
21056
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
5244 if (getline_equal(eap->getline, eap->cookie, getsourceline)) |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
5245 { |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
5246 evalarg.eval_getline = eap->getline; |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
5247 evalarg.eval_cookie = eap->cookie; |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
5248 } |
7 | 5249 |
5250 if (eap->skip) | |
5251 ++emsg_skip; | |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5252 while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int) |
7 | 5253 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5254 // 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
|
5255 // still need to be cleared. E.g., "echo 22,44". |
1624 | 5256 need_clr_eos = needclr; |
5257 | |
7 | 5258 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
|
5259 if (eval1(&arg, &rettv, &evalarg) == FAIL) |
7 | 5260 { |
5261 /* | |
5262 * Report the invalid expression unless the expression evaluation | |
5263 * has been cancelled due to an aborting error, an interrupt, or an | |
5264 * exception. | |
5265 */ | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5266 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
|
5267 && 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
|
5268 semsg(_(e_invexpr2), p); |
1624 | 5269 need_clr_eos = FALSE; |
5270 break; | |
5271 } | |
5272 need_clr_eos = FALSE; | |
5273 | |
7 | 5274 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
|
5275 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
|
5276 |
71 | 5277 clear_tv(&rettv); |
7 | 5278 arg = skipwhite(arg); |
5279 } | |
5280 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
|
5281 clear_evalarg(&evalarg, eap); |
7 | 5282 |
5283 if (eap->skip) | |
5284 --emsg_skip; | |
5285 else | |
5286 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5287 // remove text that may still be there from the command |
7 | 5288 if (needclr) |
5289 msg_clr_eos(); | |
5290 if (eap->cmdidx == CMD_echo) | |
5291 msg_end(); | |
5292 } | |
5293 } | |
5294 | |
5295 /* | |
5296 * ":echohl {name}". | |
5297 */ | |
5298 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5299 ex_echohl(exarg_T *eap) |
7 | 5300 { |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
5301 echo_attr = syn_name2attr(eap->arg); |
7 | 5302 } |
5303 | |
5304 /* | |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5305 * 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
|
5306 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5307 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5308 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
|
5309 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5310 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
|
5311 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5312 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5313 /* |
7 | 5314 * ":execute expr1 ..." execute the result of an expression. |
5315 * ":echomsg expr1 ..." Print a message | |
5316 * ":echoerr expr1 ..." Print an error | |
5317 * Each gets spaces around each argument and a newline at the end for | |
5318 * echo commands | |
5319 */ | |
5320 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5321 ex_execute(exarg_T *eap) |
7 | 5322 { |
5323 char_u *arg = eap->arg; | |
137 | 5324 typval_T rettv; |
7 | 5325 int ret = OK; |
5326 char_u *p; | |
5327 garray_T ga; | |
5328 int len; | |
5329 | |
5330 ga_init2(&ga, 1, 80); | |
5331 | |
5332 if (eap->skip) | |
5333 ++emsg_skip; | |
20061
6e6a75800884
patch 8.2.0586: Vim9: # comment not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20059
diff
changeset
|
5334 while (!ends_excmd2(eap->cmd, arg) || *arg == '"') |
7 | 5335 { |
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
|
5336 ret = eval1_emsg(&arg, &rettv, !eap->skip); |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5337 if (ret == FAIL) |
7 | 5338 break; |
5339 | |
5340 if (!eap->skip) | |
5341 { | |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5342 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
|
5343 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5344 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
|
5345 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5346 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
|
5347 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5348 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
|
5349 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
|
5350 } |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5351 else |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
5352 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
|
5353 } |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5354 else |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5355 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
|
5356 if (p == NULL) |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5357 { |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5358 clear_tv(&rettv); |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5359 ret = FAIL; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5360 break; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5361 } |
7 | 5362 len = (int)STRLEN(p); |
5363 if (ga_grow(&ga, len + 2) == FAIL) | |
5364 { | |
71 | 5365 clear_tv(&rettv); |
7 | 5366 ret = FAIL; |
5367 break; | |
5368 } | |
5369 if (ga.ga_len) | |
5370 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' '; | |
5371 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p); | |
5372 ga.ga_len += len; | |
5373 } | |
5374 | |
71 | 5375 clear_tv(&rettv); |
7 | 5376 arg = skipwhite(arg); |
5377 } | |
5378 | |
5379 if (ret != FAIL && ga.ga_data != NULL) | |
5380 { | |
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
|
5381 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
|
5382 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5383 // 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
|
5384 // 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
|
5385 // 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
|
5386 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
|
5387 } |
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5388 |
7 | 5389 if (eap->cmdidx == CMD_echomsg) |
625 | 5390 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
5391 msg_attr(ga.ga_data, echo_attr); |
625 | 5392 out_flush(); |
5393 } | |
7 | 5394 else if (eap->cmdidx == CMD_echoerr) |
5395 { | |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20128
diff
changeset
|
5396 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
|
5397 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5398 // 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
|
5399 emsg(ga.ga_data); |
7 | 5400 if (!force_abort) |
5401 did_emsg = save_did_emsg; | |
5402 } | |
5403 else if (eap->cmdidx == CMD_execute) | |
5404 do_cmdline((char_u *)ga.ga_data, | |
5405 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); | |
5406 } | |
5407 | |
5408 ga_clear(&ga); | |
5409 | |
5410 if (eap->skip) | |
5411 --emsg_skip; | |
5412 | |
5413 eap->nextcmd = check_nextcmd(arg); | |
5414 } | |
5415 | |
5416 /* | |
5417 * Skip over the name of an option: "&option", "&g:option" or "&l:option". | |
5418 * "arg" points to the "&" or '+' when called, to "option" when returning. | |
5419 * Returns NULL when no option name found. Otherwise pointer to the char | |
5420 * after the option name. | |
5421 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
5422 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5423 find_option_end(char_u **arg, int *opt_flags) |
7 | 5424 { |
5425 char_u *p = *arg; | |
5426 | |
5427 ++p; | |
5428 if (*p == 'g' && p[1] == ':') | |
5429 { | |
5430 *opt_flags = OPT_GLOBAL; | |
5431 p += 2; | |
5432 } | |
5433 else if (*p == 'l' && p[1] == ':') | |
5434 { | |
5435 *opt_flags = OPT_LOCAL; | |
5436 p += 2; | |
5437 } | |
5438 else | |
5439 *opt_flags = 0; | |
5440 | |
5441 if (!ASCII_ISALPHA(*p)) | |
5442 return NULL; | |
5443 *arg = p; | |
5444 | |
5445 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
|
5446 p += 4; // termcap option |
7 | 5447 else |
5448 while (ASCII_ISALPHA(*p)) | |
5449 ++p; | |
5450 return p; | |
5451 } | |
5452 | |
5453 /* | |
448 | 5454 * Display script name where an item was last set. |
5455 * Should only be invoked when 'verbose' is non-zero. | |
5456 */ | |
5457 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
|
5458 last_set_msg(sctx_T script_ctx) |
448 | 5459 { |
507 | 5460 char_u *p; |
5461 | |
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
|
5462 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
|
5463 { |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
5464 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); |
507 | 5465 if (p != NULL) |
5466 { | |
5467 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
5468 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
|
5469 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
|
5470 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
|
5471 { |
18939
25ebc35e104f
patch 8.2.0030: "gF" does not work on output of "verbose command"
Bram Moolenaar <Bram@vim.org>
parents:
18851
diff
changeset
|
5472 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
|
5473 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
|
5474 } |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
5475 verbose_leave(); |
507 | 5476 vim_free(p); |
5477 } | |
448 | 5478 } |
5479 } | |
5480 | |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
5481 #endif // FEAT_EVAL |
7 | 5482 |
5483 /* | |
5484 * 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
|
5485 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL. |
7 | 5486 * "flags" can be "g" to do a global substitute. |
5487 * Returns an allocated string, NULL for error. | |
5488 */ | |
5489 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5490 do_string_sub( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5491 char_u *str, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5492 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5493 char_u *sub, |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5494 typval_T *expr, |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5495 char_u *flags) |
7 | 5496 { |
5497 int sublen; | |
5498 regmatch_T regmatch; | |
5499 int i; | |
5500 int do_all; | |
5501 char_u *tail; | |
6332 | 5502 char_u *end; |
7 | 5503 garray_T ga; |
5504 char_u *ret; | |
5505 char_u *save_cpo; | |
5623 | 5506 char_u *zero_width = NULL; |
7 | 5507 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5508 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here |
7 | 5509 save_cpo = p_cpo; |
1672 | 5510 p_cpo = empty_option; |
7 | 5511 |
5512 ga_init2(&ga, 1, 200); | |
5513 | |
5514 do_all = (flags[0] == 'g'); | |
5515 | |
5516 regmatch.rm_ic = p_ic; | |
5517 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | |
5518 if (regmatch.regprog != NULL) | |
5519 { | |
5520 tail = str; | |
6332 | 5521 end = str + STRLEN(str); |
7 | 5522 while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) |
5523 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5524 // Skip empty match except for first match. |
5623 | 5525 if (regmatch.startp[0] == regmatch.endp[0]) |
5526 { | |
5527 if (zero_width == regmatch.startp[0]) | |
5528 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5529 // 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
|
5530 i = mb_ptr2len(tail); |
5964 | 5531 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, |
5532 (size_t)i); | |
5533 ga.ga_len += i; | |
5534 tail += i; | |
5623 | 5535 continue; |
5536 } | |
5537 zero_width = regmatch.startp[0]; | |
5538 } | |
5539 | |
7 | 5540 /* |
5541 * Get some space for a temporary buffer to do the substitution | |
5542 * into. It will contain: | |
5543 * - The text up to where the match is. | |
5544 * - The substituted text. | |
5545 * - The text after the match. | |
5546 */ | |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5547 sublen = vim_regsub(®match, sub, expr, tail, FALSE, TRUE, FALSE); |
6332 | 5548 if (ga_grow(&ga, (int)((end - tail) + sublen - |
7 | 5549 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL) |
5550 { | |
5551 ga_clear(&ga); | |
5552 break; | |
5553 } | |
5554 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5555 // copy the text up to where the match is |
7 | 5556 i = (int)(regmatch.startp[0] - tail); |
5557 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
|
5558 // add the substituted text |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
5559 (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data |
7 | 5560 + ga.ga_len + i, TRUE, TRUE, FALSE); |
5561 ga.ga_len += i + sublen - 1; | |
5388 | 5562 tail = regmatch.endp[0]; |
5563 if (*tail == NUL) | |
5564 break; | |
7 | 5565 if (!do_all) |
5566 break; | |
5567 } | |
5568 | |
5569 if (ga.ga_data != NULL) | |
5570 STRCPY((char *)ga.ga_data + ga.ga_len, tail); | |
5571 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4778
diff
changeset
|
5572 vim_regfree(regmatch.regprog); |
7 | 5573 } |
5574 | |
5575 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data); | |
5576 ga_clear(&ga); | |
1672 | 5577 if (p_cpo == empty_option) |
5578 p_cpo = save_cpo; | |
5579 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5580 // Darn, evaluating {sub} expression or {expr} changed the value. |
1672 | 5581 free_string_option(save_cpo); |
7 | 5582 |
5583 return ret; | |
5584 } |