Mercurial > vim
annotate src/eval.c @ 20091:a64c16ff98b8 v8.2.0601
patch 8.2.0601: Vim9: :unlet is not compiled
Commit: https://github.com/vim/vim/commit/d72c1bf0a6784afdc8d8ceab4a007cd76d5b81e1
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 19 16:28:59 2020 +0200
patch 8.2.0601: Vim9: :unlet is not compiled
Problem: Vim9: :unlet is not compiled.
Solution: Implement :unlet instruction and check for errors.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Apr 2020 16:30:04 +0200 |
parents | 6e6a75800884 |
children | f40231487a49 |
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"); |
4936
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
24 #ifdef FEAT_FLOAT |
4870
b7bb20390111
updated for version 7.3.1181
Bram Moolenaar <bram@vim.org>
parents:
4859
diff
changeset
|
25 static char *e_float_as_string = N_("E806: using Float as a String"); |
4936
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
26 #endif |
1624 | 27 |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
28 #define NAMESPACE_CHAR (char_u *)"abglstvw" |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
29 |
142 | 30 /* |
364 | 31 * When recursively copying lists and dicts we need to remember which ones we |
32 * have done to avoid endless recursiveness. This unique ID is used for that. | |
1891 | 33 * The last bit is used for previous_funccal, ignored when comparing. |
364 | 34 */ |
35 static int current_copyID = 0; | |
5973 | 36 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
37 static int echo_attr = 0; // attributes used for ":echo" |
7 | 38 |
39 /* | |
76 | 40 * Info used by a ":for" loop. |
41 */ | |
137 | 42 typedef struct |
76 | 43 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
44 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
|
45 int fi_varcount; // nr of variables in the list |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 blob_T *fi_blob; // blob being used |
137 | 50 } forinfo_T; |
76 | 51 |
7720
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
52 static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
53 static int eval2(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
54 static int eval3(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
55 static int eval4(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
56 static int eval5(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
57 static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
58 static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string); |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
59 static int eval7_leader(typval_T *rettv, 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
|
60 |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
61 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
|
62 static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end); |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
63 static int tv_check_lock(typval_T *tv, char_u *name, int use_gettext); |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
64 |
15969
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 * 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
|
67 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
68 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
69 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
|
70 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
71 varnumber_T result; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
72 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
73 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
|
74 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
75 if (n1 == 0) |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
76 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
|
77 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
|
78 result = -VARNUM_MAX; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
79 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
80 result = VARNUM_MAX; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
81 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
82 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
83 result = n1 / n2; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
84 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
85 return result; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
86 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
87 |
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 * 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
|
90 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
91 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
92 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
|
93 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
94 // 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
|
95 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
|
96 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
97 |
10567
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
98 #if defined(EBCDIC) || defined(PROTO) |
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 * 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
|
101 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
102 static int |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
103 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
|
104 { |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
105 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
|
106 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
|
107 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
108 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
|
109 } |
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 /* |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
112 * 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
|
113 * 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
|
114 * 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
|
115 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
116 static void |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
117 sortFunctions(void) |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
118 { |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
119 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
|
120 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
121 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
|
122 } |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
123 #endif |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
124 |
137 | 125 /* |
126 * Initialize the global and v: variables. | |
127 */ | |
128 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
129 eval_init(void) |
137 | 130 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
131 evalvars_init(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
132 func_init(); |
137 | 133 |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
134 #ifdef EBCDIC |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
135 /* |
3178 | 136 * 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
|
137 */ |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
138 sortFunctions(); |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
139 #endif |
137 | 140 } |
141 | |
357 | 142 #if defined(EXITFREE) || defined(PROTO) |
143 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
144 eval_clear(void) |
357 | 145 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
146 evalvars_clear(); |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
147 free_scriptnames(); // must come after evalvars_clear(). |
2849 | 148 free_locales(); |
357 | 149 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
150 // 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
|
151 free_autoload_scriptnames(); |
855 | 152 |
16967
586d625e21b4
patch 8.1.1484: some tests are slow
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
153 // unreferenced lists and dicts |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
154 (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
|
155 |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16967
diff
changeset
|
156 // 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
|
157 free_all_functions(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
158 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
159 #endif |
137 | 160 |
7 | 161 /* |
162 * Top level evaluation function, returning a boolean. | |
163 * Sets "error" to TRUE if there was an error. | |
164 * Return TRUE or FALSE. | |
165 */ | |
166 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
167 eval_to_bool( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
168 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
169 int *error, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
170 char_u **nextcmd, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
171 int skip) // only parse, don't execute |
7 | 172 { |
137 | 173 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
174 varnumber_T retval = FALSE; |
7 | 175 |
176 if (skip) | |
177 ++emsg_skip; | |
71 | 178 if (eval0(arg, &tv, nextcmd, !skip) == FAIL) |
7 | 179 *error = TRUE; |
180 else | |
181 { | |
182 *error = FALSE; | |
183 if (!skip) | |
184 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
185 retval = (tv_get_number_chk(&tv, error) != 0); |
71 | 186 clear_tv(&tv); |
7 | 187 } |
188 } | |
189 if (skip) | |
190 --emsg_skip; | |
191 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
192 return (int)retval; |
7 | 193 } |
194 | |
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
|
195 /* |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
196 * 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
|
197 */ |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
198 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
|
199 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
|
200 { |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 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
|
205 |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
206 ret = eval1(arg, rettv, 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
|
207 if (ret == FAIL) |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
208 { |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
209 // Report the invalid expression unless the expression evaluation has |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
210 // been cancelled due to an aborting error, an interrupt, or an |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
211 // exception, or we already gave a more specific error. |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
212 // Also check called_emsg for when using assert_fails(). |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
213 if (!aborting() && did_emsg == did_emsg_before |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
214 && called_emsg == called_emsg_before) |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
215 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
|
216 } |
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 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
|
218 } |
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 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
220 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
221 * 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
|
222 * 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
|
223 * 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
|
224 */ |
16231
0761a4c111a7
patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
225 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
|
226 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
|
227 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
232 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
|
233 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
234 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
|
235 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
|
236 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
237 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
|
238 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
239 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
|
240 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
|
241 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
242 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
|
243 { |
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 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
|
245 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
246 if (partial->pt_func != NULL && partial->pt_func->uf_dfunc_idx >= 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
247 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
248 if (call_def_function(partial->pt_func, argc, argv, rettv) == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
249 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
250 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
251 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
252 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
253 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
|
254 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
|
255 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
261 } |
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
|
262 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
263 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
|
264 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
265 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
|
266 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
|
267 return FAIL; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
268 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
|
269 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
|
270 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
271 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
|
272 { |
14331
f8280e1bfc84
patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
273 clear_tv(rettv); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
274 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
|
275 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
|
276 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
277 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
278 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
|
279 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
280 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
281 /* |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
282 * 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
|
283 * 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
|
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 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
|
286 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
|
287 { |
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 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
|
289 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
|
290 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
291 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
|
292 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
293 *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
|
294 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
|
295 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
296 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
|
297 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
|
298 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
|
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 |
7 | 301 /* |
302 * Top level evaluation function, returning a string. If "skip" is TRUE, | |
303 * only parsing to "nextcmd" is done, without reporting errors. Return | |
304 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE. | |
305 */ | |
306 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
307 eval_to_string_skip( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
308 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
309 char_u **nextcmd, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
310 int skip) // only parse, don't execute |
7 | 311 { |
137 | 312 typval_T tv; |
7 | 313 char_u *retval; |
314 | |
315 if (skip) | |
316 ++emsg_skip; | |
71 | 317 if (eval0(arg, &tv, nextcmd, !skip) == FAIL || skip) |
7 | 318 retval = NULL; |
319 else | |
320 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
321 retval = vim_strsave(tv_get_string(&tv)); |
71 | 322 clear_tv(&tv); |
7 | 323 } |
324 if (skip) | |
325 --emsg_skip; | |
326 | |
327 return retval; | |
328 } | |
329 | |
330 /* | |
9 | 331 * Skip over an expression at "*pp". |
332 * Return FAIL for an error, OK otherwise. | |
333 */ | |
334 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
335 skip_expr(char_u **pp) |
9 | 336 { |
137 | 337 typval_T rettv; |
9 | 338 |
339 *pp = skipwhite(*pp); | |
71 | 340 return eval1(pp, &rettv, FALSE); |
9 | 341 } |
342 | |
343 /* | |
7 | 344 * Top level evaluation function, returning a string. |
1713 | 345 * When "convert" is TRUE convert a List into a sequence of lines and convert |
346 * a Float to a String. | |
7 | 347 * Return pointer to allocated memory, or NULL for failure. |
348 */ | |
349 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
350 eval_to_string( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
351 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
352 char_u **nextcmd, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
353 int convert) |
7 | 354 { |
137 | 355 typval_T tv; |
7 | 356 char_u *retval; |
714 | 357 garray_T ga; |
1851 | 358 #ifdef FEAT_FLOAT |
1713 | 359 char_u numbuf[NUMBUFLEN]; |
1851 | 360 #endif |
7 | 361 |
71 | 362 if (eval0(arg, &tv, nextcmd, TRUE) == FAIL) |
7 | 363 retval = NULL; |
364 else | |
365 { | |
1713 | 366 if (convert && tv.v_type == VAR_LIST) |
714 | 367 { |
368 ga_init2(&ga, (int)sizeof(char), 80); | |
1690 | 369 if (tv.vval.v_list != NULL) |
3000 | 370 { |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
371 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0); |
3000 | 372 if (tv.vval.v_list->lv_len > 0) |
373 ga_append(&ga, NL); | |
374 } | |
714 | 375 ga_append(&ga, NUL); |
376 retval = (char_u *)ga.ga_data; | |
377 } | |
1713 | 378 #ifdef FEAT_FLOAT |
379 else if (convert && tv.v_type == VAR_FLOAT) | |
380 { | |
381 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float); | |
382 retval = vim_strsave(numbuf); | |
383 } | |
384 #endif | |
714 | 385 else |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
386 retval = vim_strsave(tv_get_string(&tv)); |
71 | 387 clear_tv(&tv); |
7 | 388 } |
389 | |
390 return retval; | |
391 } | |
392 | |
393 /* | |
634 | 394 * Call eval_to_string() without using current local variables and using |
395 * textlock. When "use_sandbox" is TRUE use the sandbox. | |
7 | 396 */ |
397 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
398 eval_to_string_safe( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
399 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
400 char_u **nextcmd, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
401 int use_sandbox) |
7 | 402 { |
403 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
|
404 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
|
405 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
406 save_funccal(&funccal_entry); |
634 | 407 if (use_sandbox) |
408 ++sandbox; | |
409 ++textlock; | |
714 | 410 retval = eval_to_string(arg, nextcmd, FALSE); |
634 | 411 if (use_sandbox) |
412 --sandbox; | |
413 --textlock; | |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
414 restore_funccal(); |
7 | 415 return retval; |
416 } | |
417 | |
418 /* | |
419 * Top level evaluation function, returning a number. | |
420 * Evaluates "expr" silently. | |
421 * Returns -1 for an error. | |
422 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
423 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
424 eval_to_number(char_u *expr) |
7 | 425 { |
137 | 426 typval_T rettv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
427 varnumber_T retval; |
97 | 428 char_u *p = skipwhite(expr); |
7 | 429 |
430 ++emsg_off; | |
431 | |
71 | 432 if (eval1(&p, &rettv, TRUE) == FAIL) |
7 | 433 retval = -1; |
434 else | |
435 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
436 retval = tv_get_number_chk(&rettv, NULL); |
71 | 437 clear_tv(&rettv); |
7 | 438 } |
439 --emsg_off; | |
440 | |
441 return retval; | |
442 } | |
443 | |
446 | 444 /* |
625 | 445 * Top level evaluation function. |
446 * Returns an allocated typval_T with the result. | |
447 * Returns NULL when there is an error. | |
446 | 448 */ |
449 typval_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
450 eval_expr(char_u *arg, char_u **nextcmd) |
446 | 451 { |
452 typval_T *tv; | |
453 | |
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
|
454 tv = ALLOC_ONE(typval_T); |
625 | 455 if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
456 VIM_CLEAR(tv); |
446 | 457 |
458 return tv; | |
459 } | |
460 | |
7 | 461 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
462 * 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
|
463 * 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
|
464 * should have type VAR_UNKNOWN. |
408 | 465 * Returns OK or FAIL. |
466 */ | |
3078 | 467 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
468 call_vim_function( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
469 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
470 int argc, |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
471 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
|
472 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
|
473 { |
408 | 474 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
475 funcexe_T funcexe; |
7 | 476 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
477 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
|
478 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
|
479 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
|
480 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
|
481 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
482 ret = call_func(func, -1, rettv, argc, argv, &funcexe); |
408 | 483 if (ret == FAIL) |
484 clear_tv(rettv); | |
485 | |
486 return ret; | |
487 } | |
488 | |
4133 | 489 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
490 * Call Vim script function "func" and return the result as a number. |
4133 | 491 * 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
|
492 * 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
|
493 * have type VAR_UNKNOWN. |
4133 | 494 */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
495 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
496 call_func_retnr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
497 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
498 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
|
499 typval_T *argv) |
4133 | 500 { |
501 typval_T rettv; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
502 varnumber_T retval; |
4133 | 503 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
504 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
4133 | 505 return -1; |
506 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
507 retval = tv_get_number_chk(&rettv, NULL); |
4133 | 508 clear_tv(&rettv); |
509 return retval; | |
510 } | |
511 | |
408 | 512 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
513 * Call Vim script function "func" and return the result as a string. |
453 | 514 * 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
|
515 * 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
|
516 * have type VAR_UNKNOWN. |
408 | 517 */ |
518 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
519 call_func_retstr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
520 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
521 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
|
522 typval_T *argv) |
408 | 523 { |
524 typval_T rettv; | |
453 | 525 char_u *retval; |
408 | 526 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
527 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 528 return NULL; |
529 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
530 retval = vim_strsave(tv_get_string(&rettv)); |
408 | 531 clear_tv(&rettv); |
7 | 532 return retval; |
533 } | |
1322 | 534 |
453 | 535 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
536 * 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
|
537 * 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
|
538 * have type VAR_UNKNOWN. |
1690 | 539 * Returns NULL when there is something wrong. |
408 | 540 */ |
541 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
542 call_func_retlist( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
543 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
544 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
|
545 typval_T *argv) |
408 | 546 { |
547 typval_T rettv; | |
548 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
549 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 550 return NULL; |
551 | |
552 if (rettv.v_type != VAR_LIST) | |
553 { | |
554 clear_tv(&rettv); | |
555 return NULL; | |
556 } | |
557 | |
558 return rettv.vval.v_list; | |
559 } | |
1322 | 560 |
7 | 561 #ifdef FEAT_FOLDING |
562 /* | |
563 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding | |
564 * it in "*cp". Doesn't give error messages. | |
565 */ | |
566 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
567 eval_foldexpr(char_u *arg, int *cp) |
7 | 568 { |
137 | 569 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
570 varnumber_T retval; |
7 | 571 char_u *s; |
681 | 572 int use_sandbox = was_set_insecurely((char_u *)"foldexpr", |
573 OPT_LOCAL); | |
7 | 574 |
575 ++emsg_off; | |
634 | 576 if (use_sandbox) |
577 ++sandbox; | |
578 ++textlock; | |
7 | 579 *cp = NUL; |
71 | 580 if (eval0(arg, &tv, NULL, TRUE) == FAIL) |
7 | 581 retval = 0; |
582 else | |
583 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
584 // If the result is a number, just return the number. |
71 | 585 if (tv.v_type == VAR_NUMBER) |
586 retval = tv.vval.v_number; | |
156 | 587 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL) |
7 | 588 retval = 0; |
589 else | |
590 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
591 // 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
|
592 // the number. |
71 | 593 s = tv.vval.v_string; |
7 | 594 if (!VIM_ISDIGIT(*s) && *s != '-') |
595 *cp = *s++; | |
596 retval = atol((char *)s); | |
597 } | |
71 | 598 clear_tv(&tv); |
7 | 599 } |
600 --emsg_off; | |
634 | 601 if (use_sandbox) |
602 --sandbox; | |
603 --textlock; | |
7 | 604 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
605 return (int)retval; |
7 | 606 } |
607 #endif | |
608 | |
609 /* | |
110 | 610 * Get an lval: variable, Dict item or List item that can be assigned a value |
611 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]", | |
612 * "name.key", "name.key[expr]" etc. | |
613 * Indexing only works if "name" is an existing List or Dictionary. | |
614 * "name" points to the start of the name. | |
615 * If "rettv" is not NULL it points to the value to be assigned. | |
616 * "unlet" is TRUE for ":unlet": slightly different behavior when something is | |
617 * wrong; must end in space or cmd separator. | |
618 * | |
5604 | 619 * flags: |
620 * 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
|
621 * GLV_READ_ONLY: will not change the variable |
5604 | 622 * GLV_NO_AUTOLOAD: do not use script autoloading |
623 * | |
110 | 624 * Returns a pointer to just after the name, including indexes. |
124 | 625 * When an evaluation error occurs "lp->ll_name" is NULL; |
110 | 626 * Returns NULL for a parsing error. Still need to free items in "lp"! |
71 | 627 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
628 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
629 get_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
630 char_u *name, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
631 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
632 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
633 int unlet, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
634 int skip, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
635 int flags, // GLV_ values |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
636 int fne_flags) // flags for find_name_end() |
110 | 637 { |
638 char_u *p; | |
639 char_u *expr_start, *expr_end; | |
640 int cc; | |
137 | 641 dictitem_T *v; |
642 typval_T var1; | |
643 typval_T var2; | |
110 | 644 int empty1 = FALSE; |
137 | 645 listitem_T *ni; |
100 | 646 char_u *key = NULL; |
647 int len; | |
137 | 648 hashtab_T *ht; |
5604 | 649 int quiet = flags & GLV_QUIET; |
71 | 650 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
651 // Clear everything in "lp". |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
652 CLEAR_POINTER(lp); |
110 | 653 |
654 if (skip) | |
655 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
656 // When skipping just find the end of the name. |
110 | 657 lp->ll_name = name; |
271 | 658 return find_name_end(name, NULL, NULL, FNE_INCL_BR | fne_flags); |
110 | 659 } |
660 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
661 // Find the end of the name. |
271 | 662 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
|
663 lp->ll_name_end = p; |
110 | 664 if (expr_start != NULL) |
665 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
666 // 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
|
667 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p) |
110 | 668 && *p != '[' && *p != '.') |
669 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
670 emsg(_(e_trailing)); |
110 | 671 return NULL; |
672 } | |
673 | |
674 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); | |
675 if (lp->ll_exp_name == NULL) | |
676 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
677 // 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
|
678 // 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
|
679 // aborting error, an interrupt, or an exception. |
110 | 680 if (!aborting() && !quiet) |
681 { | |
121 | 682 emsg_severe = TRUE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
683 semsg(_(e_invarg2), name); |
110 | 684 return NULL; |
685 } | |
686 } | |
687 lp->ll_name = lp->ll_exp_name; | |
688 } | |
689 else | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
690 { |
110 | 691 lp->ll_name = name; |
692 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
693 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
|
694 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
695 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
|
696 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
|
697 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
698 // 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
|
699 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
|
700 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
|
701 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
702 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
703 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
704 // Without [idx] or .key we are done. |
110 | 705 if ((*p != '[' && *p != '.') || lp->ll_name == NULL) |
706 return p; | |
707 | |
708 cc = *p; | |
709 *p = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
710 // 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
|
711 // 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
|
712 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
|
713 flags & GLV_NO_AUTOLOAD); |
110 | 714 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
|
715 semsg(_(e_undefvar), lp->ll_name); |
110 | 716 *p = cc; |
71 | 717 if (v == NULL) |
718 return NULL; | |
719 | |
110 | 720 /* |
721 * Loop until no more [idx] or .key is following. | |
722 */ | |
137 | 723 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
|
724 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
|
725 var2.v_type = VAR_UNKNOWN; |
110 | 726 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) |
727 { | |
728 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) | |
729 && !(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
|
730 && 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
|
731 && !(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
|
732 && lp->ll_tv->vval.v_blob != NULL)) |
110 | 733 { |
734 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
735 emsg(_("E689: Can only index a List, Dictionary or Blob")); |
110 | 736 return NULL; |
737 } | |
738 if (lp->ll_range) | |
739 { | |
740 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
741 emsg(_("E708: [:] must come last")); |
110 | 742 return NULL; |
71 | 743 } |
88 | 744 |
100 | 745 len = -1; |
746 if (*p == '.') | |
747 { | |
748 key = p + 1; | |
749 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
750 ; | |
751 if (len == 0) | |
752 { | |
110 | 753 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
754 emsg(_(e_emptykey)); |
110 | 755 return NULL; |
88 | 756 } |
100 | 757 p = key + len; |
758 } | |
759 else | |
760 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
761 // Get the index [expr] or the first index [expr: ]. |
88 | 762 p = skipwhite(p + 1); |
100 | 763 if (*p == ':') |
764 empty1 = TRUE; | |
88 | 765 else |
766 { | |
100 | 767 empty1 = FALSE; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
768 if (eval1(&p, &var1, TRUE) == FAIL) // recursive! |
110 | 769 return NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
770 if (tv_get_string_chk(&var1) == NULL) |
323 | 771 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
772 // not a number or string |
323 | 773 clear_tv(&var1); |
774 return NULL; | |
775 } | |
100 | 776 } |
777 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
778 // Optionally get the second index [ :expr]. |
100 | 779 if (*p == ':') |
780 { | |
110 | 781 if (lp->ll_tv->v_type == VAR_DICT) |
782 { | |
783 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
784 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
|
785 clear_tv(&var1); |
110 | 786 return NULL; |
787 } | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
788 if (rettv != NULL |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
789 && !(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
|
790 && rettv->vval.v_list != NULL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
791 && !(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
|
792 && rettv->vval.v_blob != NULL)) |
110 | 793 { |
794 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
795 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
|
796 clear_tv(&var1); |
110 | 797 return NULL; |
88 | 798 } |
100 | 799 p = skipwhite(p + 1); |
800 if (*p == ']') | |
110 | 801 lp->ll_empty2 = TRUE; |
100 | 802 else |
803 { | |
110 | 804 lp->ll_empty2 = FALSE; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
805 if (eval1(&p, &var2, TRUE) == FAIL) // recursive! |
100 | 806 { |
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
|
807 clear_tv(&var1); |
110 | 808 return NULL; |
100 | 809 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
810 if (tv_get_string_chk(&var2) == NULL) |
323 | 811 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
812 // 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
|
813 clear_tv(&var1); |
323 | 814 clear_tv(&var2); |
815 return NULL; | |
816 } | |
100 | 817 } |
110 | 818 lp->ll_range = TRUE; |
100 | 819 } |
820 else | |
110 | 821 lp->ll_range = FALSE; |
100 | 822 |
823 if (*p != ']') | |
824 { | |
110 | 825 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
826 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
|
827 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
|
828 clear_tv(&var2); |
110 | 829 return NULL; |
100 | 830 } |
831 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
832 // Skip to past ']'. |
100 | 833 ++p; |
834 } | |
835 | |
110 | 836 if (lp->ll_tv->v_type == VAR_DICT) |
100 | 837 { |
838 if (len == -1) | |
839 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
840 // "[key]": get key from "var1" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
841 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
|
842 if (key == NULL) |
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
843 { |
100 | 844 clear_tv(&var1); |
110 | 845 return NULL; |
846 } | |
847 } | |
117 | 848 lp->ll_list = NULL; |
849 lp->ll_dict = lp->ll_tv->vval.v_dict; | |
121 | 850 lp->ll_di = dict_find(lp->ll_dict, key, len); |
2739 | 851 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
852 // 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
|
853 // 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
|
854 // g: dictionary). Disallow overwriting a builtin function. |
3687 | 855 if (rettv != NULL && lp->ll_dict->dv_scope != 0) |
856 { | |
857 int prevval; | |
858 int wrong; | |
859 | |
860 if (len != -1) | |
861 { | |
862 prevval = key[len]; | |
863 key[len] = NUL; | |
864 } | |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
865 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
866 prevval = 0; // avoid compiler warning |
3687 | 867 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE |
868 && rettv->v_type == VAR_FUNC | |
2739 | 869 && var_check_func_name(key, lp->ll_di == NULL)) |
3687 | 870 || !valid_varname(key); |
871 if (len != -1) | |
872 key[len] = prevval; | |
873 if (wrong) | |
2739 | 874 return NULL; |
875 } | |
876 | |
110 | 877 if (lp->ll_di == NULL) |
100 | 878 { |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
879 // 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
|
880 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
|
881 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht()) |
2739 | 882 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
883 semsg(_(e_illvar), name); |
16013
93b08b92a049
patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents:
15969
diff
changeset
|
884 clear_tv(&var1); |
2739 | 885 return NULL; |
886 } | |
887 | |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
888 // Key does not exist in dict: may need to add it. |
110 | 889 if (*p == '[' || *p == '.' || unlet) |
890 { | |
891 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
892 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
|
893 clear_tv(&var1); |
110 | 894 return NULL; |
100 | 895 } |
896 if (len == -1) | |
110 | 897 lp->ll_newkey = vim_strsave(key); |
100 | 898 else |
110 | 899 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
|
900 clear_tv(&var1); |
110 | 901 if (lp->ll_newkey == NULL) |
100 | 902 p = NULL; |
903 break; | |
904 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
905 // 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
|
906 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
|
907 && 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
|
908 { |
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
909 clear_tv(&var1); |
2739 | 910 return NULL; |
10910
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
911 } |
2739 | 912 |
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
|
913 clear_tv(&var1); |
110 | 914 lp->ll_tv = &lp->ll_di->di_tv; |
100 | 915 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
916 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
|
917 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
918 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
|
919 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
920 /* |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
921 * 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
|
922 */ |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
923 if (empty1) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
924 lp->ll_n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
925 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
926 // is number or string |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
927 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
|
928 clear_tv(&var1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
929 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
930 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
|
931 || lp->ll_n1 > bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
932 || (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
|
933 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
934 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
935 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
|
936 clear_tv(&var2); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
937 return NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
938 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
939 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
|
940 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
941 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
|
942 clear_tv(&var2); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
943 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
|
944 || lp->ll_n2 >= bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
945 || 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
|
946 { |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
947 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
948 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
|
949 return NULL; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
950 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
951 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
952 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
|
953 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
|
954 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
955 } |
100 | 956 else |
957 { | |
958 /* | |
959 * Get the number and item for the only or first index of the List. | |
960 */ | |
961 if (empty1) | |
110 | 962 lp->ll_n1 = 0; |
100 | 963 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
964 // 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
|
965 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
|
966 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
|
967 |
117 | 968 lp->ll_dict = NULL; |
110 | 969 lp->ll_list = lp->ll_tv->vval.v_list; |
970 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
971 if (lp->ll_li == NULL) | |
972 { | |
842 | 973 if (lp->ll_n1 < 0) |
974 { | |
975 lp->ll_n1 = 0; | |
976 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
977 } | |
978 } | |
979 if (lp->ll_li == NULL) | |
980 { | |
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
|
981 clear_tv(&var2); |
2772 | 982 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
983 semsg(_(e_listidx), lp->ll_n1); |
110 | 984 return NULL; |
100 | 985 } |
986 | |
987 /* | |
988 * May need to find the item or absolute index for the second | |
989 * index of a range. | |
110 | 990 * When no index given: "lp->ll_empty2" is TRUE. |
991 * Otherwise "lp->ll_n2" is set to the second index. | |
100 | 992 */ |
110 | 993 if (lp->ll_range && !lp->ll_empty2) |
994 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
995 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
|
996 // is number or string |
88 | 997 clear_tv(&var2); |
110 | 998 if (lp->ll_n2 < 0) |
999 { | |
1000 ni = list_find(lp->ll_list, lp->ll_n2); | |
100 | 1001 if (ni == NULL) |
2772 | 1002 { |
1003 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1004 semsg(_(e_listidx), lp->ll_n2); |
110 | 1005 return NULL; |
2772 | 1006 } |
110 | 1007 lp->ll_n2 = list_idx_of_item(lp->ll_list, ni); |
1008 } | |
1009 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1010 // Check that lp->ll_n2 isn't before lp->ll_n1. |
110 | 1011 if (lp->ll_n1 < 0) |
1012 lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li); | |
1013 if (lp->ll_n2 < lp->ll_n1) | |
2772 | 1014 { |
1015 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1016 semsg(_(e_listidx), lp->ll_n2); |
110 | 1017 return NULL; |
2772 | 1018 } |
110 | 1019 } |
1020 | |
1021 lp->ll_tv = &lp->ll_li->li_tv; | |
1022 } | |
1023 } | |
1024 | |
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
|
1025 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
|
1026 lp->ll_name_end = p; |
110 | 1027 return p; |
1028 } | |
1029 | |
1030 /* | |
137 | 1031 * Clear lval "lp" that was filled by get_lval(). |
110 | 1032 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1033 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1034 clear_lval(lval_T *lp) |
110 | 1035 { |
1036 vim_free(lp->ll_exp_name); | |
1037 vim_free(lp->ll_newkey); | |
1038 } | |
1039 | |
1040 /* | |
151 | 1041 * Set a variable that was parsed by get_lval() to "rettv". |
110 | 1042 * "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
|
1043 * "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
|
1044 * "%" for "%=", "." for ".=" or "=" for "=". |
117 | 1045 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
1046 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1047 set_var_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1048 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1049 char_u *endp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1050 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1051 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
|
1052 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
|
1053 char_u *op) |
110 | 1054 { |
1055 int cc; | |
137 | 1056 listitem_T *ri; |
1057 dictitem_T *di; | |
110 | 1058 |
1059 if (lp->ll_tv == NULL) | |
1060 { | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1061 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
|
1062 *endp = NUL; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1063 if (lp->ll_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1064 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1065 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
|
1066 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1067 if (op != NULL && *op != '=') |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1068 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1069 semsg(_(e_letwrong), op); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1070 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1071 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1072 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1073 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
|
1074 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1075 int il, ir; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1076 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1077 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1078 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
|
1079 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1080 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
|
1081 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1082 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
|
1083 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1084 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1085 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1086 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
|
1087 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1088 ir = 0; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1089 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
|
1090 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
|
1091 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
|
1092 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1093 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1094 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1095 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
|
1096 if (!error) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1097 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1098 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
|
1099 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1100 // 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
|
1101 // the end is an error otherwise. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1102 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
|
1103 || (lp->ll_n1 == gap->ga_len |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1104 && 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
|
1105 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1106 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
|
1107 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
|
1108 ++gap->ga_len; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1109 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1110 // 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
|
1111 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1112 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1113 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1114 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
|
1115 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1116 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
|
1117 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1118 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
|
1119 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1120 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
|
1121 *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
|
1122 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1123 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1124 |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1125 // 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
|
1126 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
|
1127 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
|
1128 &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
|
1129 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1130 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
|
1131 || (!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
|
1132 && !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
|
1133 && 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
|
1134 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
|
1135 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
|
1136 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1137 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1138 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1139 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
|
1140 *endp = cc; |
110 | 1141 } |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1142 else if (var_check_lock(lp->ll_newkey == NULL |
151 | 1143 ? lp->ll_tv->v_lock |
6773 | 1144 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE)) |
151 | 1145 ; |
110 | 1146 else if (lp->ll_range) |
1147 { | |
6166 | 1148 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
|
1149 int ll_n1 = lp->ll_n1; |
6166 | 1150 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1151 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
|
1152 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1153 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
|
1154 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1155 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1156 |
6166 | 1157 /* |
1158 * Check whether any of the list items is locked | |
1159 */ | |
6422 | 1160 for (ri = rettv->vval.v_list->lv_first; ri != NULL && ll_li != NULL; ) |
6166 | 1161 { |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1162 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE)) |
6166 | 1163 return; |
1164 ri = ri->li_next; | |
1165 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == ll_n1)) | |
1166 break; | |
1167 ll_li = ll_li->li_next; | |
1168 ++ll_n1; | |
1169 } | |
1170 | |
110 | 1171 /* |
1172 * Assign the List values to the list items. | |
1173 */ | |
1174 for (ri = rettv->vval.v_list->lv_first; ri != NULL; ) | |
1175 { | |
117 | 1176 if (op != NULL && *op != '=') |
1177 tv_op(&lp->ll_li->li_tv, &ri->li_tv, op); | |
1178 else | |
1179 { | |
1180 clear_tv(&lp->ll_li->li_tv); | |
1181 copy_tv(&ri->li_tv, &lp->ll_li->li_tv); | |
1182 } | |
110 | 1183 ri = ri->li_next; |
1184 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1)) | |
1185 break; | |
1186 if (lp->ll_li->li_next == NULL) | |
1187 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1188 // Need to add an empty item. |
533 | 1189 if (list_append_number(lp->ll_list, 0) == FAIL) |
110 | 1190 { |
1191 ri = NULL; | |
88 | 1192 break; |
110 | 1193 } |
1194 } | |
1195 lp->ll_li = lp->ll_li->li_next; | |
1196 ++lp->ll_n1; | |
1197 } | |
1198 if (ri != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1199 emsg(_("E710: List value has more items than target")); |
117 | 1200 else if (lp->ll_empty2 |
1201 ? (lp->ll_li != NULL && lp->ll_li->li_next != NULL) | |
110 | 1202 : 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
|
1203 emsg(_("E711: List value has not enough items")); |
110 | 1204 } |
1205 else | |
1206 { | |
1207 /* | |
1208 * Assign to a List or Dictionary item. | |
1209 */ | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1210 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
|
1211 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1212 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
|
1213 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1214 } |
110 | 1215 if (lp->ll_newkey != NULL) |
1216 { | |
117 | 1217 if (op != NULL && *op != '=') |
1218 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1219 semsg(_(e_letwrong), op); |
117 | 1220 return; |
1221 } | |
1222 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1223 // Need to add an item to the Dictionary. |
121 | 1224 di = dictitem_alloc(lp->ll_newkey); |
110 | 1225 if (di == NULL) |
1226 return; | |
121 | 1227 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL) |
1228 { | |
1229 vim_free(di); | |
1230 return; | |
1231 } | |
110 | 1232 lp->ll_tv = &di->di_tv; |
1233 } | |
117 | 1234 else if (op != NULL && *op != '=') |
1235 { | |
1236 tv_op(lp->ll_tv, rettv, op); | |
1237 return; | |
1238 } | |
110 | 1239 else |
1240 clear_tv(lp->ll_tv); | |
1241 | |
1242 /* | |
1243 * Assign the value to the variable or list item. | |
1244 */ | |
1245 if (copy) | |
1246 copy_tv(rettv, lp->ll_tv); | |
1247 else | |
1248 { | |
1249 *lp->ll_tv = *rettv; | |
156 | 1250 lp->ll_tv->v_lock = 0; |
110 | 1251 init_tv(rettv); |
1252 } | |
1253 } | |
7 | 1254 } |
1255 | |
76 | 1256 /* |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1257 * 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
|
1258 * and "tv1 .= tv2" |
117 | 1259 * Returns OK or FAIL. |
1260 */ | |
1261 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1262 tv_op(typval_T *tv1, typval_T *tv2, char_u *op) |
117 | 1263 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1264 varnumber_T n; |
117 | 1265 char_u numbuf[NUMBUFLEN]; |
1266 char_u *s; | |
1267 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1268 // 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
|
1269 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
|
1270 && tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL) |
117 | 1271 { |
1272 switch (tv1->v_type) | |
1273 { | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1274 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
|
1275 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
|
1276 case VAR_VOID: |
117 | 1277 case VAR_DICT: |
1278 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1279 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
|
1280 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1281 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1282 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
1283 case VAR_CHANNEL: |
117 | 1284 break; |
1285 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1286 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1287 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
|
1288 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1289 // BLOB += BLOB |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1290 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
|
1291 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1292 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
|
1293 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
|
1294 int i, len = blob_len(b2); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1295 for (i = 0; i < len; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1296 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
|
1297 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1298 return OK; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1299 |
117 | 1300 case VAR_LIST: |
1301 if (*op != '+' || tv2->v_type != VAR_LIST) | |
1302 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1303 // List += List |
117 | 1304 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL) |
1305 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL); | |
1306 return OK; | |
1307 | |
1308 case VAR_NUMBER: | |
1309 case VAR_STRING: | |
1310 if (tv2->v_type == VAR_LIST) | |
1311 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1312 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
|
1313 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1314 // 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
|
1315 n = tv_get_number(tv1); |
1624 | 1316 #ifdef FEAT_FLOAT |
1317 if (tv2->v_type == VAR_FLOAT) | |
1318 { | |
1319 float_T f = n; | |
1320 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1321 if (*op == '%') |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1322 break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1323 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1324 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1325 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
|
1326 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
|
1327 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
|
1328 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
|
1329 } |
1624 | 1330 clear_tv(tv1); |
1331 tv1->v_type = VAR_FLOAT; | |
1332 tv1->vval.v_float = f; | |
1333 } | |
117 | 1334 else |
1624 | 1335 #endif |
1336 { | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1337 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1338 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1339 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
|
1340 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
|
1341 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
|
1342 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
|
1343 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
|
1344 } |
1624 | 1345 clear_tv(tv1); |
1346 tv1->v_type = VAR_NUMBER; | |
1347 tv1->vval.v_number = n; | |
1348 } | |
1349 } | |
1350 else | |
1351 { | |
1352 if (tv2->v_type == VAR_FLOAT) | |
1353 break; | |
1354 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1355 // str .= str |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1356 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
|
1357 s = concat_str(s, tv_get_string_buf(tv2, numbuf)); |
117 | 1358 clear_tv(tv1); |
1359 tv1->v_type = VAR_STRING; | |
1360 tv1->vval.v_string = s; | |
1361 } | |
1362 return OK; | |
1624 | 1363 |
1364 case VAR_FLOAT: | |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1365 #ifdef FEAT_FLOAT |
1624 | 1366 { |
1367 float_T f; | |
1368 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1369 if (*op == '%' || *op == '.' |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1370 || (tv2->v_type != VAR_FLOAT |
1624 | 1371 && tv2->v_type != VAR_NUMBER |
1372 && tv2->v_type != VAR_STRING)) | |
1373 break; | |
1374 if (tv2->v_type == VAR_FLOAT) | |
1375 f = tv2->vval.v_float; | |
1376 else | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1377 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
|
1378 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1379 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1380 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
|
1381 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
|
1382 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
|
1383 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
|
1384 } |
1624 | 1385 } |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1386 #endif |
1624 | 1387 return OK; |
117 | 1388 } |
1389 } | |
1390 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1391 semsg(_(e_letwrong), op); |
117 | 1392 return FAIL; |
1393 } | |
1394 | |
1395 /* | |
76 | 1396 * Evaluate the expression used in a ":for var in expr" command. |
1397 * "arg" points to "var". | |
1398 * Set "*errp" to TRUE for an error, FALSE otherwise; | |
1399 * Return a pointer that holds the info. Null when there is an error. | |
1400 */ | |
1401 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1402 eval_for_line( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1403 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1404 int *errp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1405 char_u **nextcmdp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1406 int skip) |
76 | 1407 { |
137 | 1408 forinfo_T *fi; |
76 | 1409 char_u *expr; |
137 | 1410 typval_T tv; |
1411 list_T *l; | |
76 | 1412 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1413 *errp = TRUE; // default: there is an error |
76 | 1414 |
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
|
1415 fi = ALLOC_CLEAR_ONE(forinfo_T); |
76 | 1416 if (fi == NULL) |
1417 return NULL; | |
1418 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1419 expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon); |
76 | 1420 if (expr == NULL) |
1421 return fi; | |
1422 | |
1423 expr = skipwhite(expr); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1424 if (expr[0] != 'i' || expr[1] != 'n' || !VIM_ISWHITE(expr[2])) |
76 | 1425 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1426 emsg(_(e_missing_in)); |
76 | 1427 return fi; |
1428 } | |
1429 | |
1430 if (skip) | |
1431 ++emsg_skip; | |
1432 if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK) | |
1433 { | |
1434 *errp = FALSE; | |
1435 if (!skip) | |
1436 { | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1437 if (tv.v_type == VAR_LIST) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1438 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1439 l = tv.vval.v_list; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1440 if (l == NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1441 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1442 // 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
|
1443 clear_tv(&tv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1444 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1445 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1446 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1447 // Need a real list here. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1448 range_list_materialize(l); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1449 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1450 // 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
|
1451 // the list being used in "tv". |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1452 fi->fi_list = l; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1453 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
|
1454 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
|
1455 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1456 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1457 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
|
1458 { |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1459 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
|
1460 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
|
1461 { |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1462 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
|
1463 |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1464 // 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
|
1465 // 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
|
1466 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
|
1467 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
|
1468 } |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1469 clear_tv(&tv); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1470 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1471 else |
359 | 1472 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1473 emsg(_(e_listreq)); |
359 | 1474 clear_tv(&tv); |
1475 } | |
76 | 1476 } |
1477 } | |
1478 if (skip) | |
1479 --emsg_skip; | |
1480 | |
1481 return fi; | |
1482 } | |
1483 | |
1484 /* | |
1485 * Use the first item in a ":for" list. Advance to the next. | |
1486 * Assign the values to the variable (list). "arg" points to the first one. | |
1487 * Return TRUE when a valid item was found, FALSE when at end of list or | |
1488 * something wrong. | |
1489 */ | |
1490 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1491 next_for_item(void *fi_void, char_u *arg) |
76 | 1492 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
1493 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1494 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
|
1495 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
|
1496 LET_NO_COMMAND : 0; |
137 | 1497 listitem_T *item; |
76 | 1498 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1499 if (fi->fi_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1500 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1501 typval_T tv; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1502 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1503 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
|
1504 return FALSE; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1505 tv.v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1506 tv.v_lock = VAR_FIXED; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1507 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
|
1508 ++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
|
1509 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
|
1510 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
|
1511 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1512 |
76 | 1513 item = fi->fi_lw.lw_item; |
1514 if (item == NULL) | |
1515 result = FALSE; | |
1516 else | |
1517 { | |
1518 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
|
1519 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
|
1520 fi->fi_varcount, flag, NULL) == OK); |
76 | 1521 } |
1522 return result; | |
1523 } | |
1524 | |
1525 /* | |
1526 * Free the structure used to store info used by ":for". | |
1527 */ | |
1528 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1529 free_for_info(void *fi_void) |
76 | 1530 { |
137 | 1531 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1532 |
92 | 1533 if (fi != NULL && fi->fi_list != NULL) |
359 | 1534 { |
76 | 1535 list_rem_watch(fi->fi_list, &fi->fi_lw); |
359 | 1536 list_unref(fi->fi_list); |
1537 } | |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
1538 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
|
1539 blob_unref(fi->fi_blob); |
76 | 1540 vim_free(fi); |
1541 } | |
1542 | |
7 | 1543 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1544 set_context_for_expression( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1545 expand_T *xp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1546 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1547 cmdidx_T cmdidx) |
7 | 1548 { |
1549 int got_eq = FALSE; | |
1550 int c; | |
76 | 1551 char_u *p; |
1552 | |
18713
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1553 if (cmdidx == CMD_let || cmdidx == CMD_const) |
76 | 1554 { |
1555 xp->xp_context = EXPAND_USER_VARS; | |
159 | 1556 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) |
76 | 1557 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1558 // ":let var1 var2 ...": find last space. |
159 | 1559 for (p = arg + STRLEN(arg); p >= arg; ) |
76 | 1560 { |
1561 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
|
1562 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
|
1563 if (VIM_ISWHITE(*p)) |
76 | 1564 break; |
1565 } | |
1566 return; | |
1567 } | |
1568 } | |
1569 else | |
1570 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS | |
1571 : EXPAND_EXPRESSION; | |
7 | 1572 while ((xp->xp_pattern = vim_strpbrk(arg, |
1573 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) | |
1574 { | |
1575 c = *xp->xp_pattern; | |
1576 if (c == '&') | |
1577 { | |
1578 c = xp->xp_pattern[1]; | |
1579 if (c == '&') | |
1580 { | |
1581 ++xp->xp_pattern; | |
1582 xp->xp_context = cmdidx != CMD_let || got_eq | |
1583 ? EXPAND_EXPRESSION : EXPAND_NOTHING; | |
1584 } | |
1585 else if (c != ' ') | |
201 | 1586 { |
7 | 1587 xp->xp_context = EXPAND_SETTINGS; |
201 | 1588 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') |
1589 xp->xp_pattern += 2; | |
1590 | |
1591 } | |
7 | 1592 } |
1593 else if (c == '$') | |
1594 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1595 // environment variable |
7 | 1596 xp->xp_context = EXPAND_ENV_VARS; |
1597 } | |
1598 else if (c == '=') | |
1599 { | |
1600 got_eq = TRUE; | |
1601 xp->xp_context = EXPAND_EXPRESSION; | |
1602 } | |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1603 else if (c == '#' |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1604 && xp->xp_context == EXPAND_EXPRESSION) |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1605 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1606 // Autoload function/variable contains '#'. |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1607 break; |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1608 } |
6367 | 1609 else if ((c == '<' || c == '#') |
7 | 1610 && xp->xp_context == EXPAND_FUNCTIONS |
1611 && vim_strchr(xp->xp_pattern, '(') == NULL) | |
1612 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1613 // Function name can start with "<SNR>" and contain '#'. |
7 | 1614 break; |
1615 } | |
1616 else if (cmdidx != CMD_let || got_eq) | |
1617 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1618 if (c == '"') // string |
7 | 1619 { |
1620 while ((c = *++xp->xp_pattern) != NUL && c != '"') | |
1621 if (c == '\\' && xp->xp_pattern[1] != NUL) | |
1622 ++xp->xp_pattern; | |
1623 xp->xp_context = EXPAND_NOTHING; | |
1624 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1625 else if (c == '\'') // literal string |
7 | 1626 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1627 // Trick: '' is like stopping and starting a literal string. |
7 | 1628 while ((c = *++xp->xp_pattern) != NUL && c != '\'') |
1629 /* skip */ ; | |
1630 xp->xp_context = EXPAND_NOTHING; | |
1631 } | |
1632 else if (c == '|') | |
1633 { | |
1634 if (xp->xp_pattern[1] == '|') | |
1635 { | |
1636 ++xp->xp_pattern; | |
1637 xp->xp_context = EXPAND_EXPRESSION; | |
1638 } | |
1639 else | |
1640 xp->xp_context = EXPAND_COMMANDS; | |
1641 } | |
1642 else | |
1643 xp->xp_context = EXPAND_EXPRESSION; | |
1644 } | |
1645 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1646 // 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
|
1647 // anyway. |
76 | 1648 xp->xp_context = EXPAND_EXPRESSION; |
7 | 1649 arg = xp->xp_pattern; |
1650 if (*arg != NUL) | |
1651 while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) | |
1652 /* skip */ ; | |
1653 } | |
1654 xp->xp_pattern = arg; | |
1655 } | |
1656 | |
1657 /* | |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1658 * Return TRUE if "pat" matches "text". |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1659 * 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
|
1660 */ |
17377
cb008de2a6ec
patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17375
diff
changeset
|
1661 int |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1662 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
|
1663 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1664 int matches = FALSE; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1665 char_u *save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1666 regmatch_T regmatch; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1667 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1668 // avoid 'l' flag in 'cpoptions' |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1669 save_cpo = p_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1670 p_cpo = (char_u *)""; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1671 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
|
1672 if (regmatch.regprog != NULL) |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1673 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1674 regmatch.rm_ic = ic; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1675 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
|
1676 vim_regfree(regmatch.regprog); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1677 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1678 p_cpo = save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1679 return matches; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1680 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1681 |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1682 /* |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1683 * 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
|
1684 * "expr->name(arg)". |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1685 * Returns OK or FAIL. |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1686 */ |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1687 static int |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1688 eval_func( |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1689 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
|
1690 char_u *name, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1691 int name_len, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1692 typval_T *rettv, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1693 int evaluate, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1694 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
|
1695 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1696 char_u *s = name; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1697 int len = name_len; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1698 partial_T *partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1699 int ret = OK; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1700 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1701 if (!evaluate) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1702 check_vars(s, len); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1703 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1704 // 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
|
1705 // use its contents. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1706 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
|
1707 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1708 // 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
|
1709 // the name invalid. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1710 s = vim_strsave(s); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1711 if (s == NULL) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1712 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1713 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1714 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1715 funcexe_T funcexe; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1716 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1717 // Invoke the function. |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1718 CLEAR_FIELD(funcexe); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1719 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
|
1720 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
|
1721 funcexe.evaluate = evaluate; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1722 funcexe.partial = partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1723 funcexe.basetv = basetv; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1724 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
|
1725 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1726 vim_free(s); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1727 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1728 // 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
|
1729 // 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
|
1730 // 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
|
1731 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
|
1732 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1733 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
|
1734 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
|
1735 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1736 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1737 // 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
|
1738 // 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
|
1739 // 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
|
1740 if (evaluate && aborting()) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1741 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1742 if (ret == OK) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1743 clear_tv(rettv); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1744 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1745 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1746 return ret; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1747 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1748 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1749 /* |
7 | 1750 * The "evaluate" argument: When FALSE, the argument is only parsed but not |
71 | 1751 * executed. The function may return OK, but the rettv will be of type |
7 | 1752 * VAR_UNKNOWN. The function still returns FAIL for a syntax error. |
1753 */ | |
1754 | |
1755 /* | |
1756 * Handle zero level expression. | |
1757 * This calls eval1() and handles error message and nextcmd. | |
71 | 1758 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. |
533 | 1759 * Note: "rettv.v_lock" is not set. |
7 | 1760 * Return OK or FAIL. |
1761 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1762 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1763 eval0( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1764 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1765 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1766 char_u **nextcmd, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1767 int evaluate) |
7 | 1768 { |
1769 int ret; | |
1770 char_u *p; | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1771 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
|
1772 int called_emsg_before = called_emsg; |
7 | 1773 |
1774 p = skipwhite(arg); | |
71 | 1775 ret = eval1(&p, rettv, evaluate); |
7 | 1776 if (ret == FAIL || !ends_excmd(*p)) |
1777 { | |
1778 if (ret != FAIL) | |
71 | 1779 clear_tv(rettv); |
7 | 1780 /* |
1781 * Report the invalid expression unless the expression evaluation has | |
1782 * 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
|
1783 * 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
|
1784 * Also check called_emsg for when using assert_fails(). |
7 | 1785 */ |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1786 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
|
1787 && 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
|
1788 semsg(_(e_invexpr2), arg); |
7 | 1789 ret = FAIL; |
1790 } | |
1791 if (nextcmd != NULL) | |
1792 *nextcmd = check_nextcmd(p); | |
1793 | |
1794 return ret; | |
1795 } | |
1796 | |
1797 /* | |
1798 * Handle top level expression: | |
1800 | 1799 * expr2 ? expr1 : expr1 |
7 | 1800 * |
1801 * "arg" must point to the first non-white of the expression. | |
1802 * "arg" is advanced to the next non-white after the recognized expression. | |
1803 * | |
533 | 1804 * Note: "rettv.v_lock" is not set. |
1805 * | |
7 | 1806 * Return OK or FAIL. |
1807 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
1808 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1809 eval1(char_u **arg, typval_T *rettv, int evaluate) |
7 | 1810 { |
1811 int result; | |
137 | 1812 typval_T var2; |
7 | 1813 |
1814 /* | |
1815 * Get the first variable. | |
1816 */ | |
71 | 1817 if (eval2(arg, rettv, evaluate) == FAIL) |
7 | 1818 return FAIL; |
1819 | |
1820 if ((*arg)[0] == '?') | |
1821 { | |
1822 result = FALSE; | |
1823 if (evaluate) | |
1824 { | |
323 | 1825 int error = FALSE; |
1826 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1827 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 1828 result = TRUE; |
71 | 1829 clear_tv(rettv); |
323 | 1830 if (error) |
1831 return FAIL; | |
7 | 1832 } |
1833 | |
1834 /* | |
1835 * Get the second variable. | |
1836 */ | |
1837 *arg = skipwhite(*arg + 1); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1838 if (eval1(arg, rettv, evaluate && result) == FAIL) // recursive! |
7 | 1839 return FAIL; |
1840 | |
1841 /* | |
1842 * Check for the ":". | |
1843 */ | |
1844 if ((*arg)[0] != ':') | |
1845 { | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1846 emsg(_(e_missing_colon)); |
7 | 1847 if (evaluate && result) |
71 | 1848 clear_tv(rettv); |
7 | 1849 return FAIL; |
1850 } | |
1851 | |
1852 /* | |
1853 * Get the third variable. | |
1854 */ | |
1855 *arg = skipwhite(*arg + 1); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1856 if (eval1(arg, &var2, evaluate && !result) == FAIL) // recursive! |
7 | 1857 { |
1858 if (evaluate && result) | |
71 | 1859 clear_tv(rettv); |
7 | 1860 return FAIL; |
1861 } | |
1862 if (evaluate && !result) | |
71 | 1863 *rettv = var2; |
7 | 1864 } |
1865 | |
1866 return OK; | |
1867 } | |
1868 | |
1869 /* | |
1870 * Handle first level expression: | |
1871 * expr2 || expr2 || expr2 logical OR | |
1872 * | |
1873 * "arg" must point to the first non-white of the expression. | |
1874 * "arg" is advanced to the next non-white after the recognized expression. | |
1875 * | |
1876 * Return OK or FAIL. | |
1877 */ | |
1878 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1879 eval2(char_u **arg, typval_T *rettv, int evaluate) |
7 | 1880 { |
137 | 1881 typval_T var2; |
7 | 1882 long result; |
1883 int first; | |
323 | 1884 int error = FALSE; |
7 | 1885 |
1886 /* | |
1887 * Get the first variable. | |
1888 */ | |
71 | 1889 if (eval3(arg, rettv, evaluate) == FAIL) |
7 | 1890 return FAIL; |
1891 | |
1892 /* | |
1893 * Repeat until there is no following "||". | |
1894 */ | |
1895 first = TRUE; | |
1896 result = FALSE; | |
1897 while ((*arg)[0] == '|' && (*arg)[1] == '|') | |
1898 { | |
1899 if (evaluate && first) | |
1900 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1901 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 1902 result = TRUE; |
71 | 1903 clear_tv(rettv); |
323 | 1904 if (error) |
1905 return FAIL; | |
7 | 1906 first = FALSE; |
1907 } | |
1908 | |
1909 /* | |
1910 * Get the second variable. | |
1911 */ | |
1912 *arg = skipwhite(*arg + 2); | |
1913 if (eval3(arg, &var2, evaluate && !result) == FAIL) | |
1914 return FAIL; | |
1915 | |
1916 /* | |
1917 * Compute the result. | |
1918 */ | |
1919 if (evaluate && !result) | |
1920 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1921 if (tv_get_number_chk(&var2, &error) != 0) |
7 | 1922 result = TRUE; |
71 | 1923 clear_tv(&var2); |
323 | 1924 if (error) |
1925 return FAIL; | |
7 | 1926 } |
1927 if (evaluate) | |
1928 { | |
71 | 1929 rettv->v_type = VAR_NUMBER; |
1930 rettv->vval.v_number = result; | |
7 | 1931 } |
1932 } | |
1933 | |
1934 return OK; | |
1935 } | |
1936 | |
1937 /* | |
1938 * Handle second level expression: | |
1939 * expr3 && expr3 && expr3 logical AND | |
1940 * | |
1941 * "arg" must point to the first non-white of the expression. | |
1942 * "arg" is advanced to the next non-white after the recognized expression. | |
1943 * | |
1944 * Return OK or FAIL. | |
1945 */ | |
1946 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1947 eval3(char_u **arg, typval_T *rettv, int evaluate) |
7 | 1948 { |
137 | 1949 typval_T var2; |
7 | 1950 long result; |
1951 int first; | |
323 | 1952 int error = FALSE; |
7 | 1953 |
1954 /* | |
1955 * Get the first variable. | |
1956 */ | |
71 | 1957 if (eval4(arg, rettv, evaluate) == FAIL) |
7 | 1958 return FAIL; |
1959 | |
1960 /* | |
1961 * Repeat until there is no following "&&". | |
1962 */ | |
1963 first = TRUE; | |
1964 result = TRUE; | |
1965 while ((*arg)[0] == '&' && (*arg)[1] == '&') | |
1966 { | |
1967 if (evaluate && first) | |
1968 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1969 if (tv_get_number_chk(rettv, &error) == 0) |
7 | 1970 result = FALSE; |
71 | 1971 clear_tv(rettv); |
323 | 1972 if (error) |
1973 return FAIL; | |
7 | 1974 first = FALSE; |
1975 } | |
1976 | |
1977 /* | |
1978 * Get the second variable. | |
1979 */ | |
1980 *arg = skipwhite(*arg + 2); | |
1981 if (eval4(arg, &var2, evaluate && result) == FAIL) | |
1982 return FAIL; | |
1983 | |
1984 /* | |
1985 * Compute the result. | |
1986 */ | |
1987 if (evaluate && result) | |
1988 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1989 if (tv_get_number_chk(&var2, &error) == 0) |
7 | 1990 result = FALSE; |
71 | 1991 clear_tv(&var2); |
323 | 1992 if (error) |
1993 return FAIL; | |
7 | 1994 } |
1995 if (evaluate) | |
1996 { | |
71 | 1997 rettv->v_type = VAR_NUMBER; |
1998 rettv->vval.v_number = result; | |
7 | 1999 } |
2000 } | |
2001 | |
2002 return OK; | |
2003 } | |
2004 | |
2005 /* | |
2006 * Handle third level expression: | |
2007 * var1 == var2 | |
2008 * var1 =~ var2 | |
2009 * var1 != var2 | |
2010 * var1 !~ var2 | |
2011 * var1 > var2 | |
2012 * var1 >= var2 | |
2013 * var1 < var2 | |
2014 * var1 <= var2 | |
80 | 2015 * var1 is var2 |
2016 * var1 isnot var2 | |
7 | 2017 * |
2018 * "arg" must point to the first non-white of the expression. | |
2019 * "arg" is advanced to the next non-white after the recognized expression. | |
2020 * | |
2021 * Return OK or FAIL. | |
2022 */ | |
2023 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2024 eval4(char_u **arg, typval_T *rettv, int evaluate) |
7 | 2025 { |
137 | 2026 typval_T var2; |
7 | 2027 char_u *p; |
2028 int i; | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2029 exptype_T type = EXPR_UNKNOWN; |
7 | 2030 int len = 2; |
2031 int ic; | |
2032 | |
2033 /* | |
2034 * Get the first variable. | |
2035 */ | |
71 | 2036 if (eval5(arg, rettv, evaluate) == FAIL) |
7 | 2037 return FAIL; |
2038 | |
2039 p = *arg; | |
2040 switch (p[0]) | |
2041 { | |
2042 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
|
2043 type = EXPR_EQUAL; |
7 | 2044 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
|
2045 type = EXPR_MATCH; |
7 | 2046 break; |
2047 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
|
2048 type = EXPR_NEQUAL; |
7 | 2049 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
|
2050 type = EXPR_NOMATCH; |
7 | 2051 break; |
2052 case '>': if (p[1] != '=') | |
2053 { | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2054 type = EXPR_GREATER; |
7 | 2055 len = 1; |
2056 } | |
2057 else | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2058 type = EXPR_GEQUAL; |
7 | 2059 break; |
2060 case '<': if (p[1] != '=') | |
2061 { | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2062 type = EXPR_SMALLER; |
7 | 2063 len = 1; |
2064 } | |
2065 else | |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2066 type = EXPR_SEQUAL; |
7 | 2067 break; |
80 | 2068 case 'i': if (p[1] == 's') |
2069 { | |
2070 if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') | |
2071 len = 5; | |
7064
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2072 i = p[len]; |
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2073 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
|
2074 type = len == 2 ? EXPR_IS : EXPR_ISNOT; |
80 | 2075 } |
2076 break; | |
7 | 2077 } |
2078 | |
2079 /* | |
1624 | 2080 * If there is a comparative operator, use it. |
7 | 2081 */ |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
2082 if (type != EXPR_UNKNOWN) |
7 | 2083 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2084 // extra question mark appended: ignore case |
7 | 2085 if (p[len] == '?') |
2086 { | |
2087 ic = TRUE; | |
2088 ++len; | |
2089 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2090 // extra '#' appended: match case |
7 | 2091 else if (p[len] == '#') |
2092 { | |
2093 ic = FALSE; | |
2094 ++len; | |
2095 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2096 // nothing appended: use 'ignorecase' |
7 | 2097 else |
2098 ic = p_ic; | |
2099 | |
2100 /* | |
2101 * Get the second variable. | |
2102 */ | |
2103 *arg = skipwhite(p + len); | |
2104 if (eval5(arg, &var2, evaluate) == FAIL) | |
2105 { | |
71 | 2106 clear_tv(rettv); |
7 | 2107 return FAIL; |
2108 } | |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2109 if (evaluate) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2110 { |
18966
6bd715870e32
patch 8.2.0044: expression type is used inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
18939
diff
changeset
|
2111 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
|
2112 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2113 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
|
2114 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
|
2115 } |
7 | 2116 } |
2117 | |
2118 return OK; | |
2119 } | |
2120 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2121 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2122 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
|
2123 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2124 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
|
2125 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
|
2126 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
|
2127 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2128 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2129 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
|
2130 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2131 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
|
2132 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
|
2133 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
|
2134 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
|
2135 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2136 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
|
2137 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
|
2138 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2139 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2140 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2141 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2142 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
|
2143 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2144 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
|
2145 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2146 // concatenate Lists |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2147 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
|
2148 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2149 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
|
2150 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
|
2151 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2152 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2153 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
|
2154 *tv1 = var3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2155 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2156 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2157 |
7 | 2158 /* |
2159 * Handle fourth level expression: | |
2160 * + number addition | |
2161 * - number subtraction | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2162 * . 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
|
2163 * .. string concatenation |
7 | 2164 * |
2165 * "arg" must point to the first non-white of the expression. | |
2166 * "arg" is advanced to the next non-white after the recognized expression. | |
2167 * | |
2168 * Return OK or FAIL. | |
2169 */ | |
2170 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2171 eval5(char_u **arg, typval_T *rettv, int evaluate) |
7 | 2172 { |
137 | 2173 typval_T var2; |
7 | 2174 int op; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2175 varnumber_T n1, n2; |
1624 | 2176 #ifdef FEAT_FLOAT |
2177 float_T f1 = 0, f2 = 0; | |
2178 #endif | |
7 | 2179 char_u *s1, *s2; |
2180 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | |
2181 char_u *p; | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2182 int concat; |
7 | 2183 |
2184 /* | |
2185 * Get the first variable. | |
2186 */ | |
1655 | 2187 if (eval6(arg, rettv, evaluate, FALSE) == FAIL) |
7 | 2188 return FAIL; |
2189 | |
2190 /* | |
2191 * Repeat computing, until no '+', '-' or '.' is following. | |
2192 */ | |
2193 for (;;) | |
2194 { | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2195 // "." is only string concatenation when scriptversion is 1 |
7 | 2196 op = **arg; |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2197 concat = op == '.' |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2198 && (*(*arg + 1) == '.' || 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
|
2199 if (op != '+' && op != '-' && !concat) |
7 | 2200 break; |
2201 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2202 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
|
2203 && rettv->v_type != VAR_BLOB)) |
1624 | 2204 #ifdef FEAT_FLOAT |
2205 && (op == '.' || rettv->v_type != VAR_FLOAT) | |
2206 #endif | |
2207 ) | |
323 | 2208 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2209 // 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
|
2210 // 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
|
2211 // 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
|
2212 // 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
|
2213 // 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
|
2214 // 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
|
2215 // side effects after an error. |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2216 if (evaluate && tv_get_string_chk(rettv) == NULL) |
323 | 2217 { |
2218 clear_tv(rettv); | |
2219 return FAIL; | |
2220 } | |
2221 } | |
2222 | |
7 | 2223 /* |
2224 * Get the second variable. | |
2225 */ | |
16219
bd49e1656c72
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents:
16170
diff
changeset
|
2226 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
|
2227 ++*arg; |
7 | 2228 *arg = skipwhite(*arg + 1); |
1655 | 2229 if (eval6(arg, &var2, evaluate, op == '.') == FAIL) |
7 | 2230 { |
71 | 2231 clear_tv(rettv); |
7 | 2232 return FAIL; |
2233 } | |
2234 | |
2235 if (evaluate) | |
2236 { | |
2237 /* | |
2238 * Compute the result. | |
2239 */ | |
2240 if (op == '.') | |
2241 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2242 s1 = tv_get_string_buf(rettv, buf1); // already checked |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2243 s2 = tv_get_string_buf_chk(&var2, buf2); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2244 if (s2 == NULL) // type error ? |
323 | 2245 { |
2246 clear_tv(rettv); | |
2247 clear_tv(&var2); | |
2248 return FAIL; | |
2249 } | |
117 | 2250 p = concat_str(s1, s2); |
71 | 2251 clear_tv(rettv); |
2252 rettv->v_type = VAR_STRING; | |
2253 rettv->vval.v_string = p; | |
7 | 2254 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2255 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
|
2256 && 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
|
2257 eval_addblob(rettv, &var2); |
104 | 2258 else if (op == '+' && rettv->v_type == VAR_LIST |
2259 && var2.v_type == VAR_LIST) | |
80 | 2260 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2261 if (eval_addlist(rettv, &var2) == FAIL) |
80 | 2262 return FAIL; |
2263 } | |
7 | 2264 else |
2265 { | |
323 | 2266 int error = FALSE; |
2267 | |
1624 | 2268 #ifdef FEAT_FLOAT |
2269 if (rettv->v_type == VAR_FLOAT) | |
2270 { | |
2271 f1 = rettv->vval.v_float; | |
2272 n1 = 0; | |
2273 } | |
2274 else | |
2275 #endif | |
2276 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2277 n1 = tv_get_number_chk(rettv, &error); |
1624 | 2278 if (error) |
2279 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2280 // 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
|
2281 // "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
|
2282 // before evaluating the 2nd operand. |
1624 | 2283 clear_tv(rettv); |
2284 return FAIL; | |
2285 } | |
2286 #ifdef FEAT_FLOAT | |
2287 if (var2.v_type == VAR_FLOAT) | |
2288 f1 = n1; | |
2289 #endif | |
2290 } | |
2291 #ifdef FEAT_FLOAT | |
2292 if (var2.v_type == VAR_FLOAT) | |
2293 { | |
2294 f2 = var2.vval.v_float; | |
2295 n2 = 0; | |
2296 } | |
2297 else | |
2298 #endif | |
2299 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2300 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2301 if (error) |
2302 { | |
2303 clear_tv(rettv); | |
2304 clear_tv(&var2); | |
2305 return FAIL; | |
2306 } | |
2307 #ifdef FEAT_FLOAT | |
2308 if (rettv->v_type == VAR_FLOAT) | |
2309 f2 = n2; | |
2310 #endif | |
323 | 2311 } |
71 | 2312 clear_tv(rettv); |
1624 | 2313 |
2314 #ifdef FEAT_FLOAT | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2315 // If there is a float on either side the result is a float. |
1624 | 2316 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) |
2317 { | |
2318 if (op == '+') | |
2319 f1 = f1 + f2; | |
2320 else | |
2321 f1 = f1 - f2; | |
2322 rettv->v_type = VAR_FLOAT; | |
2323 rettv->vval.v_float = f1; | |
2324 } | |
2325 else | |
2326 #endif | |
2327 { | |
2328 if (op == '+') | |
2329 n1 = n1 + n2; | |
2330 else | |
2331 n1 = n1 - n2; | |
2332 rettv->v_type = VAR_NUMBER; | |
2333 rettv->vval.v_number = n1; | |
2334 } | |
71 | 2335 } |
2336 clear_tv(&var2); | |
7 | 2337 } |
2338 } | |
2339 return OK; | |
2340 } | |
2341 | |
2342 /* | |
2343 * Handle fifth level expression: | |
2344 * * number multiplication | |
2345 * / number division | |
2346 * % number modulo | |
2347 * | |
2348 * "arg" must point to the first non-white of the expression. | |
2349 * "arg" is advanced to the next non-white after the recognized expression. | |
2350 * | |
2351 * Return OK or FAIL. | |
2352 */ | |
2353 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2354 eval6( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2355 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2356 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2357 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2358 int want_string) // after "." operator |
7 | 2359 { |
137 | 2360 typval_T var2; |
7 | 2361 int op; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2362 varnumber_T n1, n2; |
1624 | 2363 #ifdef FEAT_FLOAT |
2364 int use_float = FALSE; | |
16405
840fa633ad64
patch 8.1.1207: some compilers give warning messages
Bram Moolenaar <Bram@vim.org>
parents:
16366
diff
changeset
|
2365 float_T f1 = 0, f2 = 0; |
1624 | 2366 #endif |
323 | 2367 int error = FALSE; |
7 | 2368 |
2369 /* | |
2370 * Get the first variable. | |
2371 */ | |
1655 | 2372 if (eval7(arg, rettv, evaluate, want_string) == FAIL) |
7 | 2373 return FAIL; |
2374 | |
2375 /* | |
2376 * Repeat computing, until no '*', '/' or '%' is following. | |
2377 */ | |
2378 for (;;) | |
2379 { | |
2380 op = **arg; | |
17387
2558f90045e5
patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents:
17377
diff
changeset
|
2381 if (op != '*' && op != '/' && op != '%') |
7 | 2382 break; |
2383 | |
2384 if (evaluate) | |
2385 { | |
1624 | 2386 #ifdef FEAT_FLOAT |
2387 if (rettv->v_type == VAR_FLOAT) | |
2388 { | |
2389 f1 = rettv->vval.v_float; | |
2390 use_float = TRUE; | |
2391 n1 = 0; | |
2392 } | |
2393 else | |
2394 #endif | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2395 n1 = tv_get_number_chk(rettv, &error); |
71 | 2396 clear_tv(rettv); |
323 | 2397 if (error) |
2398 return FAIL; | |
7 | 2399 } |
2400 else | |
2401 n1 = 0; | |
2402 | |
2403 /* | |
2404 * Get the second variable. | |
2405 */ | |
2406 *arg = skipwhite(*arg + 1); | |
1655 | 2407 if (eval7(arg, &var2, evaluate, FALSE) == FAIL) |
7 | 2408 return FAIL; |
2409 | |
2410 if (evaluate) | |
2411 { | |
1624 | 2412 #ifdef FEAT_FLOAT |
2413 if (var2.v_type == VAR_FLOAT) | |
2414 { | |
2415 if (!use_float) | |
2416 { | |
2417 f1 = n1; | |
2418 use_float = TRUE; | |
2419 } | |
2420 f2 = var2.vval.v_float; | |
2421 n2 = 0; | |
2422 } | |
2423 else | |
2424 #endif | |
2425 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2426 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2427 clear_tv(&var2); |
2428 if (error) | |
2429 return FAIL; | |
2430 #ifdef FEAT_FLOAT | |
2431 if (use_float) | |
2432 f2 = n2; | |
2433 #endif | |
2434 } | |
7 | 2435 |
2436 /* | |
2437 * Compute the result. | |
1624 | 2438 * When either side is a float the result is a float. |
7 | 2439 */ |
1624 | 2440 #ifdef FEAT_FLOAT |
2441 if (use_float) | |
2442 { | |
2443 if (op == '*') | |
2444 f1 = f1 * f2; | |
2445 else if (op == '/') | |
2446 { | |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2447 # ifdef VMS |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2448 // 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
|
2449 if (f2 == 0.0) |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2450 { |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2451 if (f1 == 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2452 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
|
2453 else if (f1 < 0) |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2454 f1 = -1 * __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2455 else |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2456 f1 = __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2457 } |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2458 else |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2459 f1 = f1 / f2; |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2460 # else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2461 // 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
|
2462 // by zero to result in "inf" and not a crash. |
1624 | 2463 f1 = f1 / f2; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2464 # endif |
1624 | 2465 } |
2466 else | |
2467 { | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2468 emsg(_(e_modulus)); |
1624 | 2469 return FAIL; |
2470 } | |
2471 rettv->v_type = VAR_FLOAT; | |
2472 rettv->vval.v_float = f1; | |
2473 } | |
2474 else | |
2475 #endif | |
2476 { | |
2477 if (op == '*') | |
2478 n1 = n1 * n2; | |
2479 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
|
2480 n1 = num_divide(n1, n2); |
1624 | 2481 else |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
2482 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
|
2483 |
1624 | 2484 rettv->v_type = VAR_NUMBER; |
2485 rettv->vval.v_number = n1; | |
2486 } | |
7 | 2487 } |
2488 } | |
2489 | |
2490 return OK; | |
2491 } | |
2492 | |
2493 /* | |
2494 * Handle sixth level expression: | |
2495 * number number constant | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2496 * 0zFFFFFFFF Blob constant |
1228 | 2497 * "string" string constant |
2498 * 'string' literal string constant | |
7 | 2499 * &option-name option value |
2500 * @r register contents | |
2501 * identifier variable value | |
2502 * function() function call | |
2503 * $VAR environment variable | |
2504 * (expression) nested expression | |
151 | 2505 * [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
|
2506 * {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
|
2507 * {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
|
2508 * #{key: val, key: val} Dictionary with literal keys |
7 | 2509 * |
2510 * Also handle: | |
2511 * ! in front logical NOT | |
2512 * - in front unary minus | |
2513 * + in front unary plus (ignored) | |
100 | 2514 * trailing [] subscript in String or List |
2515 * 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
|
2516 * trailing ->name() method call |
7 | 2517 * |
2518 * "arg" must point to the first non-white of the expression. | |
2519 * "arg" is advanced to the next non-white after the recognized expression. | |
2520 * | |
2521 * Return OK or FAIL. | |
2522 */ | |
2523 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2524 eval7( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2525 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2526 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2527 int evaluate, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2528 int want_string) // after "." operator |
7 | 2529 { |
2530 int len; | |
2531 char_u *s; | |
2532 char_u *start_leader, *end_leader; | |
2533 int ret = OK; | |
2534 char_u *alias; | |
2535 | |
2536 /* | |
71 | 2537 * Initialise variable so that clear_tv() can't mistake this for a |
56 | 2538 * string and free a string that isn't there. |
7 | 2539 */ |
71 | 2540 rettv->v_type = VAR_UNKNOWN; |
7 | 2541 |
2542 /* | |
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10000
diff
changeset
|
2543 * Skip '!', '-' and '+' characters. They are handled later. |
7 | 2544 */ |
2545 start_leader = *arg; | |
2546 while (**arg == '!' || **arg == '-' || **arg == '+') | |
2547 *arg = skipwhite(*arg + 1); | |
2548 end_leader = *arg; | |
2549 | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2550 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
|
2551 #ifdef FEAT_FLOAT |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2552 || 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
|
2553 #endif |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2554 )) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2555 { |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2556 semsg(_(e_invexpr2), *arg); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2557 ++*arg; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2558 return FAIL; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2559 } |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2560 |
7 | 2561 switch (**arg) |
2562 { | |
2563 /* | |
2564 * Number constant. | |
2565 */ | |
2566 case '0': | |
2567 case '1': | |
2568 case '2': | |
2569 case '3': | |
2570 case '4': | |
2571 case '5': | |
2572 case '6': | |
2573 case '7': | |
2574 case '8': | |
2575 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
|
2576 case '.': ret = get_number_tv(arg, rettv, evaluate, want_string); |
1624 | 2577 break; |
7 | 2578 |
2579 /* | |
2580 * String constant: "string". | |
2581 */ | |
71 | 2582 case '"': ret = get_string_tv(arg, rettv, evaluate); |
7 | 2583 break; |
2584 | |
2585 /* | |
100 | 2586 * Literal string constant: 'str''ing'. |
7 | 2587 */ |
71 | 2588 case '\'': ret = get_lit_string_tv(arg, rettv, evaluate); |
56 | 2589 break; |
2590 | |
2591 /* | |
2592 * List: [expr, expr] | |
2593 */ | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2594 case '[': ret = get_list_tv(arg, rettv, evaluate, TRUE); |
7 | 2595 break; |
2596 | |
2597 /* | |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2598 * 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
|
2599 */ |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2600 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
|
2601 { |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2602 ++*arg; |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
19017
diff
changeset
|
2603 ret = eval_dict(arg, rettv, evaluate, TRUE); |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2604 } |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2605 else |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2606 ret = NOTDONE; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2607 break; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2608 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2609 /* |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2610 * 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
|
2611 * Dictionary: {'key': val, 'key': val} |
100 | 2612 */ |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2613 case '{': ret = get_lambda_tv(arg, rettv, evaluate); |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2614 if (ret == NOTDONE) |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
19017
diff
changeset
|
2615 ret = eval_dict(arg, rettv, evaluate, FALSE); |
100 | 2616 break; |
2617 | |
2618 /* | |
104 | 2619 * Option value: &name |
7 | 2620 */ |
104 | 2621 case '&': ret = get_option_tv(arg, rettv, evaluate); |
7 | 2622 break; |
2623 | |
2624 /* | |
2625 * Environment variable: $VAR. | |
2626 */ | |
71 | 2627 case '$': ret = get_env_tv(arg, rettv, evaluate); |
7 | 2628 break; |
2629 | |
2630 /* | |
2631 * Register contents: @r. | |
2632 */ | |
2633 case '@': ++*arg; | |
2634 if (evaluate) | |
2635 { | |
71 | 2636 rettv->v_type = VAR_STRING; |
5796 | 2637 rettv->vval.v_string = get_reg_contents(**arg, |
2638 GREG_EXPR_SRC); | |
7 | 2639 } |
2640 if (**arg != NUL) | |
2641 ++*arg; | |
2642 break; | |
2643 | |
2644 /* | |
2645 * nested expression: (expression). | |
2646 */ | |
2647 case '(': *arg = skipwhite(*arg + 1); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2648 ret = eval1(arg, rettv, evaluate); // recursive! |
7 | 2649 if (**arg == ')') |
2650 ++*arg; | |
2651 else if (ret == OK) | |
2652 { | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2653 emsg(_(e_missing_close)); |
71 | 2654 clear_tv(rettv); |
7 | 2655 ret = FAIL; |
2656 } | |
2657 break; | |
2658 | |
100 | 2659 default: ret = NOTDONE; |
2660 break; | |
2661 } | |
2662 | |
2663 if (ret == NOTDONE) | |
2664 { | |
2665 /* | |
2666 * Must be a variable or function name. | |
2667 * Can also be a curly-braces kind of name: {expr}. | |
2668 */ | |
2669 s = *arg; | |
159 | 2670 len = get_name_len(arg, &alias, evaluate, TRUE); |
100 | 2671 if (alias != NULL) |
2672 s = alias; | |
2673 | |
159 | 2674 if (len <= 0) |
100 | 2675 ret = FAIL; |
2676 else | |
2677 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2678 if (**arg == '(') // recursive! |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2679 ret = eval_func(arg, s, len, rettv, evaluate, NULL); |
100 | 2680 else if (evaluate) |
6791 | 2681 ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE); |
117 | 2682 else |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2683 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2684 check_vars(s, len); |
117 | 2685 ret = OK; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2686 } |
100 | 2687 } |
2690 | 2688 vim_free(alias); |
100 | 2689 } |
2690 | |
7 | 2691 *arg = skipwhite(*arg); |
2692 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2693 // 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
|
2694 // expr(expr), expr->name(expr) |
159 | 2695 if (ret == OK) |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2696 ret = handle_subscript(arg, rettv, evaluate, TRUE, |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2697 start_leader, &end_leader); |
7 | 2698 |
2699 /* | |
2700 * Apply logical NOT and unary '-', from right to left, ignore '+'. | |
2701 */ | |
2702 if (ret == OK && evaluate && end_leader > start_leader) | |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2703 ret = eval7_leader(rettv, start_leader, &end_leader); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2704 return ret; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2705 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2706 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2707 /* |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2708 * Apply the leading "!" and "-" before an eval7 expression to "rettv". |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2709 * 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
|
2710 */ |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2711 static int |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2712 eval7_leader(typval_T *rettv, char_u *start_leader, char_u **end_leaderp) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2713 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2714 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
|
2715 int ret = OK; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2716 int error = FALSE; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2717 varnumber_T val = 0; |
1624 | 2718 #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
|
2719 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
|
2720 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2721 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
|
2722 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
|
2723 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2724 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2725 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
|
2726 if (error) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2727 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2728 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2729 ret = FAIL; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2730 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2731 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2732 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2733 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
|
2734 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2735 --end_leader; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2736 if (*end_leader == '!') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2737 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2738 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2739 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
|
2740 f = !f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2741 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2742 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2743 val = !val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2744 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2745 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
|
2746 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2747 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2748 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
|
2749 f = -f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2750 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2751 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2752 val = -val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2753 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2754 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2755 #ifdef FEAT_FLOAT |
1624 | 2756 if (rettv->v_type == VAR_FLOAT) |
323 | 2757 { |
2758 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
|
2759 rettv->vval.v_float = f; |
323 | 2760 } |
2761 else | |
1624 | 2762 #endif |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2763 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2764 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2765 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
|
2766 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
|
2767 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2768 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2769 *end_leaderp = end_leader; |
7 | 2770 return ret; |
2771 } | |
2772 | |
2773 /* | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2774 * 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
|
2775 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2776 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2777 call_func_rettv( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2778 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2779 typval_T *rettv, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2780 int evaluate, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2781 dict_T *selfdict, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2782 typval_T *basetv) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2783 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2784 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
|
2785 funcexe_T funcexe; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2786 typval_T functv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2787 char_u *s; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2788 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2789 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2790 // 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
|
2791 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2792 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2793 functv = *rettv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2794 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
|
2795 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2796 // 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
|
2797 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
|
2798 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2799 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
|
2800 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
|
2801 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2802 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2803 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
|
2804 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2805 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2806 s = (char_u *)""; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2807 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2808 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
|
2809 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
|
2810 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
|
2811 funcexe.evaluate = evaluate; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2812 funcexe.partial = pt; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2813 funcexe.selfdict = selfdict; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2814 funcexe.basetv = basetv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2815 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
|
2816 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2817 // 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
|
2818 // 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
|
2819 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2820 clear_tv(&functv); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2821 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2822 return ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2823 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2824 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2825 /* |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2826 * Evaluate "->method()". |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2827 * "*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
|
2828 * 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
|
2829 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2830 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2831 eval_lambda( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2832 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2833 typval_T *rettv, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2834 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2835 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
|
2836 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2837 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
|
2838 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2839 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2840 // Skip over the ->. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2841 *arg += 2; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2842 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
|
2843 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2844 ret = get_lambda_tv(arg, rettv, evaluate); |
18851
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
2845 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
|
2846 return FAIL; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2847 else if (**arg != '(') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2848 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2849 if (verbose) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2850 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2851 if (*skipwhite(*arg) == '(') |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
2852 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
|
2853 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2854 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
|
2855 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2856 clear_tv(rettv); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2857 ret = FAIL; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2858 } |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2859 else |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2860 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
|
2861 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2862 // 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
|
2863 // 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
|
2864 if (evaluate) |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2865 clear_tv(&base); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2866 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2867 return ret; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2868 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2869 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2870 /* |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2871 * Evaluate "->method()". |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2872 * "*arg" points to the '-'. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2873 * 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
|
2874 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2875 static int |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2876 eval_method( |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2877 char_u **arg, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2878 typval_T *rettv, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2879 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2880 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
|
2881 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2882 char_u *name; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2883 long len; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2884 char_u *alias; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2885 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
|
2886 int ret; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2887 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2888 // Skip over the ->. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2889 *arg += 2; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2890 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
|
2891 |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2892 name = *arg; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2893 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
|
2894 if (alias != NULL) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2895 name = alias; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2896 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2897 if (len <= 0) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2898 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2899 if (verbose) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2900 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
|
2901 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2902 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2903 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2904 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2905 if (**arg != '(') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2906 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2907 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
|
2908 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
|
2909 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2910 } |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2911 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
|
2912 { |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2913 if (verbose) |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19568
diff
changeset
|
2914 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
|
2915 ret = FAIL; |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2916 } |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2917 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2918 ret = eval_func(arg, name, len, rettv, evaluate, &base); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2919 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2920 |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2921 // 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
|
2922 // 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
|
2923 if (evaluate) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2924 clear_tv(&base); |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2925 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2926 return ret; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2927 } |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2928 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2929 /* |
829 | 2930 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". |
2931 * "*arg" points to the '[' or '.'. | |
56 | 2932 * Returns FAIL or OK. "*arg" is advanced to after the ']'. |
2933 */ | |
2934 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2935 eval_index( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2936 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2937 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2938 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2939 int verbose) // give error messages |
56 | 2940 { |
2941 int empty1 = FALSE, empty2 = FALSE; | |
137 | 2942 typval_T var1, var2; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2943 long i; |
56 | 2944 long n1, n2 = 0; |
100 | 2945 long len = -1; |
2946 int range = FALSE; | |
56 | 2947 char_u *s; |
100 | 2948 char_u *key = NULL; |
56 | 2949 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2950 switch (rettv->v_type) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2951 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2952 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
2953 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2954 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
2955 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
|
2956 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2957 case VAR_FLOAT: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2958 #ifdef FEAT_FLOAT |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2959 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
2960 emsg(_(e_float_as_string)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2961 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2962 #endif |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
2963 case VAR_BOOL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2964 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
2965 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
2966 case VAR_CHANNEL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2967 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
2968 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
|
2969 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2970 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
|
2971 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
|
2972 case VAR_VOID: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2973 if (evaluate) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2974 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2975 // FALLTHROUGH |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2976 |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2977 case VAR_STRING: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2978 case VAR_NUMBER: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2979 case VAR_LIST: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2980 case VAR_DICT: |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2981 case VAR_BLOB: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
2982 break; |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
2983 } |
56 | 2984 |
7046
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
2985 init_tv(&var1); |
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
2986 init_tv(&var2); |
100 | 2987 if (**arg == '.') |
2988 { | |
2989 /* | |
2990 * dict.name | |
2991 */ | |
2992 key = *arg + 1; | |
2993 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
2994 ; | |
2995 if (len == 0) | |
2996 return FAIL; | |
2997 *arg = skipwhite(key + len); | |
2998 } | |
2999 else | |
3000 { | |
3001 /* | |
3002 * something[idx] | |
3003 * | |
3004 * Get the (first) variable from inside the []. | |
3005 */ | |
56 | 3006 *arg = skipwhite(*arg + 1); |
100 | 3007 if (**arg == ':') |
3008 empty1 = TRUE; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3009 else if (eval1(arg, &var1, evaluate) == FAIL) // recursive! |
56 | 3010 return FAIL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3011 else if (evaluate && tv_get_string_chk(&var1) == NULL) |
323 | 3012 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3013 // not a number or string |
323 | 3014 clear_tv(&var1); |
3015 return FAIL; | |
3016 } | |
100 | 3017 |
3018 /* | |
3019 * Get the second variable from inside the [:]. | |
3020 */ | |
3021 if (**arg == ':') | |
3022 { | |
3023 range = TRUE; | |
3024 *arg = skipwhite(*arg + 1); | |
3025 if (**arg == ']') | |
3026 empty2 = TRUE; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3027 else if (eval1(arg, &var2, evaluate) == FAIL) // recursive! |
100 | 3028 { |
323 | 3029 if (!empty1) |
3030 clear_tv(&var1); | |
3031 return FAIL; | |
3032 } | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3033 else if (evaluate && tv_get_string_chk(&var2) == NULL) |
323 | 3034 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3035 // not a number or string |
323 | 3036 if (!empty1) |
3037 clear_tv(&var1); | |
3038 clear_tv(&var2); | |
100 | 3039 return FAIL; |
3040 } | |
3041 } | |
3042 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3043 // Check for the ']'. |
100 | 3044 if (**arg != ']') |
3045 { | |
159 | 3046 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3047 emsg(_(e_missbrac)); |
100 | 3048 clear_tv(&var1); |
3049 if (range) | |
3050 clear_tv(&var2); | |
3051 return FAIL; | |
3052 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3053 *arg = skipwhite(*arg + 1); // skip the ']' |
56 | 3054 } |
3055 | |
3056 if (evaluate) | |
3057 { | |
100 | 3058 n1 = 0; |
3059 if (!empty1 && rettv->v_type != VAR_DICT) | |
56 | 3060 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3061 n1 = tv_get_number(&var1); |
71 | 3062 clear_tv(&var1); |
56 | 3063 } |
3064 if (range) | |
3065 { | |
3066 if (empty2) | |
3067 n2 = -1; | |
3068 else | |
3069 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3070 n2 = tv_get_number(&var2); |
71 | 3071 clear_tv(&var2); |
3072 } | |
3073 } | |
3074 | |
3075 switch (rettv->v_type) | |
56 | 3076 { |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3077 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
|
3078 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
|
3079 case VAR_VOID: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3080 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
3081 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3082 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
|
3083 case VAR_BOOL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3084 case VAR_SPECIAL: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3085 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3086 case VAR_CHANNEL: |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3087 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
|
3088 |
56 | 3089 case VAR_NUMBER: |
3090 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
|
3091 s = tv_get_string(rettv); |
56 | 3092 len = (long)STRLEN(s); |
3093 if (range) | |
3094 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3095 // 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
|
3096 // are out of range the result is empty. |
56 | 3097 if (n1 < 0) |
3098 { | |
3099 n1 = len + n1; | |
3100 if (n1 < 0) | |
3101 n1 = 0; | |
3102 } | |
3103 if (n2 < 0) | |
3104 n2 = len + n2; | |
3105 else if (n2 >= len) | |
3106 n2 = len; | |
3107 if (n1 >= len || n2 < 0 || n1 > n2) | |
3108 s = NULL; | |
3109 else | |
3110 s = vim_strnsave(s + n1, (int)(n2 - n1 + 1)); | |
3111 } | |
3112 else | |
3113 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3114 // 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
|
3115 // 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
|
3116 // result is empty. |
56 | 3117 if (n1 >= len || n1 < 0) |
3118 s = NULL; | |
3119 else | |
3120 s = vim_strnsave(s + n1, 1); | |
3121 } | |
71 | 3122 clear_tv(rettv); |
3123 rettv->v_type = VAR_STRING; | |
3124 rettv->vval.v_string = s; | |
56 | 3125 break; |
3126 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3127 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3128 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
|
3129 if (range) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3130 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
3131 // 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
|
3132 // 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
|
3133 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3134 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3135 n1 = len + n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3136 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3137 n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3138 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3139 if (n2 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3140 n2 = len + n2; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3141 else if (n2 >= len) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3142 n2 = len - 1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3143 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
|
3144 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3145 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3146 rettv->v_type = VAR_BLOB; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3147 rettv->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3148 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3149 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3150 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3151 blob_T *blob = blob_alloc(); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3152 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3153 if (blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3154 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3155 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
|
3156 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3157 blob_free(blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3158 return FAIL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3159 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3160 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
|
3161 for (i = n1; i <= n2; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3162 blob_set(blob, i - n1, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3163 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
|
3164 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3165 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3166 rettv_blob_set(rettv, blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3167 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3168 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3169 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3170 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3171 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3172 // 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
|
3173 // 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
|
3174 if (n1 < 0) |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3175 n1 = len + n1; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3176 if (n1 < len && n1 >= 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3177 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3178 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
|
3179 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3180 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3181 rettv->v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3182 rettv->vval.v_number = v; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3183 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3184 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3185 semsg(_(e_blobidx), n1); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3186 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3187 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3188 |
56 | 3189 case VAR_LIST: |
71 | 3190 len = list_len(rettv->vval.v_list); |
56 | 3191 if (n1 < 0) |
3192 n1 = len + n1; | |
3193 if (!empty1 && (n1 < 0 || n1 >= len)) | |
3194 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3195 // 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
|
3196 // list. A list index out of range is an error. |
842 | 3197 if (!range) |
3198 { | |
3199 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3200 semsg(_(e_listidx), n1); |
842 | 3201 return FAIL; |
3202 } | |
3203 n1 = len; | |
56 | 3204 } |
3205 if (range) | |
3206 { | |
137 | 3207 list_T *l; |
3208 listitem_T *item; | |
56 | 3209 |
3210 if (n2 < 0) | |
3211 n2 = len + n2; | |
829 | 3212 else if (n2 >= len) |
3213 n2 = len - 1; | |
3214 if (!empty2 && (n2 < 0 || n2 + 1 < n1)) | |
842 | 3215 n2 = -1; |
56 | 3216 l = list_alloc(); |
3217 if (l == NULL) | |
3218 return FAIL; | |
71 | 3219 for (item = list_find(rettv->vval.v_list, n1); |
56 | 3220 n1 <= n2; ++n1) |
3221 { | |
3222 if (list_append_tv(l, &item->li_tv) == FAIL) | |
3223 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3224 list_free(l); |
56 | 3225 return FAIL; |
3226 } | |
3227 item = item->li_next; | |
3228 } | |
71 | 3229 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
|
3230 rettv_list_set(rettv, l); |
56 | 3231 } |
3232 else | |
3233 { | |
842 | 3234 copy_tv(&list_find(rettv->vval.v_list, n1)->li_tv, &var1); |
71 | 3235 clear_tv(rettv); |
3236 *rettv = var1; | |
56 | 3237 } |
3238 break; | |
100 | 3239 |
3240 case VAR_DICT: | |
3241 if (range) | |
3242 { | |
159 | 3243 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3244 emsg(_(e_dictrange)); |
100 | 3245 if (len == -1) |
3246 clear_tv(&var1); | |
3247 return FAIL; | |
3248 } | |
3249 { | |
137 | 3250 dictitem_T *item; |
100 | 3251 |
3252 if (len == -1) | |
3253 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3254 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
|
3255 if (key == NULL) |
100 | 3256 { |
3257 clear_tv(&var1); | |
3258 return FAIL; | |
3259 } | |
3260 } | |
3261 | |
121 | 3262 item = dict_find(rettv->vval.v_dict, key, (int)len); |
100 | 3263 |
159 | 3264 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
|
3265 semsg(_(e_dictkey), key); |
100 | 3266 if (len == -1) |
3267 clear_tv(&var1); | |
3268 if (item == NULL) | |
3269 return FAIL; | |
3270 | |
3271 copy_tv(&item->di_tv, &var1); | |
3272 clear_tv(rettv); | |
3273 *rettv = var1; | |
3274 } | |
3275 break; | |
3276 } | |
3277 } | |
3278 | |
56 | 3279 return OK; |
3280 } | |
3281 | |
3282 /* | |
7 | 3283 * Get an option value. |
3284 * "arg" points to the '&' or '+' before the option name. | |
3285 * "arg" is advanced to character after the option name. | |
3286 * Return OK or FAIL. | |
3287 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
3288 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3289 get_option_tv( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3290 char_u **arg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3291 typval_T *rettv, // when NULL, only check if option exists |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3292 int evaluate) |
7 | 3293 { |
3294 char_u *option_end; | |
3295 long numval; | |
3296 char_u *stringval; | |
3297 int opt_type; | |
3298 int c; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3299 int working = (**arg == '+'); // has("+option") |
7 | 3300 int ret = OK; |
3301 int opt_flags; | |
3302 | |
3303 /* | |
3304 * Isolate the option name and find its value. | |
3305 */ | |
3306 option_end = find_option_end(arg, &opt_flags); | |
3307 if (option_end == NULL) | |
3308 { | |
71 | 3309 if (rettv != NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3310 semsg(_("E112: Option name missing: %s"), *arg); |
7 | 3311 return FAIL; |
3312 } | |
3313 | |
3314 if (!evaluate) | |
3315 { | |
3316 *arg = option_end; | |
3317 return OK; | |
3318 } | |
3319 | |
3320 c = *option_end; | |
3321 *option_end = NUL; | |
3322 opt_type = get_option_value(*arg, &numval, | |
71 | 3323 rettv == NULL ? NULL : &stringval, opt_flags); |
7 | 3324 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3325 if (opt_type == -3) // invalid name |
7 | 3326 { |
71 | 3327 if (rettv != NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3328 semsg(_(e_unknown_option), *arg); |
7 | 3329 ret = FAIL; |
3330 } | |
71 | 3331 else if (rettv != NULL) |
7 | 3332 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3333 if (opt_type == -2) // hidden string option |
7 | 3334 { |
71 | 3335 rettv->v_type = VAR_STRING; |
3336 rettv->vval.v_string = NULL; | |
7 | 3337 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3338 else if (opt_type == -1) // hidden number option |
7 | 3339 { |
71 | 3340 rettv->v_type = VAR_NUMBER; |
3341 rettv->vval.v_number = 0; | |
7 | 3342 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3343 else if (opt_type == 1) // number option |
7 | 3344 { |
71 | 3345 rettv->v_type = VAR_NUMBER; |
3346 rettv->vval.v_number = numval; | |
7 | 3347 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3348 else // string option |
7 | 3349 { |
71 | 3350 rettv->v_type = VAR_STRING; |
3351 rettv->vval.v_string = stringval; | |
7 | 3352 } |
3353 } | |
3354 else if (working && (opt_type == -2 || opt_type == -1)) | |
3355 ret = FAIL; | |
3356 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3357 *option_end = c; // put back for error messages |
7 | 3358 *arg = option_end; |
3359 | |
3360 return ret; | |
3361 } | |
3362 | |
3363 /* | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3364 * Allocate a variable for a number constant. Also deals with "0z" for blob. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3365 * Return 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
|
3366 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3367 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3368 get_number_tv( |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3369 char_u **arg, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3370 typval_T *rettv, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3371 int evaluate, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3372 int want_string UNUSED) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3373 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3374 int len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3375 #ifdef FEAT_FLOAT |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3376 char_u *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3377 int get_float = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3378 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3379 // We accept a float when the format matches |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3380 // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3381 // strict to avoid backwards compatibility problems. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3382 // With script version 2 and later the leading digit can be |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3383 // omitted. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3384 // Don't look for a float after the "." operator, so that |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3385 // ":let vers = 1.2.3" doesn't fail. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3386 if (**arg == '.') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3387 p = *arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3388 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3389 p = skipdigits(*arg + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3390 if (!want_string && p[0] == '.' && vim_isdigit(p[1])) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3391 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3392 get_float = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3393 p = skipdigits(p + 2); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3394 if (*p == 'e' || *p == 'E') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3395 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3396 ++p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3397 if (*p == '-' || *p == '+') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3398 ++p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3399 if (!vim_isdigit(*p)) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3400 get_float = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3401 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3402 p = skipdigits(p + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3403 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3404 if (ASCII_ISALPHA(*p) || *p == '.') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3405 get_float = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3406 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3407 if (get_float) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3408 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3409 float_T f; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3410 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3411 *arg += string2float(*arg, &f); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3412 if (evaluate) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3413 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3414 rettv->v_type = VAR_FLOAT; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3415 rettv->vval.v_float = f; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3416 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3417 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3418 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3419 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3420 if (**arg == '0' && ((*arg)[1] == 'z' || (*arg)[1] == 'Z')) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3421 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3422 char_u *bp; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3423 blob_T *blob = NULL; // init for gcc |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3424 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3425 // Blob constant: 0z0123456789abcdef |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3426 if (evaluate) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3427 blob = blob_alloc(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3428 for (bp = *arg + 2; vim_isxdigit(bp[0]); bp += 2) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3429 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3430 if (!vim_isxdigit(bp[1])) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3431 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3432 if (blob != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3433 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3434 emsg(_("E973: Blob literal should have an even number of hex characters")); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3435 ga_clear(&blob->bv_ga); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3436 VIM_CLEAR(blob); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3437 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3438 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3439 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3440 if (blob != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3441 ga_append(&blob->bv_ga, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3442 (hex2nr(*bp) << 4) + hex2nr(*(bp+1))); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3443 if (bp[2] == '.' && vim_isxdigit(bp[3])) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3444 ++bp; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3445 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3446 if (blob != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3447 rettv_blob_set(rettv, blob); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3448 *arg = bp; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3449 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3450 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3451 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3452 varnumber_T n; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3453 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3454 // decimal, hex or octal number |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3455 vim_str2nr(*arg, NULL, &len, current_sctx.sc_version >= 4 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3456 ? STR2NR_NO_OCT + STR2NR_QUOTE |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3457 : STR2NR_ALL, &n, NULL, 0, TRUE); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3458 if (len == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3459 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3460 semsg(_(e_invexpr2), *arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3461 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3462 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3463 *arg += len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3464 if (evaluate) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3465 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3466 rettv->v_type = VAR_NUMBER; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3467 rettv->vval.v_number = n; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3468 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3469 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3470 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3471 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3472 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3473 /* |
7 | 3474 * Allocate a variable for a string constant. |
3475 * Return OK or FAIL. | |
3476 */ | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3477 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3478 get_string_tv(char_u **arg, typval_T *rettv, int evaluate) |
7 | 3479 { |
3480 char_u *p; | |
3481 char_u *name; | |
3482 int extra = 0; | |
3483 | |
3484 /* | |
3485 * Find the end of the string, skipping backslashed characters. | |
3486 */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
3487 for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
7 | 3488 { |
3489 if (*p == '\\' && p[1] != NUL) | |
3490 { | |
3491 ++p; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3492 // A "\<x>" form occupies at least 4 characters, and produces up |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3493 // to 6 characters: reserve space for 2 extra |
7 | 3494 if (*p == '<') |
3495 extra += 2; | |
3496 } | |
3497 } | |
3498 | |
3499 if (*p != '"') | |
3500 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3501 semsg(_("E114: Missing quote: %s"), *arg); |
7 | 3502 return FAIL; |
3503 } | |
3504 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3505 // If only parsing, set *arg and return here |
7 | 3506 if (!evaluate) |
3507 { | |
3508 *arg = p + 1; | |
3509 return OK; | |
3510 } | |
3511 | |
3512 /* | |
3513 * Copy the string into allocated memory, handling backslashed | |
3514 * characters. | |
3515 */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
3516 name = alloc(p - *arg + extra); |
7 | 3517 if (name == NULL) |
3518 return FAIL; | |
100 | 3519 rettv->v_type = VAR_STRING; |
3520 rettv->vval.v_string = name; | |
3521 | |
3522 for (p = *arg + 1; *p != NUL && *p != '"'; ) | |
7 | 3523 { |
3524 if (*p == '\\') | |
3525 { | |
3526 switch (*++p) | |
3527 { | |
100 | 3528 case 'b': *name++ = BS; ++p; break; |
3529 case 'e': *name++ = ESC; ++p; break; | |
3530 case 'f': *name++ = FF; ++p; break; | |
3531 case 'n': *name++ = NL; ++p; break; | |
3532 case 'r': *name++ = CAR; ++p; break; | |
3533 case 't': *name++ = TAB; ++p; break; | |
7 | 3534 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3535 case 'X': // hex: "\x1", "\x12" |
7 | 3536 case 'x': |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3537 case 'u': // Unicode: "\u0023" |
7 | 3538 case 'U': |
3539 if (vim_isxdigit(p[1])) | |
3540 { | |
3541 int n, nr; | |
3542 int c = toupper(*p); | |
3543 | |
3544 if (c == 'X') | |
3545 n = 2; | |
6836 | 3546 else if (*p == 'u') |
3547 n = 4; | |
7 | 3548 else |
6836 | 3549 n = 8; |
7 | 3550 nr = 0; |
3551 while (--n >= 0 && vim_isxdigit(p[1])) | |
3552 { | |
3553 ++p; | |
3554 nr = (nr << 4) + hex2nr(*p); | |
3555 } | |
100 | 3556 ++p; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3557 // For "\u" store the number according to |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3558 // 'encoding'. |
7 | 3559 if (c != 'X') |
100 | 3560 name += (*mb_char2bytes)(nr, name); |
7 | 3561 else |
100 | 3562 *name++ = nr; |
7 | 3563 } |
3564 break; | |
3565 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3566 // octal: "\1", "\12", "\123" |
7 | 3567 case '0': |
3568 case '1': | |
3569 case '2': | |
3570 case '3': | |
3571 case '4': | |
3572 case '5': | |
3573 case '6': | |
100 | 3574 case '7': *name = *p++ - '0'; |
3575 if (*p >= '0' && *p <= '7') | |
7 | 3576 { |
100 | 3577 *name = (*name << 3) + *p++ - '0'; |
3578 if (*p >= '0' && *p <= '7') | |
3579 *name = (*name << 3) + *p++ - '0'; | |
7 | 3580 } |
100 | 3581 ++name; |
7 | 3582 break; |
3583 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3584 // Special key, e.g.: "\<C-W>" |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
3585 case '<': extra = trans_special(&p, name, TRUE, TRUE, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
3586 TRUE, NULL); |
7 | 3587 if (extra != 0) |
3588 { | |
100 | 3589 name += extra; |
7 | 3590 break; |
3591 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3592 // FALLTHROUGH |
7 | 3593 |
100 | 3594 default: MB_COPY_CHAR(p, name); |
7 | 3595 break; |
3596 } | |
3597 } | |
3598 else | |
100 | 3599 MB_COPY_CHAR(p, name); |
3600 | |
3601 } | |
3602 *name = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3603 if (*p != NUL) // just in case |
9965
b329e3ca0dcb
commit https://github.com/vim/vim/commit/db249f26edf7a5f88d1f4468d08ec5b84f5ab7ad
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
3604 ++p; |
b329e3ca0dcb
commit https://github.com/vim/vim/commit/db249f26edf7a5f88d1f4468d08ec5b84f5ab7ad
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
3605 *arg = p; |
7 | 3606 |
3607 return OK; | |
3608 } | |
3609 | |
3610 /* | |
100 | 3611 * Allocate a variable for a 'str''ing' constant. |
7 | 3612 * Return OK or FAIL. |
3613 */ | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3614 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3615 get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) |
7 | 3616 { |
3617 char_u *p; | |
100 | 3618 char_u *str; |
3619 int reduce = 0; | |
7 | 3620 |
3621 /* | |
100 | 3622 * Find the end of the string, skipping ''. |
7 | 3623 */ |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
3624 for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p)) |
100 | 3625 { |
3626 if (*p == '\'') | |
3627 { | |
3628 if (p[1] != '\'') | |
3629 break; | |
3630 ++reduce; | |
3631 ++p; | |
3632 } | |
3633 } | |
3634 | |
3635 if (*p != '\'') | |
7 | 3636 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3637 semsg(_("E115: Missing quote: %s"), *arg); |
7 | 3638 return FAIL; |
3639 } | |
3640 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3641 // If only parsing return after setting "*arg" |
97 | 3642 if (!evaluate) |
3643 { | |
3644 *arg = p + 1; | |
3645 return OK; | |
3646 } | |
3647 | |
3648 /* | |
100 | 3649 * Copy the string into allocated memory, handling '' to ' reduction. |
97 | 3650 */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
3651 str = alloc((p - *arg) - reduce); |
97 | 3652 if (str == NULL) |
3653 return FAIL; | |
100 | 3654 rettv->v_type = VAR_STRING; |
3655 rettv->vval.v_string = str; | |
3656 | |
3657 for (p = *arg + 1; *p != NUL; ) | |
3658 { | |
3659 if (*p == '\'') | |
3660 { | |
3661 if (p[1] != '\'') | |
97 | 3662 break; |
3663 ++p; | |
3664 } | |
100 | 3665 MB_COPY_CHAR(p, str); |
3666 } | |
3667 *str = NUL; | |
97 | 3668 *arg = p + 1; |
3669 | |
3670 return OK; | |
3671 } | |
3672 | |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3673 /* |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3674 * 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
|
3675 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3676 char_u * |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3677 partial_name(partial_T *pt) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3678 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3679 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3680 return pt->pt_name; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3681 return pt->pt_func->uf_name; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3682 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3683 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3684 static void |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3685 partial_free(partial_T *pt) |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3686 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3687 int i; |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3688 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3689 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
|
3690 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
|
3691 vim_free(pt->pt_argv); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3692 dict_unref(pt->pt_dict); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3693 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3694 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3695 func_unref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3696 vim_free(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3697 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3698 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3699 func_ptr_unref(pt->pt_func); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3700 vim_free(pt); |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3701 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3702 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3703 /* |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3704 * 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
|
3705 * becomes zero. |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3706 */ |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3707 void |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3708 partial_unref(partial_T *pt) |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3709 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3710 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
|
3711 partial_free(pt); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3712 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3713 |
2634 | 3714 static int tv_equal_recurse_limit; |
3715 | |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3716 static int |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3717 func_equal( |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3718 typval_T *tv1, |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3719 typval_T *tv2, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3720 int ic) // ignore case |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3721 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3722 char_u *s1, *s2; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3723 dict_T *d1, *d2; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3724 int a1, a2; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3725 int i; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3726 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3727 // empty and NULL function name considered the same |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3728 s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3729 : partial_name(tv1->vval.v_partial); |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3730 if (s1 != NULL && *s1 == NUL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3731 s1 = NULL; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3732 s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3733 : partial_name(tv2->vval.v_partial); |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3734 if (s2 != NULL && *s2 == NUL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3735 s2 = NULL; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3736 if (s1 == NULL || s2 == NULL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3737 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3738 if (s1 != s2) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3739 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3740 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3741 else if (STRCMP(s1, s2) != 0) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3742 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3743 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3744 // empty dict and NULL dict is different |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3745 d1 = tv1->v_type == VAR_FUNC ? NULL : tv1->vval.v_partial->pt_dict; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3746 d2 = tv2->v_type == VAR_FUNC ? NULL : tv2->vval.v_partial->pt_dict; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3747 if (d1 == NULL || d2 == NULL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3748 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3749 if (d1 != d2) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3750 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3751 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3752 else if (!dict_equal(d1, d2, ic, TRUE)) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3753 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3754 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3755 // empty list and no list considered the same |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3756 a1 = tv1->v_type == VAR_FUNC ? 0 : tv1->vval.v_partial->pt_argc; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3757 a2 = tv2->v_type == VAR_FUNC ? 0 : tv2->vval.v_partial->pt_argc; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3758 if (a1 != a2) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3759 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3760 for (i = 0; i < a1; ++i) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3761 if (!tv_equal(tv1->vval.v_partial->pt_argv + i, |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3762 tv2->vval.v_partial->pt_argv + i, ic, TRUE)) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3763 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3764 |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3765 return TRUE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3766 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3767 |
117 | 3768 /* |
80 | 3769 * Return TRUE if "tv1" and "tv2" have the same value. |
388 | 3770 * Compares the items just like "==" would compare them, but strings and |
1624 | 3771 * numbers are different. Floats and numbers are also different. |
80 | 3772 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
3773 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3774 tv_equal( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3775 typval_T *tv1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3776 typval_T *tv2, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3777 int ic, // ignore case |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3778 int recursive) // TRUE when used recursively |
80 | 3779 { |
3780 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | |
323 | 3781 char_u *s1, *s2; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3782 static int recursive_cnt = 0; // catch recursive loops |
1008 | 3783 int r; |
3784 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3785 // Catch lists and dicts that have an endless loop by limiting |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3786 // recursiveness to a limit. We guess they are equal then. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3787 // A fixed limit has the problem of still taking an awful long time. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3788 // Reduce the limit every time running into it. That should work fine for |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3789 // deeply linked structures that are not recursively linked and catch |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3790 // recursiveness quickly. |
2634 | 3791 if (!recursive) |
3792 tv_equal_recurse_limit = 1000; | |
3793 if (recursive_cnt >= tv_equal_recurse_limit) | |
3794 { | |
3795 --tv_equal_recurse_limit; | |
1014 | 3796 return TRUE; |
2634 | 3797 } |
388 | 3798 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3799 // For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3800 // arguments. |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3801 if ((tv1->v_type == VAR_FUNC |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3802 || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL)) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3803 && (tv2->v_type == VAR_FUNC |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3804 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial != NULL))) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3805 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3806 ++recursive_cnt; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3807 r = func_equal(tv1, tv2, ic); |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3808 --recursive_cnt; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3809 return r; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3810 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3811 |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3812 if (tv1->v_type != tv2->v_type) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3813 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3814 |
388 | 3815 switch (tv1->v_type) |
3816 { | |
3817 case VAR_LIST: | |
2634 | 3818 ++recursive_cnt; |
3819 r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE); | |
3820 --recursive_cnt; | |
1008 | 3821 return r; |
388 | 3822 |
3823 case VAR_DICT: | |
2634 | 3824 ++recursive_cnt; |
3825 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE); | |
3826 --recursive_cnt; | |
1008 | 3827 return r; |
388 | 3828 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3829 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3830 return blob_equal(tv1->vval.v_blob, tv2->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3831 |
388 | 3832 case VAR_NUMBER: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3833 case VAR_BOOL: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3834 case VAR_SPECIAL: |
388 | 3835 return tv1->vval.v_number == tv2->vval.v_number; |
3836 | |
3837 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
|
3838 s1 = tv_get_string_buf(tv1, buf1); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3839 s2 = tv_get_string_buf(tv2, buf2); |
388 | 3840 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0); |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3841 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3842 case VAR_FLOAT: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3843 #ifdef FEAT_FLOAT |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3844 return tv1->vval.v_float == tv2->vval.v_float; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3845 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3846 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3847 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3848 return tv1->vval.v_job == tv2->vval.v_job; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3849 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3850 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3851 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3852 return tv1->vval.v_channel == tv2->vval.v_channel; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3853 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3854 |
19874
f92435f0f449
patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19760
diff
changeset
|
3855 case VAR_PARTIAL: |
f92435f0f449
patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19760
diff
changeset
|
3856 return tv1->vval.v_partial == tv2->vval.v_partial; |
f92435f0f449
patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19760
diff
changeset
|
3857 |
8635
3a38d465f731
commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
8633
diff
changeset
|
3858 case VAR_FUNC: |
19874
f92435f0f449
patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19760
diff
changeset
|
3859 return tv1->vval.v_string == tv2->vval.v_string; |
f92435f0f449
patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19760
diff
changeset
|
3860 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3861 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
|
3862 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
|
3863 case VAR_VOID: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3864 break; |
388 | 3865 } |
3866 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3867 // VAR_UNKNOWN can be the result of a invalid expression, let's say it |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3868 // does not equal anything, not even itself. |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3869 return FALSE; |
80 | 3870 } |
3871 | |
3872 /* | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3873 * Return the next (unique) copy ID. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3874 * Used for serializing nested structures. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3875 */ |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3876 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3877 get_copyID(void) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3878 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3879 current_copyID += COPYID_INC; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3880 return current_copyID; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3881 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3882 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3883 /* |
371 | 3884 * Garbage collection for lists and dictionaries. |
3885 * | |
3886 * We use reference counts to be able to free most items right away when they | |
3887 * are no longer used. But for composite items it's possible that it becomes | |
3888 * unused while the reference count is > 0: When there is a recursive | |
3889 * reference. Example: | |
3890 * :let l = [1, 2, 3] | |
3891 * :let d = {9: l} | |
3892 * :let l[1] = d | |
3893 * | |
3894 * Since this is quite unusual we handle this with garbage collection: every | |
3895 * once in a while find out which lists and dicts are not referenced from any | |
3896 * variable. | |
3897 * | |
3898 * Here is a good reference text about garbage collection (refers to Python | |
3899 * but it applies to all reference-counting mechanisms): | |
3900 * http://python.ca/nas/python/gc/ | |
3901 */ | |
3902 | |
3903 /* | |
3904 * 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
|
3905 * When "testing" is TRUE this is called from test_garbagecollect_now(). |
371 | 3906 * Return TRUE if some memory was freed. |
3907 */ | |
3908 int | |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3909 garbage_collect(int testing) |
371 | 3910 { |
1891 | 3911 int copyID; |
6565 | 3912 int abort = FALSE; |
371 | 3913 buf_T *buf; |
3914 win_T *wp; | |
6588 | 3915 int did_free = FALSE; |
819 | 3916 tabpage_T *tp; |
371 | 3917 |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3918 if (!testing) |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3919 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3920 // Only do this once. |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3921 want_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3922 may_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3923 garbage_collect_at_exit = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3924 } |
958 | 3925 |
19001
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3926 // 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
|
3927 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
|
3928 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3929 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
|
3930 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
|
3931 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
|
3932 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3933 // 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
|
3934 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
|
3935 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
|
3936 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
|
3937 |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3938 // 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
|
3939 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
|
3940 { |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3941 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
|
3942 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
|
3943 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
|
3944 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
|
3945 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
|
3946 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
|
3947 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3948 } |
1ebfb46710cd
patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents:
18968
diff
changeset
|
3949 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3950 // 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
|
3951 // previous_funccal. |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3952 copyID = get_copyID(); |
1891 | 3953 |
371 | 3954 /* |
3955 * 1. Go through all accessible variables and mark all lists and dicts | |
3956 * with copyID. | |
3957 */ | |
1891 | 3958 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3959 // 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
|
3960 // 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
|
3961 // 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
|
3962 abort = abort || set_ref_in_previous_funccal(copyID); |
1891 | 3963 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3964 // 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
|
3965 abort = abort || garbage_collect_scriptvars(copyID); |
371 | 3966 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3967 // buffer-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3968 FOR_ALL_BUFFERS(buf) |
6565 | 3969 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID, |
3970 NULL, NULL); | |
371 | 3971 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3972 // window-local variables |
819 | 3973 FOR_ALL_TAB_WINDOWS(tp, wp) |
6565 | 3974 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, |
3975 NULL, NULL); | |
4309 | 3976 if (aucmd_win != NULL) |
6565 | 3977 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID, |
3978 NULL, NULL); | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
3979 #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
|
3980 FOR_ALL_POPUPWINS(wp) |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3981 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
|
3982 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3983 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
|
3984 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
|
3985 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
|
3986 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3987 #endif |
371 | 3988 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3989 // tabpage-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3990 FOR_ALL_TABPAGES(tp) |
6565 | 3991 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, |
3992 NULL, NULL); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3993 // 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
|
3994 abort = abort || garbage_collect_globvars(copyID); |
371 | 3995 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3996 // function-local variables |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3997 abort = abort || set_ref_in_call_stack(copyID); |
371 | 3998 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3999 // named functions (matters for closures) |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
4000 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
|
4001 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4002 // 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
|
4003 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
|
4004 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4005 // 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
|
4006 abort = abort || garbage_collect_vimvars(copyID); |
1733 | 4007 |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4008 // callbacks in buffers |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4009 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
|
4010 |
3450 | 4011 #ifdef FEAT_LUA |
6565 | 4012 abort = abort || set_ref_in_lua(copyID); |
3450 | 4013 #endif |
4014 | |
3618 | 4015 #ifdef FEAT_PYTHON |
6565 | 4016 abort = abort || set_ref_in_python(copyID); |
3618 | 4017 #endif |
4018 | |
4019 #ifdef FEAT_PYTHON3 | |
6565 | 4020 abort = abort || set_ref_in_python3(copyID); |
4021 #endif | |
4022 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4023 #ifdef FEAT_JOB_CHANNEL |
8877
50e40f322e78
commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents:
8870
diff
changeset
|
4024 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
|
4025 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
|
4026 #endif |
9052
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
4027 #ifdef FEAT_NETBEANS_INTG |
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
4028 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
|
4029 #endif |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7895
diff
changeset
|
4030 |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
4031 #ifdef FEAT_TIMERS |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
4032 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
|
4033 #endif |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
4034 |
11412
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
4035 #ifdef FEAT_QUICKFIX |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
4036 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
|
4037 #endif |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
4038 |
11804
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
4039 #ifdef FEAT_TERMINAL |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
4040 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
|
4041 #endif |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
4042 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
4043 #ifdef FEAT_PROP_POPUP |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4044 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
|
4045 #endif |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
4046 |
6565 | 4047 if (!abort) |
4048 { | |
4049 /* | |
4050 * 2. Free lists and dictionaries that are not referenced. | |
4051 */ | |
4052 did_free = free_unref_items(copyID); | |
4053 | |
4054 /* | |
4055 * 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
|
4056 * This may call us back recursively. |
6565 | 4057 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4058 free_unref_funccal(copyID, testing); |
6565 | 4059 } |
4060 else if (p_verbose > 0) | |
4061 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4062 verb_msg(_("Not enough memory to set references, garbage collection aborted!")); |
6565 | 4063 } |
1891 | 4064 |
4065 return did_free; | |
4066 } | |
4067 | |
4068 /* | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4069 * Free lists, dictionaries, channels and jobs that are no longer referenced. |
1891 | 4070 */ |
4071 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4072 free_unref_items(int copyID) |
1891 | 4073 { |
4074 int did_free = FALSE; | |
4075 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4076 // 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
|
4077 // 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
|
4078 // do that here. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4079 in_free_unref_items = TRUE; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4080 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4081 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4082 * 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
|
4083 * 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
|
4084 */ |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4085 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4086 // 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
|
4087 did_free |= dict_free_nonref(copyID); |
371 | 4088 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4089 // 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
|
4090 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
|
4091 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4092 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4093 // 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
|
4094 // 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
|
4095 // 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
|
4096 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
|
4097 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4098 // 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
|
4099 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
|
4100 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4101 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4102 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4103 * PASS 2: free the items themselves. |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4104 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4105 dict_free_items(copyID); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
9556
diff
changeset
|
4106 list_free_items(copyID); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4107 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4108 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4109 // 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
|
4110 // 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
|
4111 // 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
|
4112 free_unused_jobs(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4113 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4114 // 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
|
4115 free_unused_channels(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4116 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4117 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4118 in_free_unref_items = FALSE; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4119 |
371 | 4120 return did_free; |
4121 } | |
4122 | |
4123 /* | |
4124 * Mark all lists and dicts referenced through hashtab "ht" with "copyID". | |
6565 | 4125 * "list_stack" is used to add lists to be marked. Can be NULL. |
4126 * | |
4127 * Returns TRUE if setting references failed somehow. | |
4128 */ | |
4129 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4130 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack) |
364 | 4131 { |
4132 int todo; | |
6565 | 4133 int abort = FALSE; |
364 | 4134 hashitem_T *hi; |
6565 | 4135 hashtab_T *cur_ht; |
4136 ht_stack_T *ht_stack = NULL; | |
4137 ht_stack_T *tempitem; | |
4138 | |
4139 cur_ht = ht; | |
4140 for (;;) | |
4141 { | |
4142 if (!abort) | |
4143 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4144 // 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
|
4145 // 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
|
4146 // list_stack. |
6565 | 4147 todo = (int)cur_ht->ht_used; |
4148 for (hi = cur_ht->ht_array; todo > 0; ++hi) | |
4149 if (!HASHITEM_EMPTY(hi)) | |
4150 { | |
4151 --todo; | |
4152 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID, | |
4153 &ht_stack, list_stack); | |
4154 } | |
4155 } | |
4156 | |
4157 if (ht_stack == NULL) | |
4158 break; | |
4159 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4160 // take an item from the stack |
6565 | 4161 cur_ht = ht_stack->ht; |
4162 tempitem = ht_stack; | |
4163 ht_stack = ht_stack->prev; | |
4164 free(tempitem); | |
4165 } | |
4166 | |
4167 return abort; | |
371 | 4168 } |
4169 | |
4170 /* | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4171 * 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
|
4172 * 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
|
4173 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4174 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4175 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
|
4176 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4177 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
|
4178 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4179 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
|
4180 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
|
4181 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4182 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
|
4183 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4184 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4185 /* |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4186 * 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
|
4187 * 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
|
4188 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4189 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4190 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
|
4191 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4192 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
|
4193 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4194 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
|
4195 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
|
4196 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4197 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
|
4198 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4199 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4200 /* |
371 | 4201 * Mark all lists and dicts referenced through list "l" with "copyID". |
6565 | 4202 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. |
4203 * | |
4204 * Returns TRUE if setting references failed somehow. | |
4205 */ | |
4206 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
|
4207 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack) |
6565 | 4208 { |
4209 listitem_T *li; | |
4210 int abort = FALSE; | |
4211 list_T *cur_l; | |
4212 list_stack_T *list_stack = NULL; | |
4213 list_stack_T *tempitem; | |
4214 | |
4215 cur_l = l; | |
4216 for (;;) | |
4217 { | |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
4218 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
|
4219 // 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
|
4220 // 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
|
4221 // list_stack. |
6565 | 4222 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next) |
4223 abort = abort || set_ref_in_item(&li->li_tv, copyID, | |
4224 ht_stack, &list_stack); | |
4225 if (list_stack == NULL) | |
4226 break; | |
4227 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4228 // take an item from the stack |
6565 | 4229 cur_l = list_stack->list; |
4230 tempitem = list_stack; | |
4231 list_stack = list_stack->prev; | |
4232 free(tempitem); | |
4233 } | |
4234 | |
4235 return abort; | |
371 | 4236 } |
4237 | |
4238 /* | |
4239 * Mark all lists and dicts referenced through typval "tv" with "copyID". | |
6565 | 4240 * "list_stack" is used to add lists to be marked. Can be NULL. |
4241 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. | |
4242 * | |
4243 * Returns TRUE if setting references failed somehow. | |
4244 */ | |
4245 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4246 set_ref_in_item( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4247 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4248 int copyID, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4249 ht_stack_T **ht_stack, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4250 list_stack_T **list_stack) |
364 | 4251 { |
6565 | 4252 int abort = FALSE; |
364 | 4253 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4254 if (tv->v_type == VAR_DICT) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4255 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4256 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
|
4257 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4258 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
|
4259 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4260 // 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
|
4261 dd->dv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4262 if (ht_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4263 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4264 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
|
4265 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4266 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4267 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4268 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
|
4269 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4270 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4271 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4272 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4273 newitem->ht = &dd->dv_hashtab; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4274 newitem->prev = *ht_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4275 *ht_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4276 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4277 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4278 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4279 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4280 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
|
4281 { |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4282 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
|
4283 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4284 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
|
4285 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4286 // 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
|
4287 ll->lv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4288 if (list_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4289 { |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4290 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
|
4291 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4292 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4293 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4294 list_stack_T *newitem = (list_stack_T*)malloc( |
6565 | 4295 sizeof(list_stack_T)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4296 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4297 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4298 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4299 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4300 newitem->list = ll; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4301 newitem->prev = *list_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4302 *list_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4303 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4304 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4305 } |
6565 | 4306 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4307 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
|
4308 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4309 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
|
4310 } |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4311 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
|
4312 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4313 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
|
4314 int i; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4315 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4316 // A partial does not have a copyID, because it cannot contain itself. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4317 if (pt != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4318 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4319 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
|
4320 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4321 if (pt->pt_dict != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4322 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4323 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4324 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4325 dtv.v_type = VAR_DICT; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4326 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
|
4327 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
|
4328 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4329 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4330 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
|
4331 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
|
4332 ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4333 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4334 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4335 #ifdef FEAT_JOB_CHANNEL |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4336 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
|
4337 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4338 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
|
4339 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4340 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4341 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
|
4342 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4343 job->jv_copyID = copyID; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4344 if (job->jv_channel != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4345 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4346 dtv.v_type = VAR_CHANNEL; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4347 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
|
4348 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
|
4349 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4350 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
|
4351 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4352 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
|
4353 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
|
4354 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
|
4355 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4356 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4357 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4358 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
|
4359 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4360 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
|
4361 ch_part_T part; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4362 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4363 jsonq_T *jq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4364 cbq_T *cq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4365 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4366 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
|
4367 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4368 ch->ch_copyID = copyID; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10235
diff
changeset
|
4369 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
|
4370 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4371 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
|
4372 jq = jq->jq_next) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4373 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
|
4374 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
|
4375 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
|
4376 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
|
4377 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4378 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
|
4379 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
|
4380 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
|
4381 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4382 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
|
4383 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4384 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
|
4385 dtv.vval.v_partial = |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4386 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
|
4387 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
|
4388 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4389 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4390 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
|
4391 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4392 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
|
4393 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
|
4394 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
|
4395 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4396 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
|
4397 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4398 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
|
4399 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
|
4400 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
|
4401 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4402 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4403 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4404 #endif |
6565 | 4405 return abort; |
364 | 4406 } |
4407 | |
100 | 4408 /* |
56 | 4409 * Return a string with the string representation of a variable. |
4410 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
80 | 4411 * "numbuf" is used for a number. |
634 | 4412 * 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
|
4413 * 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
|
4414 * 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
|
4415 * ":echo" displays values. |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4416 * 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
|
4417 * are replaced with "...". |
1360 | 4418 * May return NULL. |
56 | 4419 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4420 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4421 echo_string_core( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4422 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4423 char_u **tofree, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4424 char_u *numbuf, |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4425 int copyID, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4426 int echo_style, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4427 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
|
4428 int composite_val) |
56 | 4429 { |
104 | 4430 static int recurse = 0; |
4431 char_u *r = NULL; | |
4432 | |
137 | 4433 if (recurse >= DICT_MAXNEST) |
104 | 4434 { |
5973 | 4435 if (!did_echo_string_emsg) |
4436 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4437 // 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
|
4438 // 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
|
4439 // and dicts. |
5973 | 4440 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
|
4441 emsg(_("E724: variable nested too deep for displaying")); |
5973 | 4442 } |
104 | 4443 *tofree = NULL; |
5973 | 4444 return (char_u *)"{E724}"; |
104 | 4445 } |
4446 ++recurse; | |
4447 | |
56 | 4448 switch (tv->v_type) |
4449 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4450 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
|
4451 if (echo_style && !composite_val) |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4452 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4453 *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
|
4454 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
|
4455 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
|
4456 r = (char_u *)""; |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4457 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4458 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4459 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4460 *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
|
4461 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4462 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4463 break; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4464 |
56 | 4465 case VAR_FUNC: |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4466 if (echo_style) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4467 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4468 *tofree = NULL; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4469 r = tv->vval.v_string; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4470 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4471 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4472 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4473 *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
|
4474 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4475 } |
104 | 4476 break; |
634 | 4477 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4478 case VAR_PARTIAL: |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4479 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4480 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
|
4481 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
|
4482 : partial_name(pt), FALSE); |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4483 garray_T ga; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4484 int i; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4485 char_u *tf; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4486 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4487 ga_init2(&ga, 1, 100); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4488 ga_concat(&ga, (char_u *)"function("); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4489 if (fname != NULL) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4490 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4491 ga_concat(&ga, fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4492 vim_free(fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4493 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4494 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
|
4495 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4496 ga_concat(&ga, (char_u *)", ["); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4497 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
|
4498 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4499 if (i > 0) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4500 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4501 ga_concat(&ga, |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4502 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
|
4503 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4504 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4505 ga_concat(&ga, (char_u *)"]"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4506 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4507 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
|
4508 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4509 typval_T dtv; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4510 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4511 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4512 dtv.v_type = VAR_DICT; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4513 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
|
4514 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
|
4515 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4516 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4517 ga_concat(&ga, (char_u *)")"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4518 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4519 *tofree = ga.ga_data; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4520 r = *tofree; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4521 break; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4522 } |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4523 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4524 case VAR_BLOB: |
15466
435fcefd2c8e
patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15464
diff
changeset
|
4525 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
|
4526 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4527 |
56 | 4528 case VAR_LIST: |
634 | 4529 if (tv->vval.v_list == NULL) |
4530 { | |
4531 *tofree = NULL; | |
4532 r = NULL; | |
4533 } | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4534 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
|
4535 && tv->vval.v_list->lv_len > 0) |
634 | 4536 { |
4537 *tofree = NULL; | |
4538 r = (char_u *)"[...]"; | |
4539 } | |
4540 else | |
4541 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4542 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
|
4543 |
634 | 4544 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
|
4545 *tofree = list2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4546 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4547 tv->vval.v_list->lv_copyID = old_copyID; |
634 | 4548 r = *tofree; |
4549 } | |
4550 break; | |
4551 | |
100 | 4552 case VAR_DICT: |
634 | 4553 if (tv->vval.v_dict == NULL) |
4554 { | |
4555 *tofree = NULL; | |
4556 r = NULL; | |
4557 } | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4558 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
|
4559 && tv->vval.v_dict->dv_hashtab.ht_used != 0) |
634 | 4560 { |
4561 *tofree = NULL; | |
4562 r = (char_u *)"{...}"; | |
4563 } | |
4564 else | |
4565 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4566 int old_copyID = tv->vval.v_dict->dv_copyID; |
634 | 4567 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
|
4568 *tofree = dict2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4569 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4570 tv->vval.v_dict->dv_copyID = old_copyID; |
634 | 4571 r = *tofree; |
4572 } | |
4573 break; | |
4574 | |
71 | 4575 case VAR_NUMBER: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4576 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
|
4577 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
|
4578 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
|
4579 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4580 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
|
4581 break; |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4582 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4583 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
4584 case VAR_CHANNEL: |
104 | 4585 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4586 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
|
4587 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
|
4588 { |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4589 *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
|
4590 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
|
4591 } |
71 | 4592 break; |
634 | 4593 |
1624 | 4594 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4595 #ifdef FEAT_FLOAT |
1624 | 4596 *tofree = NULL; |
4597 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float); | |
4598 r = numbuf; | |
4599 break; | |
4600 #endif | |
4601 | |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
4602 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4603 case VAR_SPECIAL: |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4604 *tofree = NULL; |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
4605 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
|
4606 break; |
104 | 4607 } |
4608 | |
5973 | 4609 if (--recurse == 0) |
4610 did_echo_string_emsg = FALSE; | |
104 | 4611 return r; |
97 | 4612 } |
4613 | |
4614 /* | |
4615 * Return a string with the string representation of a variable. | |
4616 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
4617 * "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
|
4618 * 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
|
4619 * 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
|
4620 * May return NULL. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4621 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4622 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4623 echo_string( |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4624 typval_T *tv, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4625 char_u **tofree, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4626 char_u *numbuf, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4627 int copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4628 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4629 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
|
4630 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4631 |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4632 /* |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4633 * Return a string with the string representation of a variable. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4634 * If the memory is allocated "tofree" is set to it, otherwise NULL. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4635 * "numbuf" is used for a number. |
97 | 4636 * Puts quotes around strings, so that they can be parsed back by eval(). |
1360 | 4637 * May return NULL. |
97 | 4638 */ |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8887
diff
changeset
|
4639 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4640 tv2string( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4641 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4642 char_u **tofree, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4643 char_u *numbuf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4644 int copyID) |
97 | 4645 { |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4646 return echo_string_core(tv, tofree, numbuf, copyID, FALSE, TRUE, FALSE); |
56 | 4647 } |
4648 | |
4649 /* | |
137 | 4650 * Return string "str" in ' quotes, doubling ' characters. |
4651 * If "str" is NULL an empty string is assumed. | |
100 | 4652 * If "function" is TRUE make it function('string'). |
97 | 4653 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4654 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4655 string_quote(char_u *str, int function) |
97 | 4656 { |
137 | 4657 unsigned len; |
97 | 4658 char_u *p, *r, *s; |
4659 | |
137 | 4660 len = (function ? 13 : 3); |
4661 if (str != NULL) | |
4662 { | |
835 | 4663 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
|
4664 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
137 | 4665 if (*p == '\'') |
4666 ++len; | |
4667 } | |
97 | 4668 s = r = alloc(len); |
4669 if (r != NULL) | |
4670 { | |
4671 if (function) | |
4672 { | |
100 | 4673 STRCPY(r, "function('"); |
97 | 4674 r += 10; |
4675 } | |
4676 else | |
100 | 4677 *r++ = '\''; |
137 | 4678 if (str != NULL) |
4679 for (p = str; *p != NUL; ) | |
4680 { | |
4681 if (*p == '\'') | |
4682 *r++ = '\''; | |
4683 MB_COPY_CHAR(p, r); | |
4684 } | |
100 | 4685 *r++ = '\''; |
97 | 4686 if (function) |
4687 *r++ = ')'; | |
4688 *r++ = NUL; | |
4689 } | |
4690 return s; | |
4691 } | |
4692 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4693 #if defined(FEAT_FLOAT) || defined(PROTO) |
1624 | 4694 /* |
4695 * Convert the string "text" to a floating point number. | |
4696 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure | |
4697 * this always uses a decimal point. | |
4698 * Returns the length of the text that was consumed. | |
4699 */ | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4700 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4701 string2float( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4702 char_u *text, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4703 float_T *value) // result stored here |
1624 | 4704 { |
4705 char *s = (char *)text; | |
4706 float_T f; | |
4707 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4708 // 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
|
4709 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
|
4710 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4711 *value = INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4712 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4713 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4714 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
|
4715 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4716 *value = -INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4717 return 4; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4718 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4719 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
|
4720 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4721 *value = NAN; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4722 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4723 } |
1624 | 4724 f = strtod(s, &s); |
4725 *value = f; | |
4726 return (int)((char_u *)s - text); | |
4727 } | |
4728 #endif | |
4729 | |
97 | 4730 /* |
7 | 4731 * Get the value of an environment variable. |
4732 * "arg" is pointing to the '$'. It is advanced to after the name. | |
4733 * If the environment variable was not set, silently assume it is empty. | |
5858 | 4734 * Return FAIL if the name is invalid. |
7 | 4735 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
4736 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4737 get_env_tv(char_u **arg, typval_T *rettv, int evaluate) |
7 | 4738 { |
4739 char_u *string = NULL; | |
4740 int len; | |
4741 int cc; | |
4742 char_u *name; | |
170 | 4743 int mustfree = FALSE; |
7 | 4744 |
4745 ++*arg; | |
4746 name = *arg; | |
4747 len = get_env_len(arg); | |
4748 if (evaluate) | |
4749 { | |
5858 | 4750 if (len == 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4751 return FAIL; // invalid empty name |
5858 | 4752 |
4753 cc = name[len]; | |
4754 name[len] = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4755 // first try vim_getenv(), fast for normal environment vars |
5858 | 4756 string = vim_getenv(name, &mustfree); |
4757 if (string != NULL && *string != NUL) | |
4758 { | |
4759 if (!mustfree) | |
4760 string = vim_strsave(string); | |
4761 } | |
4762 else | |
4763 { | |
4764 if (mustfree) | |
4765 vim_free(string); | |
4766 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4767 // next try expanding things like $VIM and ${HOME} |
5858 | 4768 string = expand_env_save(name - 1); |
4769 if (string != NULL && *string == '$') | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
4770 VIM_CLEAR(string); |
5858 | 4771 } |
4772 name[len] = cc; | |
4773 | |
71 | 4774 rettv->v_type = VAR_STRING; |
4775 rettv->vval.v_string = string; | |
7 | 4776 } |
4777 | |
4778 return OK; | |
4779 } | |
4780 | |
3214 | 4781 /* |
7 | 4782 * Translate a String variable into a position. |
685 | 4783 * Returns NULL when there is an error. |
7 | 4784 */ |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4785 pos_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4786 var2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4787 typval_T *varp, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4788 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
|
4789 int *fnum) // set to fnum for '0, 'A, etc. |
7 | 4790 { |
700 | 4791 char_u *name; |
7 | 4792 static pos_T pos; |
700 | 4793 pos_T *pp; |
7 | 4794 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4795 // Argument can be [lnum, col, coladd]. |
685 | 4796 if (varp->v_type == VAR_LIST) |
4797 { | |
4798 list_T *l; | |
4799 int len; | |
705 | 4800 int error = FALSE; |
1317 | 4801 listitem_T *li; |
685 | 4802 |
4803 l = varp->vval.v_list; | |
4804 if (l == NULL) | |
4805 return NULL; | |
4806 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4807 // Get the line number |
705 | 4808 pos.lnum = list_find_nr(l, 0L, &error); |
4809 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
|
4810 return NULL; // invalid line number |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4811 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4812 // Get the column number |
705 | 4813 pos.col = list_find_nr(l, 1L, &error); |
4814 if (error) | |
685 | 4815 return NULL; |
4816 len = (long)STRLEN(ml_get(pos.lnum)); | |
1317 | 4817 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4818 // We accept "$" for the column number: last column. |
1317 | 4819 li = list_find(l, 1L); |
4820 if (li != NULL && li->li_tv.v_type == VAR_STRING | |
4821 && li->li_tv.vval.v_string != NULL | |
4822 && STRCMP(li->li_tv.vval.v_string, "$") == 0) | |
4823 pos.col = len + 1; | |
4824 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4825 // Accept a position up to the NUL after the line. |
826 | 4826 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
|
4827 return NULL; // invalid column number |
705 | 4828 --pos.col; |
4829 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4830 // Get the virtual offset. Defaults to zero. |
705 | 4831 pos.coladd = list_find_nr(l, 2L, &error); |
4832 if (error) | |
4833 pos.coladd = 0; | |
4834 | |
685 | 4835 return &pos; |
4836 } | |
4837 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4838 name = tv_get_string_chk(varp); |
323 | 4839 if (name == NULL) |
4840 return NULL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4841 if (name[0] == '.') // cursor |
7 | 4842 return &curwin->w_cursor; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4843 if (name[0] == 'v' && name[1] == NUL) // Visual start |
1609 | 4844 { |
4845 if (VIsual_active) | |
4846 return &VIsual; | |
4847 return &curwin->w_cursor; | |
4848 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4849 if (name[0] == '\'') // mark |
7 | 4850 { |
4043 | 4851 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); |
7 | 4852 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) |
4853 return NULL; | |
4854 return pp; | |
4855 } | |
705 | 4856 |
4857 pos.coladd = 0; | |
4858 | |
1317 | 4859 if (name[0] == 'w' && dollar_lnum) |
666 | 4860 { |
4861 pos.col = 0; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4862 if (name[1] == '0') // "w0": first visible line |
666 | 4863 { |
671 | 4864 update_topline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4865 // 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
|
4866 // 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
|
4867 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; |
666 | 4868 return &pos; |
4869 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4870 else if (name[1] == '$') // "w$": last visible line |
666 | 4871 { |
671 | 4872 validate_botline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4873 // 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
|
4874 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; |
666 | 4875 return &pos; |
4876 } | |
4877 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4878 else if (name[0] == '$') // last column or line |
7 | 4879 { |
1317 | 4880 if (dollar_lnum) |
7 | 4881 { |
4882 pos.lnum = curbuf->b_ml.ml_line_count; | |
4883 pos.col = 0; | |
4884 } | |
4885 else | |
4886 { | |
4887 pos.lnum = curwin->w_cursor.lnum; | |
4888 pos.col = (colnr_T)STRLEN(ml_get_curline()); | |
4889 } | |
4890 return &pos; | |
4891 } | |
4892 return NULL; | |
4893 } | |
4894 | |
4895 /* | |
709 | 4896 * Convert list in "arg" into a position and optional file number. |
4897 * When "fnump" is NULL there is no file number, only 3 items. | |
4898 * Note that the column is passed on as-is, the caller may want to decrement | |
4899 * it to use 1 for the first column. | |
4900 * Return FAIL when conversion is not possible, doesn't check the position for | |
4901 * validity. | |
4902 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4903 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4904 list2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4905 typval_T *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4906 pos_T *posp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4907 int *fnump, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4908 colnr_T *curswantp) |
709 | 4909 { |
4910 list_T *l = arg->vval.v_list; | |
4911 long i = 0; | |
4912 long n; | |
4913 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4914 // 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
|
4915 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional. |
915 | 4916 if (arg->v_type != VAR_LIST |
4917 || l == NULL | |
4918 || l->lv_len < (fnump == NULL ? 2 : 3) | |
5938 | 4919 || l->lv_len > (fnump == NULL ? 4 : 5)) |
709 | 4920 return FAIL; |
4921 | |
4922 if (fnump != NULL) | |
4923 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4924 n = list_find_nr(l, i++, NULL); // fnum |
709 | 4925 if (n < 0) |
4926 return FAIL; | |
4927 if (n == 0) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4928 n = curbuf->b_fnum; // current buffer |
709 | 4929 *fnump = n; |
4930 } | |
4931 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4932 n = list_find_nr(l, i++, NULL); // lnum |
709 | 4933 if (n < 0) |
4934 return FAIL; | |
4935 posp->lnum = n; | |
4936 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4937 n = list_find_nr(l, i++, NULL); // col |
709 | 4938 if (n < 0) |
4939 return FAIL; | |
4940 posp->col = n; | |
4941 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4942 n = list_find_nr(l, i, NULL); // off |
709 | 4943 if (n < 0) |
915 | 4944 posp->coladd = 0; |
4945 else | |
4946 posp->coladd = n; | |
709 | 4947 |
5938 | 4948 if (curswantp != NULL) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4949 *curswantp = list_find_nr(l, i + 1, NULL); // curswant |
5938 | 4950 |
709 | 4951 return OK; |
4952 } | |
4953 | |
4954 /* | |
7 | 4955 * Get the length of an environment variable name. |
4956 * Advance "arg" to the first character after the name. | |
4957 * Return 0 for error. | |
4958 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
4959 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4960 get_env_len(char_u **arg) |
7 | 4961 { |
4962 char_u *p; | |
4963 int len; | |
4964 | |
4965 for (p = *arg; vim_isIDc(*p); ++p) | |
4966 ; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4967 if (p == *arg) // no name found |
7 | 4968 return 0; |
4969 | |
4970 len = (int)(p - *arg); | |
4971 *arg = p; | |
4972 return len; | |
4973 } | |
4974 | |
4975 /* | |
4976 * Get the length of the name of a function or internal variable. | |
4977 * "arg" is advanced to the first non-white character after the name. | |
4978 * Return 0 if something is wrong. | |
4979 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4980 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4981 get_id_len(char_u **arg) |
7 | 4982 { |
4983 char_u *p; | |
4984 int len; | |
4985 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4986 // Find the end of the name. |
7 | 4987 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
|
4988 { |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4989 if (*p == ':') |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4990 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4991 // "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
|
4992 // 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
|
4993 len = (int)(p - *arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4994 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
|
4995 || len > 1) |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4996 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4997 } |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4998 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4999 if (p == *arg) // no name found |
7 | 5000 return 0; |
5001 | |
5002 len = (int)(p - *arg); | |
5003 *arg = skipwhite(p); | |
5004 | |
5005 return len; | |
5006 } | |
5007 | |
5008 /* | |
124 | 5009 * Get the length of the name of a variable or function. |
5010 * Only the name is recognized, does not handle ".key" or "[idx]". | |
7 | 5011 * "arg" is advanced to the first non-white character after the name. |
159 | 5012 * Return -1 if curly braces expansion failed. |
5013 * Return 0 if something else is wrong. | |
7 | 5014 * If the name contains 'magic' {}'s, expand them and return the |
5015 * expanded name in an allocated string via 'alias' - caller must free. | |
5016 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
5017 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5018 get_name_len( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5019 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5020 char_u **alias, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5021 int evaluate, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5022 int verbose) |
7 | 5023 { |
5024 int len; | |
5025 char_u *p; | |
5026 char_u *expr_start; | |
5027 char_u *expr_end; | |
5028 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5029 *alias = NULL; // default to no alias |
7 | 5030 |
5031 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA | |
5032 && (*arg)[2] == (int)KE_SNR) | |
5033 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5034 // hard coded <SNR>, already translated |
7 | 5035 *arg += 3; |
5036 return get_id_len(arg) + 3; | |
5037 } | |
5038 len = eval_fname_script(*arg); | |
5039 if (len > 0) | |
5040 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5041 // literal "<SID>", "s:" or "<SNR>" |
7 | 5042 *arg += len; |
5043 } | |
5044 | |
5045 /* | |
71 | 5046 * Find the end of the name; check for {} construction. |
7 | 5047 */ |
271 | 5048 p = find_name_end(*arg, &expr_start, &expr_end, |
5049 len > 0 ? 0 : FNE_CHECK_START); | |
7 | 5050 if (expr_start != NULL) |
5051 { | |
5052 char_u *temp_string; | |
5053 | |
5054 if (!evaluate) | |
5055 { | |
5056 len += (int)(p - *arg); | |
5057 *arg = skipwhite(p); | |
5058 return len; | |
5059 } | |
5060 | |
5061 /* | |
5062 * Include any <SID> etc in the expanded string: | |
5063 * Thus the -len here. | |
5064 */ | |
5065 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p); | |
5066 if (temp_string == NULL) | |
159 | 5067 return -1; |
7 | 5068 *alias = temp_string; |
5069 *arg = skipwhite(p); | |
5070 return (int)STRLEN(temp_string); | |
5071 } | |
5072 | |
5073 len += get_id_len(arg); | |
15464
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
5074 // 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
|
5075 // reported at a higher level. |
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
5076 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
|
5077 semsg(_(e_invexpr2), *arg); |
7 | 5078 |
5079 return len; | |
5080 } | |
5081 | |
71 | 5082 /* |
5083 * Find the end of a variable or function name, taking care of magic braces. | |
5084 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the | |
5085 * start and end of the first magic braces item. | |
271 | 5086 * "flags" can have FNE_INCL_BR and FNE_CHECK_START. |
71 | 5087 * Return a pointer to just after the name. Equal to "arg" if there is no |
5088 * valid name. | |
5089 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5090 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5091 find_name_end( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5092 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5093 char_u **expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5094 char_u **expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5095 int flags) |
71 | 5096 { |
5097 int mb_nest = 0; | |
5098 int br_nest = 0; | |
7 | 5099 char_u *p; |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5100 int len; |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
5101 int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; |
7 | 5102 |
71 | 5103 if (expr_start != NULL) |
5104 { | |
5105 *expr_start = NULL; | |
5106 *expr_end = NULL; | |
5107 } | |
5108 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5109 // 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
|
5110 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
|
5111 && (*arg != '{' || vim9script)) |
271 | 5112 return arg; |
5113 | |
71 | 5114 for (p = arg; *p != NUL |
5115 && (eval_isnamec(*p) | |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
5116 || (*p == '{' && !vim9script) |
271 | 5117 || ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.')) |
71 | 5118 || mb_nest != 0 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
5119 || br_nest != 0); MB_PTR_ADV(p)) |
468 | 5120 { |
5121 if (*p == '\'') | |
5122 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5123 // 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
|
5124 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) |
468 | 5125 ; |
5126 if (*p == NUL) | |
5127 break; | |
5128 } | |
5129 else if (*p == '"') | |
5130 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5131 // 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
|
5132 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
468 | 5133 if (*p == '\\' && p[1] != NUL) |
5134 ++p; | |
5135 if (*p == NUL) | |
5136 break; | |
5137 } | |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5138 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
|
5139 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5140 // "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
|
5141 // 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
|
5142 len = (int)(p - arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5143 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
|
5144 || (len > 1 && p[-1] != '}')) |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5145 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5146 } |
468 | 5147 |
71 | 5148 if (mb_nest == 0) |
5149 { | |
5150 if (*p == '[') | |
5151 ++br_nest; | |
5152 else if (*p == ']') | |
5153 --br_nest; | |
5154 } | |
468 | 5155 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20061
diff
changeset
|
5156 if (br_nest == 0 && !vim9script) |
71 | 5157 { |
5158 if (*p == '{') | |
5159 { | |
5160 mb_nest++; | |
5161 if (expr_start != NULL && *expr_start == NULL) | |
5162 *expr_start = p; | |
5163 } | |
5164 else if (*p == '}') | |
5165 { | |
5166 mb_nest--; | |
5167 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) | |
5168 *expr_end = p; | |
5169 } | |
5170 } | |
7 | 5171 } |
5172 | |
5173 return p; | |
5174 } | |
5175 | |
5176 /* | |
159 | 5177 * Expands out the 'magic' {}'s in a variable/function name. |
5178 * Note that this can call itself recursively, to deal with | |
5179 * constructs like foo{bar}{baz}{bam} | |
5180 * The four pointer arguments point to "foo{expre}ss{ion}bar" | |
5181 * "in_start" ^ | |
5182 * "expr_start" ^ | |
5183 * "expr_end" ^ | |
5184 * "in_end" ^ | |
5185 * | |
5186 * Returns a new allocated string, which the caller must free. | |
5187 * Returns NULL for failure. | |
5188 */ | |
5189 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5190 make_expanded_name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5191 char_u *in_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5192 char_u *expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5193 char_u *expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5194 char_u *in_end) |
159 | 5195 { |
5196 char_u c1; | |
5197 char_u *retval = NULL; | |
5198 char_u *temp_result; | |
5199 char_u *nextcmd = NULL; | |
5200 | |
5201 if (expr_end == NULL || in_end == NULL) | |
5202 return NULL; | |
5203 *expr_start = NUL; | |
5204 *expr_end = NUL; | |
5205 c1 = *in_end; | |
5206 *in_end = NUL; | |
5207 | |
714 | 5208 temp_result = eval_to_string(expr_start + 1, &nextcmd, FALSE); |
159 | 5209 if (temp_result != NULL && nextcmd == NULL) |
5210 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5211 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
|
5212 + (in_end - expr_end) + 1); |
159 | 5213 if (retval != NULL) |
5214 { | |
5215 STRCPY(retval, in_start); | |
5216 STRCAT(retval, temp_result); | |
5217 STRCAT(retval, expr_end + 1); | |
5218 } | |
5219 } | |
5220 vim_free(temp_result); | |
5221 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5222 *in_end = c1; // put char back for error messages |
159 | 5223 *expr_start = '{'; |
5224 *expr_end = '}'; | |
5225 | |
5226 if (retval != NULL) | |
5227 { | |
271 | 5228 temp_result = find_name_end(retval, &expr_start, &expr_end, 0); |
159 | 5229 if (expr_start != NULL) |
5230 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5231 // Further expansion! |
159 | 5232 temp_result = make_expanded_name(retval, expr_start, |
5233 expr_end, temp_result); | |
5234 vim_free(retval); | |
5235 retval = temp_result; | |
5236 } | |
5237 } | |
5238 | |
5239 return retval; | |
5240 } | |
5241 | |
5242 /* | |
7 | 5243 * Return TRUE if character "c" can be used in a variable or function name. |
104 | 5244 * Does not include '{' or '}' for magic braces. |
7 | 5245 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5246 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5247 eval_isnamec(int c) |
7 | 5248 { |
271 | 5249 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); |
5250 } | |
5251 | |
5252 /* | |
5253 * Return TRUE if character "c" can be used as the first character in a | |
5254 * variable or function name (excluding '{' and '}'). | |
5255 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5256 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5257 eval_isnamec1(int c) |
271 | 5258 { |
5259 return (ASCII_ISALPHA(c) || c == '_'); | |
7 | 5260 } |
5261 | |
5262 /* | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5263 * Handle: |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5264 * - 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
|
5265 * - ".name" lookup |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5266 * - 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
|
5267 * - method call: var->method() |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5268 * |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5269 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len() |
159 | 5270 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5271 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5272 handle_subscript( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5273 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5274 typval_T *rettv, |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5275 int evaluate, // do more than finding the end |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5276 int verbose, // give error messages |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5277 char_u *start_leader, // start of '!' and '-' prefixes |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5278 char_u **end_leaderp) // end of '!' and '-' prefixes |
159 | 5279 { |
5280 int ret = OK; | |
5281 dict_T *selfdict = NULL; | |
5282 | |
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
|
5283 // "." 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
|
5284 // scriptversion is at least 2, where string concatenation is "..". |
159 | 5285 while (ret == OK |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5286 && (((**arg == '[' |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5287 || (**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
|
5288 || (!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
|
5289 && (*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
|
5290 && 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
|
5291 || (**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
|
5292 || 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
|
5293 && !VIM_ISWHITE(*(*arg - 1))) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5294 || (**arg == '-' && (*arg)[1] == '>'))) |
159 | 5295 { |
5296 if (**arg == '(') | |
5297 { | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5298 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
|
5299 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5300 // 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
|
5301 // 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
|
5302 // but not caught. |
159 | 5303 if (aborting()) |
5304 { | |
5305 if (ret == OK) | |
5306 clear_tv(rettv); | |
5307 ret = FAIL; | |
5308 } | |
5309 dict_unref(selfdict); | |
5310 selfdict = NULL; | |
5311 } | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5312 else if (**arg == '-') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5313 { |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5314 // Expression "-1.0->method()" applies the leader "-" before |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5315 // applying ->. |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5316 if (evaluate && *end_leaderp > start_leader) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5317 ret = eval7_leader(rettv, start_leader, end_leaderp); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5318 if (ret == OK) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5319 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5320 if ((*arg)[2] == '{') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5321 // expr->{lambda}() |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5322 ret = eval_lambda(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
|
5323 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5324 // expr->name() |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5325 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
|
5326 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5327 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5328 else // **arg == '[' || **arg == '.' |
159 | 5329 { |
5330 dict_unref(selfdict); | |
5331 if (rettv->v_type == VAR_DICT) | |
5332 { | |
5333 selfdict = rettv->vval.v_dict; | |
5334 if (selfdict != NULL) | |
5335 ++selfdict->dv_refcount; | |
5336 } | |
5337 else | |
5338 selfdict = NULL; | |
5339 if (eval_index(arg, rettv, evaluate, verbose) == FAIL) | |
5340 { | |
5341 clear_tv(rettv); | |
5342 ret = FAIL; | |
5343 } | |
5344 } | |
5345 } | |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5346 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5347 // 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
|
5348 // 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
|
5349 // explicitly (pt_auto is FALSE). |
9104
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5350 if (selfdict != NULL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5351 && (rettv->v_type == VAR_FUNC |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5352 || (rettv->v_type == VAR_PARTIAL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5353 && (rettv->vval.v_partial->pt_auto |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5354 || 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
|
5355 selfdict = make_partial(selfdict, rettv); |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5356 |
159 | 5357 dict_unref(selfdict); |
5358 return ret; | |
5359 } | |
5360 | |
5361 /* | |
1624 | 5362 * Allocate memory for a variable type-value, and make it empty (0 or NULL |
56 | 5363 * value). |
5364 */ | |
7877
7fbd2de703a9
commit https://github.com/vim/vim/commit/11e0afa00a8e6c0aa1d50f760b5d5cb62dade038
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
5365 typval_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5366 alloc_tv(void) |
56 | 5367 { |
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
|
5368 return ALLOC_CLEAR_ONE(typval_T); |
56 | 5369 } |
5370 | |
5371 /* | |
5372 * Allocate memory for a variable type-value, and assign a string to it. | |
7 | 5373 * The string "s" must have been allocated, it is consumed. |
5374 * Return NULL for out of memory, the variable otherwise. | |
5375 */ | |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
5376 typval_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5377 alloc_string_tv(char_u *s) |
7 | 5378 { |
137 | 5379 typval_T *rettv; |
71 | 5380 |
5381 rettv = alloc_tv(); | |
5382 if (rettv != NULL) | |
5383 { | |
5384 rettv->v_type = VAR_STRING; | |
5385 rettv->vval.v_string = s; | |
7 | 5386 } |
5387 else | |
5388 vim_free(s); | |
71 | 5389 return rettv; |
7 | 5390 } |
5391 | |
5392 /* | |
56 | 5393 * Free the memory for a variable type-value. |
5394 */ | |
625 | 5395 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5396 free_tv(typval_T *varp) |
7 | 5397 { |
5398 if (varp != NULL) | |
5399 { | |
56 | 5400 switch (varp->v_type) |
5401 { | |
117 | 5402 case VAR_FUNC: |
5403 func_unref(varp->vval.v_string); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5404 // FALLTHROUGH |
56 | 5405 case VAR_STRING: |
5406 vim_free(varp->vval.v_string); | |
5407 break; | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5408 case VAR_PARTIAL: |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5409 partial_unref(varp->vval.v_partial); |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5410 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5411 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5412 blob_unref(varp->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5413 break; |
56 | 5414 case VAR_LIST: |
5415 list_unref(varp->vval.v_list); | |
5416 break; | |
117 | 5417 case VAR_DICT: |
5418 dict_unref(varp->vval.v_dict); | |
5419 break; | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5420 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5421 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5422 job_unref(varp->vval.v_job); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5423 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5424 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5425 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5426 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5427 channel_unref(varp->vval.v_channel); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5428 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5429 #endif |
156 | 5430 case VAR_NUMBER: |
1624 | 5431 case VAR_FLOAT: |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
5432 case VAR_ANY: |
156 | 5433 case VAR_UNKNOWN: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5434 case VAR_VOID: |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5435 case VAR_BOOL: |
7768
3d8e4e0d7127
commit https://github.com/vim/vim/commit/6650a694547eb744afa060ec62dd8270e99db9f2
Christian Brabandt <cb@256bit.org>
parents:
7765
diff
changeset
|
5436 case VAR_SPECIAL: |
156 | 5437 break; |
56 | 5438 } |
7 | 5439 vim_free(varp); |
5440 } | |
5441 } | |
5442 | |
5443 /* | |
5444 * Free the memory for a variable value and set the value to NULL or 0. | |
5445 */ | |
446 | 5446 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5447 clear_tv(typval_T *varp) |
7 | 5448 { |
5449 if (varp != NULL) | |
5450 { | |
56 | 5451 switch (varp->v_type) |
5452 { | |
117 | 5453 case VAR_FUNC: |
5454 func_unref(varp->vval.v_string); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5455 // FALLTHROUGH |
56 | 5456 case VAR_STRING: |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
5457 VIM_CLEAR(varp->vval.v_string); |
56 | 5458 break; |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5459 case VAR_PARTIAL: |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5460 partial_unref(varp->vval.v_partial); |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5461 varp->vval.v_partial = NULL; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5462 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5463 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5464 blob_unref(varp->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5465 varp->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5466 break; |
56 | 5467 case VAR_LIST: |
5468 list_unref(varp->vval.v_list); | |
121 | 5469 varp->vval.v_list = NULL; |
56 | 5470 break; |
100 | 5471 case VAR_DICT: |
5472 dict_unref(varp->vval.v_dict); | |
121 | 5473 varp->vval.v_dict = NULL; |
100 | 5474 break; |
71 | 5475 case VAR_NUMBER: |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5476 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
5477 case VAR_SPECIAL: |
56 | 5478 varp->vval.v_number = 0; |
5479 break; | |
1624 | 5480 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5481 #ifdef FEAT_FLOAT |
1624 | 5482 varp->vval.v_float = 0.0; |
5483 break; | |
5484 #endif | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5485 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5486 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5487 job_unref(varp->vval.v_job); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5488 varp->vval.v_job = NULL; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5489 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5490 break; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5491 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5492 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5493 channel_unref(varp->vval.v_channel); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5494 varp->vval.v_channel = NULL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5495 #endif |
71 | 5496 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
|
5497 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
|
5498 case VAR_VOID: |
71 | 5499 break; |
5500 } | |
151 | 5501 varp->v_lock = 0; |
71 | 5502 } |
5503 } | |
5504 | |
5505 /* | |
5506 * Set the value of a variable to NULL without freeing items. | |
5507 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
5508 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5509 init_tv(typval_T *varp) |
71 | 5510 { |
5511 if (varp != NULL) | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
5512 CLEAR_POINTER(varp); |
7 | 5513 } |
5514 | |
5515 /* | |
5516 * Get the number value of a variable. | |
5517 * If it is a String variable, uses vim_str2nr(). | |
323 | 5518 * For incompatible types, return 0. |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5519 * tv_get_number_chk() is similar to tv_get_number(), but informs the |
323 | 5520 * caller of incompatible types: it sets *denote to TRUE if "denote" |
5521 * is not NULL or returns -1 otherwise. | |
7 | 5522 */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5523 varnumber_T |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5524 tv_get_number(typval_T *varp) |
56 | 5525 { |
323 | 5526 int error = FALSE; |
5527 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5528 return tv_get_number_chk(varp, &error); // return 0L on error |
323 | 5529 } |
5530 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5531 varnumber_T |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5532 tv_get_number_chk(typval_T *varp, int *denote) |
323 | 5533 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5534 varnumber_T n = 0L; |
56 | 5535 |
5536 switch (varp->v_type) | |
5537 { | |
5538 case VAR_NUMBER: | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5539 return varp->vval.v_number; |
1624 | 5540 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5541 #ifdef FEAT_FLOAT |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5542 emsg(_("E805: Using a Float as a Number")); |
1624 | 5543 break; |
5544 #endif | |
56 | 5545 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5546 case VAR_PARTIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5547 emsg(_("E703: Using a Funcref as a Number")); |
56 | 5548 break; |
5549 case VAR_STRING: | |
5550 if (varp->vval.v_string != NULL) | |
5551 vim_str2nr(varp->vval.v_string, NULL, NULL, | |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
5552 STR2NR_ALL, &n, NULL, 0, FALSE); |
323 | 5553 return n; |
97 | 5554 case VAR_LIST: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5555 emsg(_("E745: Using a List as a Number")); |
97 | 5556 break; |
117 | 5557 case VAR_DICT: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5558 emsg(_("E728: Using a Dictionary as a Number")); |
117 | 5559 break; |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5560 case VAR_BOOL: |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5561 case VAR_SPECIAL: |
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5562 return varp->vval.v_number == VVAL_TRUE ? 1 : 0; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5563 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5564 #ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5565 emsg(_("E910: Using a Job as a Number")); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5566 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5567 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5568 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5569 #ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5570 emsg(_("E913: Using a Channel as a Number")); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5571 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5572 #endif |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5573 case VAR_BLOB: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5574 emsg(_("E974: Using a Blob as a Number")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5575 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5576 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
|
5577 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
|
5578 case VAR_VOID: |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
5579 internal_error_no_abort("tv_get_number(UNKNOWN)"); |
56 | 5580 break; |
5581 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5582 if (denote == NULL) // useful for values that must be unsigned |
323 | 5583 n = -1; |
5584 else | |
5585 *denote = TRUE; | |
56 | 5586 return n; |
7 | 5587 } |
5588 | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5589 #ifdef FEAT_FLOAT |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
5590 float_T |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5591 tv_get_float(typval_T *varp) |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5592 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5593 switch (varp->v_type) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5594 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5595 case VAR_NUMBER: |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5596 return (float_T)(varp->vval.v_number); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5597 case VAR_FLOAT: |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5598 return varp->vval.v_float; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5599 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5600 case VAR_PARTIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5601 emsg(_("E891: Using a Funcref as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5602 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5603 case VAR_STRING: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5604 emsg(_("E892: Using a String as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5605 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5606 case VAR_LIST: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5607 emsg(_("E893: Using a List as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5608 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5609 case VAR_DICT: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5610 emsg(_("E894: Using a Dictionary as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5611 break; |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5612 case VAR_BOOL: |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5613 emsg(_("E362: Using a boolean value as a Float")); |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5614 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5615 case VAR_SPECIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5616 emsg(_("E907: Using a special value as a Float")); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5617 break; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5618 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5619 # ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5620 emsg(_("E911: Using a Job as a Float")); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5621 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5622 # endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5623 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5624 # ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5625 emsg(_("E914: Using a Channel as a Float")); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5626 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5627 # endif |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5628 case VAR_BLOB: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5629 emsg(_("E975: Using a Blob as a Float")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5630 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5631 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
|
5632 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
|
5633 case VAR_VOID: |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
5634 internal_error_no_abort("tv_get_float(UNKNOWN)"); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5635 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5636 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5637 return 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5638 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5639 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5640 |
7 | 5641 /* |
5642 * Get the string value of a variable. | |
5643 * If it is a Number variable, the number is converted into a string. | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5644 * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE! |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5645 * tv_get_string_buf() uses a given buffer. |
7 | 5646 * If the String variable has never been set, return an empty string. |
5647 * Never returns NULL; | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5648 * tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return |
323 | 5649 * NULL on error. |
7 | 5650 */ |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5651 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5652 tv_get_string(typval_T *varp) |
7 | 5653 { |
5654 static char_u mybuf[NUMBUFLEN]; | |
5655 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5656 return tv_get_string_buf(varp, mybuf); |
7 | 5657 } |
5658 | |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5659 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5660 tv_get_string_buf(typval_T *varp, char_u *buf) |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5661 { |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5662 char_u *res = tv_get_string_buf_chk(varp, buf); |
323 | 5663 |
5664 return res != NULL ? res : (char_u *)""; | |
5665 } | |
5666 | |
5810 | 5667 /* |
5668 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE! | |
5669 */ | |
449 | 5670 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5671 tv_get_string_chk(typval_T *varp) |
323 | 5672 { |
5673 static char_u mybuf[NUMBUFLEN]; | |
5674 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5675 return tv_get_string_buf_chk(varp, mybuf); |
323 | 5676 } |
5677 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
5678 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5679 tv_get_string_buf_chk(typval_T *varp, char_u *buf) |
323 | 5680 { |
56 | 5681 switch (varp->v_type) |
5682 { | |
5683 case VAR_NUMBER: | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5684 vim_snprintf((char *)buf, NUMBUFLEN, "%lld", |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19201
diff
changeset
|
5685 (varnumber_T)varp->vval.v_number); |
56 | 5686 return buf; |
5687 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5688 case VAR_PARTIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5689 emsg(_("E729: using Funcref as a String")); |
56 | 5690 break; |
5691 case VAR_LIST: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5692 emsg(_("E730: using List as a String")); |
100 | 5693 break; |
5694 case VAR_DICT: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5695 emsg(_("E731: using Dictionary as a String")); |
56 | 5696 break; |
1624 | 5697 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5698 #ifdef FEAT_FLOAT |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5699 emsg(_(e_float_as_string)); |
1624 | 5700 break; |
5701 #endif | |
56 | 5702 case VAR_STRING: |
5703 if (varp->vval.v_string != NULL) | |
5704 return varp->vval.v_string; | |
323 | 5705 return (char_u *)""; |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5706 case VAR_BOOL: |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5707 case VAR_SPECIAL: |
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5708 STRCPY(buf, get_var_special_name(varp->vval.v_number)); |
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5709 return buf; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5710 case VAR_BLOB: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5711 emsg(_("E976: using Blob as a String")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5712 break; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5713 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5714 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5715 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5716 job_T *job = varp->vval.v_job; |
8424
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5717 char *status; |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5718 |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5719 if (job == NULL) |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5720 return (char_u *)"no process"; |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5721 status = job->jv_status == JOB_FAILED ? "fail" |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
5722 : job->jv_status >= JOB_ENDED ? "dead" |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5723 : "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5724 # ifdef UNIX |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5725 vim_snprintf((char *)buf, NUMBUFLEN, |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5726 "process %ld %s", (long)job->jv_pid, status); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15790
diff
changeset
|
5727 # elif defined(MSWIN) |
8001
e5dbeb923ce6
commit https://github.com/vim/vim/commit/4d8747cdfc13843a5680dc8340fbeb6d32e7b626
Christian Brabandt <cb@256bit.org>
parents:
7995
diff
changeset
|
5728 vim_snprintf((char *)buf, NUMBUFLEN, |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
5729 "process %ld %s", |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
5730 (long)job->jv_proc_info.dwProcessId, |
8001
e5dbeb923ce6
commit https://github.com/vim/vim/commit/4d8747cdfc13843a5680dc8340fbeb6d32e7b626
Christian Brabandt <cb@256bit.org>
parents:
7995
diff
changeset
|
5731 status); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5732 # else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5733 // fall-back |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5734 vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5735 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5736 return buf; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5737 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5738 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5739 break; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5740 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5741 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5742 { |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5743 channel_T *channel = varp->vval.v_channel; |
10235
ad6851687158
commit https://github.com/vim/vim/commit/0e77b7691ee7c477facb4c9d9162c8603ada2d84
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5744 char *status = channel_status(channel, -1); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5745 |
8070
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5746 if (channel == NULL) |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5747 vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status); |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5748 else |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5749 vim_snprintf((char *)buf, NUMBUFLEN, |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5750 "channel %d %s", channel->ch_id, status); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5751 return buf; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5752 } |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5753 #endif |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5754 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5755 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
|
5756 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
|
5757 case VAR_VOID: |
19085
fd1070ff696b
patch 8.2.0103: using null object with execute() has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19081
diff
changeset
|
5758 emsg(_(e_inval_string)); |
56 | 5759 break; |
5760 } | |
323 | 5761 return NULL; |
7 | 5762 } |
5763 | |
5764 /* | |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5765 * Turn a typeval into a string. Similar to tv_get_string_buf() but uses |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5766 * string() on Dict, List, etc. |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5767 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
5768 static char_u * |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5769 tv_stringify(typval_T *varp, char_u *buf) |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5770 { |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5771 if (varp->v_type == VAR_LIST |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5772 || varp->v_type == VAR_DICT |
19081
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
5773 || varp->v_type == VAR_BLOB |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5774 || varp->v_type == VAR_FUNC |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5775 || varp->v_type == VAR_PARTIAL |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5776 || varp->v_type == VAR_FLOAT) |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5777 { |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5778 typval_T tmp; |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5779 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5780 f_string(varp, &tmp); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5781 tv_get_string_buf(&tmp, buf); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5782 clear_tv(varp); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5783 *varp = tmp; |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5784 return tmp.vval.v_string; |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5785 } |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5786 return tv_get_string_buf(varp, buf); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5787 } |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5788 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5789 /* |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5790 * Return TRUE if typeval "tv" and its value are set to be locked (immutable). |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5791 * Also give an error message, using "name" or _("name") when use_gettext is |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5792 * TRUE. |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5793 */ |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5794 static int |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5795 tv_check_lock(typval_T *tv, char_u *name, int use_gettext) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5796 { |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5797 int lock = 0; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5798 |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5799 switch (tv->v_type) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5800 { |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5801 case VAR_BLOB: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5802 if (tv->vval.v_blob != NULL) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5803 lock = tv->vval.v_blob->bv_lock; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5804 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5805 case VAR_LIST: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5806 if (tv->vval.v_list != NULL) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5807 lock = tv->vval.v_list->lv_lock; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5808 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5809 case VAR_DICT: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5810 if (tv->vval.v_dict != NULL) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5811 lock = tv->vval.v_dict->dv_lock; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5812 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5813 default: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5814 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5815 } |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5816 return var_check_lock(tv->v_lock, name, use_gettext) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5817 || (lock != 0 && var_check_lock(lock, name, use_gettext)); |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5818 } |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5819 |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5820 /* |
137 | 5821 * Copy the values from typval_T "from" to typval_T "to". |
56 | 5822 * When needed allocates string or increases reference count. |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5823 * Does not make a copy of a list, blob or dict but copies the reference! |
1772 | 5824 * It is OK for "from" and "to" to point to the same item. This is used to |
5825 * make a copy later. | |
56 | 5826 */ |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2045
diff
changeset
|
5827 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5828 copy_tv(typval_T *from, typval_T *to) |
56 | 5829 { |
5830 to->v_type = from->v_type; | |
151 | 5831 to->v_lock = 0; |
56 | 5832 switch (from->v_type) |
5833 { | |
5834 case VAR_NUMBER: | |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19087
diff
changeset
|
5835 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
5836 case VAR_SPECIAL: |
56 | 5837 to->vval.v_number = from->vval.v_number; |
5838 break; | |
1624 | 5839 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5840 #ifdef FEAT_FLOAT |
1624 | 5841 to->vval.v_float = from->vval.v_float; |
5842 break; | |
5843 #endif | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5844 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5845 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5846 to->vval.v_job = from->vval.v_job; |
8174
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8170
diff
changeset
|
5847 if (to->vval.v_job != NULL) |
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8170
diff
changeset
|
5848 ++to->vval.v_job->jv_refcount; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5849 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5850 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5851 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5852 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5853 to->vval.v_channel = from->vval.v_channel; |
8070
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5854 if (to->vval.v_channel != NULL) |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5855 ++to->vval.v_channel->ch_refcount; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5856 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5857 #endif |
56 | 5858 case VAR_STRING: |
5859 case VAR_FUNC: | |
5860 if (from->vval.v_string == NULL) | |
5861 to->vval.v_string = NULL; | |
5862 else | |
117 | 5863 { |
56 | 5864 to->vval.v_string = vim_strsave(from->vval.v_string); |
117 | 5865 if (from->v_type == VAR_FUNC) |
5866 func_ref(to->vval.v_string); | |
5867 } | |
56 | 5868 break; |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5869 case VAR_PARTIAL: |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5870 if (from->vval.v_partial == NULL) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5871 to->vval.v_partial = NULL; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5872 else |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5873 { |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5874 to->vval.v_partial = from->vval.v_partial; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5875 ++to->vval.v_partial->pt_refcount; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5876 } |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5877 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5878 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5879 if (from->vval.v_blob == NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5880 to->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5881 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5882 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5883 to->vval.v_blob = from->vval.v_blob; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5884 ++to->vval.v_blob->bv_refcount; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5885 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5886 break; |
56 | 5887 case VAR_LIST: |
5888 if (from->vval.v_list == NULL) | |
5889 to->vval.v_list = NULL; | |
5890 else | |
5891 { | |
5892 to->vval.v_list = from->vval.v_list; | |
5893 ++to->vval.v_list->lv_refcount; | |
5894 } | |
5895 break; | |
100 | 5896 case VAR_DICT: |
5897 if (from->vval.v_dict == NULL) | |
5898 to->vval.v_dict = NULL; | |
5899 else | |
5900 { | |
5901 to->vval.v_dict = from->vval.v_dict; | |
5902 ++to->vval.v_dict->dv_refcount; | |
5903 } | |
5904 break; | |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5905 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
|
5906 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
|
5907 case VAR_VOID: |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
5908 internal_error_no_abort("copy_tv(UNKNOWN)"); |
56 | 5909 break; |
5910 } | |
7 | 5911 } |
5912 | |
5913 /* | |
104 | 5914 * Make a copy of an item. |
5915 * Lists and Dictionaries are also copied. A deep copy if "deep" is set. | |
165 | 5916 * For deepcopy() "copyID" is zero for a full copy or the ID for when a |
5917 * reference to an already copied list/dict can be used. | |
5918 * Returns FAIL or OK. | |
5919 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
5920 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5921 item_copy( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5922 typval_T *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5923 typval_T *to, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5924 int deep, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5925 int copyID) |
104 | 5926 { |
5927 static int recurse = 0; | |
165 | 5928 int ret = OK; |
104 | 5929 |
137 | 5930 if (recurse >= DICT_MAXNEST) |
104 | 5931 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5932 emsg(_("E698: variable nested too deep for making a copy")); |
165 | 5933 return FAIL; |
104 | 5934 } |
5935 ++recurse; | |
5936 | |
5937 switch (from->v_type) | |
5938 { | |
5939 case VAR_NUMBER: | |
1624 | 5940 case VAR_FLOAT: |
104 | 5941 case VAR_STRING: |
5942 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5943 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
|
5944 case VAR_BOOL: |
7862
d4fec9208e7e
commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5945 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5946 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5947 case VAR_CHANNEL: |
104 | 5948 copy_tv(from, to); |
5949 break; | |
5950 case VAR_LIST: | |
5951 to->v_type = VAR_LIST; | |
151 | 5952 to->v_lock = 0; |
165 | 5953 if (from->vval.v_list == NULL) |
5954 to->vval.v_list = NULL; | |
5955 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID) | |
5956 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5957 // use the copy made earlier |
165 | 5958 to->vval.v_list = from->vval.v_list->lv_copylist; |
5959 ++to->vval.v_list->lv_refcount; | |
5960 } | |
5961 else | |
5962 to->vval.v_list = list_copy(from->vval.v_list, deep, copyID); | |
5963 if (to->vval.v_list == NULL) | |
5964 ret = FAIL; | |
104 | 5965 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
|
5966 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
|
5967 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
|
5968 break; |
104 | 5969 case VAR_DICT: |
5970 to->v_type = VAR_DICT; | |
151 | 5971 to->v_lock = 0; |
165 | 5972 if (from->vval.v_dict == NULL) |
5973 to->vval.v_dict = NULL; | |
5974 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID) | |
5975 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5976 // use the copy made earlier |
165 | 5977 to->vval.v_dict = from->vval.v_dict->dv_copydict; |
5978 ++to->vval.v_dict->dv_refcount; | |
5979 } | |
5980 else | |
5981 to->vval.v_dict = dict_copy(from->vval.v_dict, deep, copyID); | |
5982 if (to->vval.v_dict == NULL) | |
5983 ret = FAIL; | |
104 | 5984 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5985 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
|
5986 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
|
5987 case VAR_VOID: |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
5988 internal_error_no_abort("item_copy(UNKNOWN)"); |
165 | 5989 ret = FAIL; |
104 | 5990 } |
5991 --recurse; | |
165 | 5992 return ret; |
104 | 5993 } |
5994 | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5995 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5996 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
|
5997 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
5998 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
|
5999 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
|
6000 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
|
6001 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6002 if (*atstart) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6003 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6004 *atstart = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6005 // 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
|
6006 // 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
|
6007 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
|
6008 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6009 // 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
|
6010 // 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
|
6011 // 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
|
6012 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
|
6013 msg_start(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6014 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6015 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6016 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
|
6017 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
|
6018 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6019 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
|
6020 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
|
6021 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6022 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
|
6023 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6024 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
|
6025 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6026 // 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
|
6027 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
|
6028 *needclr = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6029 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6030 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
|
6031 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6032 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6033 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6034 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
|
6035 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6036 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
|
6037 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6038 (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
|
6039 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
|
6040 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6041 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6042 (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
|
6043 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6044 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6045 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
|
6046 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6047 |
104 | 6048 /* |
7 | 6049 * ":echo expr1 ..." print each argument separated with a space, add a |
6050 * newline at the end. | |
6051 * ":echon expr1 ..." print each argument plain. | |
6052 */ | |
6053 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6054 ex_echo(exarg_T *eap) |
7 | 6055 { |
6056 char_u *arg = eap->arg; | |
137 | 6057 typval_T rettv; |
7 | 6058 char_u *p; |
6059 int needclr = TRUE; | |
6060 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
|
6061 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
|
6062 int called_emsg_before = called_emsg; |
7 | 6063 |
6064 if (eap->skip) | |
6065 ++emsg_skip; | |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
6066 while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int) |
7 | 6067 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6068 // 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
|
6069 // still need to be cleared. E.g., "echo 22,44". |
1624 | 6070 need_clr_eos = needclr; |
6071 | |
7 | 6072 p = arg; |
71 | 6073 if (eval1(&arg, &rettv, !eap->skip) == FAIL) |
7 | 6074 { |
6075 /* | |
6076 * Report the invalid expression unless the expression evaluation | |
6077 * has been cancelled due to an aborting error, an interrupt, or an | |
6078 * exception. | |
6079 */ | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
6080 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
|
6081 && 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
|
6082 semsg(_(e_invexpr2), p); |
1624 | 6083 need_clr_eos = FALSE; |
6084 break; | |
6085 } | |
6086 need_clr_eos = FALSE; | |
6087 | |
7 | 6088 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
|
6089 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
|
6090 |
71 | 6091 clear_tv(&rettv); |
7 | 6092 arg = skipwhite(arg); |
6093 } | |
6094 eap->nextcmd = check_nextcmd(arg); | |
6095 | |
6096 if (eap->skip) | |
6097 --emsg_skip; | |
6098 else | |
6099 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6100 // remove text that may still be there from the command |
7 | 6101 if (needclr) |
6102 msg_clr_eos(); | |
6103 if (eap->cmdidx == CMD_echo) | |
6104 msg_end(); | |
6105 } | |
6106 } | |
6107 | |
6108 /* | |
6109 * ":echohl {name}". | |
6110 */ | |
6111 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6112 ex_echohl(exarg_T *eap) |
7 | 6113 { |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
6114 echo_attr = syn_name2attr(eap->arg); |
7 | 6115 } |
6116 | |
6117 /* | |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6118 * 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
|
6119 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6120 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6121 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
|
6122 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6123 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
|
6124 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6125 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6126 /* |
7 | 6127 * ":execute expr1 ..." execute the result of an expression. |
6128 * ":echomsg expr1 ..." Print a message | |
6129 * ":echoerr expr1 ..." Print an error | |
6130 * Each gets spaces around each argument and a newline at the end for | |
6131 * echo commands | |
6132 */ | |
6133 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6134 ex_execute(exarg_T *eap) |
7 | 6135 { |
6136 char_u *arg = eap->arg; | |
137 | 6137 typval_T rettv; |
7 | 6138 int ret = OK; |
6139 char_u *p; | |
6140 garray_T ga; | |
6141 int len; | |
16054
78faa25f9698
patch 8.1.1032: warnings from clang static analyzer
Bram Moolenaar <Bram@vim.org>
parents:
16036
diff
changeset
|
6142 int save_did_emsg; |
7 | 6143 |
6144 ga_init2(&ga, 1, 80); | |
6145 | |
6146 if (eap->skip) | |
6147 ++emsg_skip; | |
20061
6e6a75800884
patch 8.2.0586: Vim9: # comment not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20059
diff
changeset
|
6148 while (!ends_excmd2(eap->cmd, arg) || *arg == '"') |
7 | 6149 { |
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
|
6150 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
|
6151 if (ret == FAIL) |
7 | 6152 break; |
6153 | |
6154 if (!eap->skip) | |
6155 { | |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6156 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
|
6157 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6158 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
|
6159 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
6160 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
|
6161 { |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
6162 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
|
6163 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
|
6164 } |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
6165 else |
e3848b251a01
patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents:
19085
diff
changeset
|
6166 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
|
6167 } |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6168 else |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6169 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
|
6170 if (p == NULL) |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
6171 { |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
6172 clear_tv(&rettv); |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
6173 ret = FAIL; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
6174 break; |
3b1f83fdaabc
patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
6175 } |
7 | 6176 len = (int)STRLEN(p); |
6177 if (ga_grow(&ga, len + 2) == FAIL) | |
6178 { | |
71 | 6179 clear_tv(&rettv); |
7 | 6180 ret = FAIL; |
6181 break; | |
6182 } | |
6183 if (ga.ga_len) | |
6184 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' '; | |
6185 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p); | |
6186 ga.ga_len += len; | |
6187 } | |
6188 | |
71 | 6189 clear_tv(&rettv); |
7 | 6190 arg = skipwhite(arg); |
6191 } | |
6192 | |
6193 if (ret != FAIL && ga.ga_data != NULL) | |
6194 { | |
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
|
6195 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
|
6196 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6197 // 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
|
6198 // 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
|
6199 // 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
|
6200 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
|
6201 } |
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6202 |
7 | 6203 if (eap->cmdidx == CMD_echomsg) |
625 | 6204 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
6205 msg_attr(ga.ga_data, echo_attr); |
625 | 6206 out_flush(); |
6207 } | |
7 | 6208 else if (eap->cmdidx == CMD_echoerr) |
6209 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6210 // We don't want to abort following commands, restore did_emsg. |
7 | 6211 save_did_emsg = did_emsg; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6212 emsg(ga.ga_data); |
7 | 6213 if (!force_abort) |
6214 did_emsg = save_did_emsg; | |
6215 } | |
6216 else if (eap->cmdidx == CMD_execute) | |
6217 do_cmdline((char_u *)ga.ga_data, | |
6218 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); | |
6219 } | |
6220 | |
6221 ga_clear(&ga); | |
6222 | |
6223 if (eap->skip) | |
6224 --emsg_skip; | |
6225 | |
6226 eap->nextcmd = check_nextcmd(arg); | |
6227 } | |
6228 | |
6229 /* | |
6230 * Skip over the name of an option: "&option", "&g:option" or "&l:option". | |
6231 * "arg" points to the "&" or '+' when called, to "option" when returning. | |
6232 * Returns NULL when no option name found. Otherwise pointer to the char | |
6233 * after the option name. | |
6234 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
6235 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6236 find_option_end(char_u **arg, int *opt_flags) |
7 | 6237 { |
6238 char_u *p = *arg; | |
6239 | |
6240 ++p; | |
6241 if (*p == 'g' && p[1] == ':') | |
6242 { | |
6243 *opt_flags = OPT_GLOBAL; | |
6244 p += 2; | |
6245 } | |
6246 else if (*p == 'l' && p[1] == ':') | |
6247 { | |
6248 *opt_flags = OPT_LOCAL; | |
6249 p += 2; | |
6250 } | |
6251 else | |
6252 *opt_flags = 0; | |
6253 | |
6254 if (!ASCII_ISALPHA(*p)) | |
6255 return NULL; | |
6256 *arg = p; | |
6257 | |
6258 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
|
6259 p += 4; // termcap option |
7 | 6260 else |
6261 while (ASCII_ISALPHA(*p)) | |
6262 ++p; | |
6263 return p; | |
6264 } | |
6265 | |
6266 /* | |
448 | 6267 * Display script name where an item was last set. |
6268 * Should only be invoked when 'verbose' is non-zero. | |
6269 */ | |
6270 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
|
6271 last_set_msg(sctx_T script_ctx) |
448 | 6272 { |
507 | 6273 char_u *p; |
6274 | |
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
|
6275 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
|
6276 { |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6277 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); |
507 | 6278 if (p != NULL) |
6279 { | |
6280 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
6281 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
|
6282 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
|
6283 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
|
6284 { |
18939
25ebc35e104f
patch 8.2.0030: "gF" does not work on output of "verbose command"
Bram Moolenaar <Bram@vim.org>
parents:
18851
diff
changeset
|
6285 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
|
6286 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
|
6287 } |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6288 verbose_leave(); |
507 | 6289 vim_free(p); |
6290 } | |
448 | 6291 } |
6292 } | |
6293 | |
16036
89fb86821b4a
patch 8.1.1023: may use NULL pointer when indexing a blob
Bram Moolenaar <Bram@vim.org>
parents:
16013
diff
changeset
|
6294 /* |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6295 * Compare "typ1" and "typ2". Put the result in "typ1". |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6296 */ |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6297 int |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6298 typval_compare( |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6299 typval_T *typ1, // first operand |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6300 typval_T *typ2, // second operand |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6301 exptype_T type, // operator |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6302 int ic) // ignore case |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6303 { |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6304 int i; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6305 varnumber_T n1, n2; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6306 char_u *s1, *s2; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6307 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6308 int type_is = type == EXPR_IS || type == EXPR_ISNOT; |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6309 |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6310 if (type_is && typ1->v_type != typ2->v_type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6311 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6312 // For "is" a different type always means FALSE, for "notis" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6313 // it means TRUE. |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6314 n1 = (type == EXPR_ISNOT); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6315 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6316 else if (typ1->v_type == VAR_BLOB || typ2->v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6317 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6318 if (type_is) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6319 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6320 n1 = (typ1->v_type == typ2->v_type |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6321 && typ1->vval.v_blob == typ2->vval.v_blob); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6322 if (type == EXPR_ISNOT) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6323 n1 = !n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6324 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6325 else if (typ1->v_type != typ2->v_type |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6326 || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6327 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6328 if (typ1->v_type != typ2->v_type) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6329 emsg(_("E977: Can only compare Blob with Blob")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6330 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6331 emsg(_(e_invalblob)); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6332 clear_tv(typ1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6333 return FAIL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6334 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6335 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6336 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6337 // Compare two Blobs for being equal or unequal. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6338 n1 = blob_equal(typ1->vval.v_blob, typ2->vval.v_blob); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6339 if (type == EXPR_NEQUAL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6340 n1 = !n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6341 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6342 } |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6343 else if (typ1->v_type == VAR_LIST || typ2->v_type == VAR_LIST) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6344 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6345 if (type_is) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6346 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6347 n1 = (typ1->v_type == typ2->v_type |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6348 && typ1->vval.v_list == typ2->vval.v_list); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6349 if (type == EXPR_ISNOT) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6350 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6351 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6352 else if (typ1->v_type != typ2->v_type |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6353 || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6354 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6355 if (typ1->v_type != typ2->v_type) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6356 emsg(_("E691: Can only compare List with List")); |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6357 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6358 emsg(_("E692: Invalid operation for List")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6359 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6360 return FAIL; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6361 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6362 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6363 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6364 // Compare two Lists for being equal or unequal. |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6365 n1 = list_equal(typ1->vval.v_list, typ2->vval.v_list, |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6366 ic, FALSE); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6367 if (type == EXPR_NEQUAL) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6368 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6369 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6370 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6371 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6372 else if (typ1->v_type == VAR_DICT || typ2->v_type == VAR_DICT) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6373 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6374 if (type_is) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6375 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6376 n1 = (typ1->v_type == typ2->v_type |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6377 && typ1->vval.v_dict == typ2->vval.v_dict); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6378 if (type == EXPR_ISNOT) |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6379 n1 = !n1; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6380 } |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6381 else if (typ1->v_type != typ2->v_type |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6382 || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6383 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6384 if (typ1->v_type != typ2->v_type) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6385 emsg(_("E735: Can only compare Dictionary with Dictionary")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6386 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6387 emsg(_("E736: Invalid operation for Dictionary")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6388 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6389 return FAIL; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6390 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6391 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6392 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6393 // Compare two Dictionaries for being equal or unequal. |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6394 n1 = dict_equal(typ1->vval.v_dict, typ2->vval.v_dict, |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6395 ic, FALSE); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6396 if (type == EXPR_NEQUAL) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6397 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6398 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6399 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6400 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6401 else if (typ1->v_type == VAR_FUNC || typ2->v_type == VAR_FUNC |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6402 || typ1->v_type == VAR_PARTIAL || typ2->v_type == VAR_PARTIAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6403 { |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6404 if (type != EXPR_EQUAL && type != EXPR_NEQUAL |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6405 && type != EXPR_IS && type != EXPR_ISNOT) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6406 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6407 emsg(_("E694: Invalid operation for Funcrefs")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6408 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6409 return FAIL; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6410 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6411 if ((typ1->v_type == VAR_PARTIAL |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6412 && typ1->vval.v_partial == NULL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6413 || (typ2->v_type == VAR_PARTIAL |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6414 && typ2->vval.v_partial == NULL)) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6415 // when a partial is NULL assume not equal |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6416 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6417 else if (type_is) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6418 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6419 if (typ1->v_type == VAR_FUNC && typ2->v_type == VAR_FUNC) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6420 // strings are considered the same if their value is |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6421 // the same |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6422 n1 = tv_equal(typ1, typ2, ic, FALSE); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6423 else if (typ1->v_type == VAR_PARTIAL |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6424 && typ2->v_type == VAR_PARTIAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6425 n1 = (typ1->vval.v_partial == typ2->vval.v_partial); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6426 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6427 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6428 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6429 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6430 n1 = tv_equal(typ1, typ2, ic, FALSE); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6431 if (type == EXPR_NEQUAL || type == EXPR_ISNOT) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6432 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6433 } |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6434 |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6435 #ifdef FEAT_FLOAT |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6436 /* |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6437 * If one of the two variables is a float, compare as a float. |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6438 * When using "=~" or "!~", always compare as string. |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6439 */ |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6440 else if ((typ1->v_type == VAR_FLOAT || typ2->v_type == VAR_FLOAT) |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6441 && type != EXPR_MATCH && type != EXPR_NOMATCH) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6442 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6443 float_T f1, f2; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6444 |
15904
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
6445 f1 = tv_get_float(typ1); |
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
6446 f2 = tv_get_float(typ2); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6447 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6448 switch (type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6449 { |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6450 case EXPR_IS: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6451 case EXPR_EQUAL: n1 = (f1 == f2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6452 case EXPR_ISNOT: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6453 case EXPR_NEQUAL: n1 = (f1 != f2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6454 case EXPR_GREATER: n1 = (f1 > f2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6455 case EXPR_GEQUAL: n1 = (f1 >= f2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6456 case EXPR_SMALLER: n1 = (f1 < f2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6457 case EXPR_SEQUAL: n1 = (f1 <= f2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6458 case EXPR_UNKNOWN: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6459 case EXPR_MATCH: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6460 default: break; // avoid gcc warning |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6461 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6462 } |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6463 #endif |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6464 |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6465 /* |
18968
24941a950cc7
patch 8.2.0045: script test fails
Bram Moolenaar <Bram@vim.org>
parents:
18966
diff
changeset
|
6466 * If one of the two variables is a number, compare as a number. |
24941a950cc7
patch 8.2.0045: script test fails
Bram Moolenaar <Bram@vim.org>
parents:
18966
diff
changeset
|
6467 * When using "=~" or "!~", always compare as string. |
24941a950cc7
patch 8.2.0045: script test fails
Bram Moolenaar <Bram@vim.org>
parents:
18966
diff
changeset
|
6468 */ |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6469 else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER) |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6470 && type != EXPR_MATCH && type != EXPR_NOMATCH) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6471 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6472 n1 = tv_get_number(typ1); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6473 n2 = tv_get_number(typ2); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6474 switch (type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6475 { |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6476 case EXPR_IS: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6477 case EXPR_EQUAL: n1 = (n1 == n2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6478 case EXPR_ISNOT: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6479 case EXPR_NEQUAL: n1 = (n1 != n2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6480 case EXPR_GREATER: n1 = (n1 > n2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6481 case EXPR_GEQUAL: n1 = (n1 >= n2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6482 case EXPR_SMALLER: n1 = (n1 < n2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6483 case EXPR_SEQUAL: n1 = (n1 <= n2); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6484 case EXPR_UNKNOWN: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6485 case EXPR_MATCH: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6486 default: break; // avoid gcc warning |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6487 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6488 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6489 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6490 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6491 s1 = tv_get_string_buf(typ1, buf1); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6492 s2 = tv_get_string_buf(typ2, buf2); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6493 if (type != EXPR_MATCH && type != EXPR_NOMATCH) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6494 i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2); |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6495 else |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6496 i = 0; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6497 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6498 switch (type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6499 { |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6500 case EXPR_IS: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6501 case EXPR_EQUAL: n1 = (i == 0); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6502 case EXPR_ISNOT: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6503 case EXPR_NEQUAL: n1 = (i != 0); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6504 case EXPR_GREATER: n1 = (i > 0); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6505 case EXPR_GEQUAL: n1 = (i >= 0); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6506 case EXPR_SMALLER: n1 = (i < 0); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6507 case EXPR_SEQUAL: n1 = (i <= 0); break; |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6508 |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6509 case EXPR_MATCH: |
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6510 case EXPR_NOMATCH: |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6511 n1 = pattern_match(s2, s1, ic); |
19017
d9ea4f0bfd34
patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents:
19001
diff
changeset
|
6512 if (type == EXPR_NOMATCH) |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6513 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6514 break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6515 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
6516 default: break; // avoid gcc warning |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6517 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6518 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6519 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6520 typ1->v_type = VAR_NUMBER; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6521 typ1->vval.v_number = n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6522 |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6523 return OK; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6524 } |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6525 |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6526 char_u * |
14391
46f14852a919
patch 8.1.0210: still a few K&R function declarations
Christian Brabandt <cb@256bit.org>
parents:
14331
diff
changeset
|
6527 typval_tostring(typval_T *arg) |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6528 { |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6529 char_u *tofree; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6530 char_u numbuf[NUMBUFLEN]; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6531 char_u *ret = NULL; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6532 |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6533 if (arg == NULL) |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6534 return vim_strsave((char_u *)"(does not exist)"); |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6535 ret = tv2string(arg, &tofree, numbuf, 0); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6536 // Make a copy if we have a value but it's not in allocated memory. |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6537 if (ret != NULL && tofree == NULL) |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6538 ret = vim_strsave(ret); |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6539 return ret; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6540 } |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6541 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
6542 #endif // FEAT_EVAL |
7 | 6543 |
6544 /* | |
6545 * 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
|
6546 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL. |
7 | 6547 * "flags" can be "g" to do a global substitute. |
6548 * Returns an allocated string, NULL for error. | |
6549 */ | |
6550 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6551 do_string_sub( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6552 char_u *str, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6553 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6554 char_u *sub, |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
6555 typval_T *expr, |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6556 char_u *flags) |
7 | 6557 { |
6558 int sublen; | |
6559 regmatch_T regmatch; | |
6560 int i; | |
6561 int do_all; | |
6562 char_u *tail; | |
6332 | 6563 char_u *end; |
7 | 6564 garray_T ga; |
6565 char_u *ret; | |
6566 char_u *save_cpo; | |
5623 | 6567 char_u *zero_width = NULL; |
7 | 6568 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6569 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here |
7 | 6570 save_cpo = p_cpo; |
1672 | 6571 p_cpo = empty_option; |
7 | 6572 |
6573 ga_init2(&ga, 1, 200); | |
6574 | |
6575 do_all = (flags[0] == 'g'); | |
6576 | |
6577 regmatch.rm_ic = p_ic; | |
6578 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | |
6579 if (regmatch.regprog != NULL) | |
6580 { | |
6581 tail = str; | |
6332 | 6582 end = str + STRLEN(str); |
7 | 6583 while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) |
6584 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6585 // Skip empty match except for first match. |
5623 | 6586 if (regmatch.startp[0] == regmatch.endp[0]) |
6587 { | |
6588 if (zero_width == regmatch.startp[0]) | |
6589 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6590 // 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
|
6591 i = mb_ptr2len(tail); |
5964 | 6592 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, |
6593 (size_t)i); | |
6594 ga.ga_len += i; | |
6595 tail += i; | |
5623 | 6596 continue; |
6597 } | |
6598 zero_width = regmatch.startp[0]; | |
6599 } | |
6600 | |
7 | 6601 /* |
6602 * Get some space for a temporary buffer to do the substitution | |
6603 * into. It will contain: | |
6604 * - The text up to where the match is. | |
6605 * - The substituted text. | |
6606 * - The text after the match. | |
6607 */ | |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
6608 sublen = vim_regsub(®match, sub, expr, tail, FALSE, TRUE, FALSE); |
6332 | 6609 if (ga_grow(&ga, (int)((end - tail) + sublen - |
7 | 6610 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL) |
6611 { | |
6612 ga_clear(&ga); | |
6613 break; | |
6614 } | |
6615 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6616 // copy the text up to where the match is |
7 | 6617 i = (int)(regmatch.startp[0] - tail); |
6618 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
|
6619 // add the substituted text |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
6620 (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data |
7 | 6621 + ga.ga_len + i, TRUE, TRUE, FALSE); |
6622 ga.ga_len += i + sublen - 1; | |
5388 | 6623 tail = regmatch.endp[0]; |
6624 if (*tail == NUL) | |
6625 break; | |
7 | 6626 if (!do_all) |
6627 break; | |
6628 } | |
6629 | |
6630 if (ga.ga_data != NULL) | |
6631 STRCPY((char *)ga.ga_data + ga.ga_len, tail); | |
6632 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4778
diff
changeset
|
6633 vim_regfree(regmatch.regprog); |
7 | 6634 } |
6635 | |
6636 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data); | |
6637 ga_clear(&ga); | |
1672 | 6638 if (p_cpo == empty_option) |
6639 p_cpo = save_cpo; | |
6640 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6641 // Darn, evaluating {sub} expression or {expr} changed the value. |
1672 | 6642 free_string_option(save_cpo); |
7 | 6643 |
6644 return ret; | |
6645 } |