annotate src/eval.c @ 21044:dc2ca403a217 v8.2.1073

patch 8.2.1073: Vim9: no line break allowed in () expression Commit: https://github.com/vim/vim/commit/7a4981b93642b5b62018cd8150b3fb0dfa2417d4 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 27 20:46:29 2020 +0200 patch 8.2.1073: Vim9: no line break allowed in () expression Problem: Vim9: no line break allowed in () expression. Solution: Skip a line break.
author Bram Moolenaar <Bram@vim.org>
date Sat, 27 Jun 2020 21:00:03 +0200
parents d9e0db9b2b99
children 0ca7e04d39e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 10000
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * eval.c: Expression evaluation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
8295
18fd94bd4eb8 commit https://github.com/vim/vim/commit/fefecb0fbe14c44d46f91036d76bbb6c28162da8
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
13 #define USING_FLOAT_STUFF
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
18
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
19 #ifdef VMS
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
20 # include <float.h>
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
21 #endif
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
22
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
23 static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary");
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
24
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
25 #define NAMESPACE_CHAR (char_u *)"abglstvw"
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
26
142
0ef5b70c3eaf updated for version 7.0045
vimboss
parents: 137
diff changeset
27 /*
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
28 * When recursively copying lists and dicts we need to remember which ones we
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
29 * have done to avoid endless recursiveness. This unique ID is used for that.
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
30 * The last bit is used for previous_funccal, ignored when comparing.
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
31 */
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
32 static int current_copyID = 0;
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
33
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 /*
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
35 * Info used by a ":for" loop.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
36 */
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
37 typedef struct
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
38 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
39 int fi_semicolon; // TRUE if ending in '; var]'
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
40 int fi_varcount; // nr of variables in the list
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
41 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
42 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
43 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
44 blob_T *fi_blob; // blob being used
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
45 } forinfo_T;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
46
7720
7c52f11e6df3 commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
47 static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
48 static int eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
49 static int eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
50 static int eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
51 static int eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
52 static int eval6(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int want_string);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
53 static int eval7(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int want_string);
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
54 static int eval7_leader(typval_T *rettv, int numeric_only, char_u *start_leader, char_u **end_leaderp);
7720
7c52f11e6df3 commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
55
7c52f11e6df3 commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
56 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
57 static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end);
2247
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
58
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
59 /*
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
60 * 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
61 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
62 varnumber_T
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
63 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
64 {
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
65 varnumber_T result;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
66
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
67 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
68 {
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
69 if (n1 == 0)
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
70 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
71 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
72 result = -VARNUM_MAX;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
73 else
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
74 result = VARNUM_MAX;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
75 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
76 else
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
77 result = n1 / n2;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
78
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
79 return result;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
80 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
81
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
82 /*
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
83 * 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
84 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
85 varnumber_T
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
86 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
87 {
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
88 // 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
89 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
90 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
91
10567
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
92 #if defined(EBCDIC) || defined(PROTO)
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
93 /*
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
94 * 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
95 */
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
96 static int
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
97 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
98 {
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
99 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
100 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
101
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
102 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
103 }
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
104
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
105 /*
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
106 * 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
107 * 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
108 * 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
109 */
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
110 static void
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
111 sortFunctions(void)
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
112 {
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
113 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
114
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
115 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
116 }
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
117 #endif
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
118
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
119 /*
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
120 * Initialize the global and v: variables.
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
121 */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
122 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
123 eval_init(void)
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
124 {
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
125 evalvars_init();
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
126 func_init();
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
127
2247
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
128 #ifdef EBCDIC
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
129 /*
3178
b7f0f23bf906 updated for version 7.3.359
Bram Moolenaar <bram@vim.org>
parents: 3160
diff changeset
130 * 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
131 */
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
132 sortFunctions();
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
133 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
134 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
135
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
136 #if defined(EXITFREE) || defined(PROTO)
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
137 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
138 eval_clear(void)
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
139 {
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
140 evalvars_clear();
19108
44c6498535c9 patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents: 19102
diff changeset
141 free_scriptnames(); // must come after evalvars_clear().
2849
b0190e93e601 updated for version 7.3.198
Bram Moolenaar <bram@vim.org>
parents: 2845
diff changeset
142 free_locales();
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
143
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
144 // 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
145 free_autoload_scriptnames();
855
d2a4f08396fe updated for version 7.0f05
vimboss
parents: 846
diff changeset
146
16967
586d625e21b4 patch 8.1.1484: some tests are slow
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
147 // unreferenced lists and dicts
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
148 (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
149
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16967
diff changeset
150 // 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
151 free_all_functions();
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
152 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
153 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
154
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 * Top level evaluation function, returning a boolean.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 * Sets "error" to TRUE if there was an error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 * Return TRUE or FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
161 eval_to_bool(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
162 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
163 int *error,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
164 exarg_T *eap,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
165 int skip) // only parse, don't execute
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
167 typval_T tv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
168 varnumber_T retval = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 ++emsg_skip;
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
172 if (eval0(arg, &tv, eap, skip ? NULL : &EVALARG_EVALUATE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 *error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 *error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 if (!skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
179 retval = (tv_get_number_chk(&tv, error) != 0);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
180 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
186 return (int)retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188
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
189 /*
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
190 * 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
191 */
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
192 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
193 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
194 {
15482
18dd04f7c4a1 patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents: 15478
diff changeset
195 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
196 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
197 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
198 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
199
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
200 ret = eval1(arg, rettv, evaluate ? &EVALARG_EVALUATE : NULL);
15478
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
201 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
202 {
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
203 // 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
204 // 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
205 // 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
206 // 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
207 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
208 && called_emsg == called_emsg_before)
15482
18dd04f7c4a1 patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents: 15478
diff changeset
209 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
210 }
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 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
212 }
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
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
214 /*
20731
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
215 * Return whether a typval is a valid expression to pass to eval_expr_typval()
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
216 * or eval_expr_to_bool(). An empty string returns FALSE;
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
217 */
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
218 int
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
219 eval_expr_valid_arg(typval_T *tv)
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
220 {
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
221 return tv->v_type != VAR_UNKNOWN
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
222 && (tv->v_type != VAR_STRING
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
223 || (tv->vval.v_string != NULL && *tv->vval.v_string != NUL));
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
224 }
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
225
ab27db64f1fb patch 8.2.0918: duplicate code for evaluating expression argument
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
226 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
227 * 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
228 * 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
229 * 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
230 */
16231
0761a4c111a7 patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents: 16223
diff changeset
231 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
232 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
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 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
235 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
236 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
237
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
238 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
239 {
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 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
241 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
242 return FAIL;
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
243 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
244 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
245 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
246 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
247 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
248 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
249 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
250 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
251
20156
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
252 if (partial == NULL)
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
253 return FAIL;
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
254
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20526
diff changeset
255 if (partial->pt_func != NULL
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
256 && partial->pt_func->uf_def_status != UF_NOT_COMPILED)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
257 {
20433
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20401
diff changeset
258 if (call_def_function(partial->pt_func, argc, argv,
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20401
diff changeset
259 partial, rettv) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
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 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
262 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
263 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
264 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
265 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
266 return FAIL;
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
267 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
268 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
269 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
270 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
271 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
272 }
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
273 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
274 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
275 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
276 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
277 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
278 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
279 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
280 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
281 return FAIL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
282 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
283 {
14331
f8280e1bfc84 patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents: 14071
diff changeset
284 clear_tv(rettv);
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
285 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
286 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
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 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
289 return 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
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
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 * 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
294 * 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
295 */
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
296 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
297 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
298 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
299 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
300 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
301
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
302 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
303 {
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
304 *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
305 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
306 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
307 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
308 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
309 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
310 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
311
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 * Top level evaluation function, returning a string. If "skip" is TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 * only parsing to "nextcmd" is done, without reporting errors. Return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
318 eval_to_string_skip(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
319 char_u *arg,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
320 exarg_T *eap,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
321 int skip) // only parse, don't execute
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
323 typval_T tv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 ++emsg_skip;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
328 if (eval0(arg, &tv, eap, skip ? NULL : &EVALARG_EVALUATE) == FAIL || skip)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
332 retval = vim_strsave(tv_get_string(&tv));
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
333 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 /*
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
342 * Skip over an expression at "*pp".
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
343 * Return FAIL for an error, OK otherwise.
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
344 */
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
345 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
346 skip_expr(char_u **pp)
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
347 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
348 typval_T rettv;
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
349
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
350 *pp = skipwhite(*pp);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
351 return eval1(pp, &rettv, NULL);
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
352 }
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
353
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
354 /*
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
355 * Skip over an expression at "*pp".
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
356 * If in Vim9 script and line breaks are encountered, the lines are
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
357 * concatenated. "evalarg->eval_tofree" will be set accordingly.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
358 * Return FAIL for an error, OK otherwise.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
359 */
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
360 int
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
361 skip_expr_concatenate(char_u **start, char_u **end, evalarg_T *evalarg)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
362 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
363 typval_T rettv;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
364 int res;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
365 int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
366 garray_T *gap = &evalarg->eval_ga;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
367 int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
368
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
369 if (vim9script && evalarg->eval_cookie != NULL)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
370 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
371 ga_init2(gap, sizeof(char_u *), 10);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
372 if (ga_grow(gap, 1) == OK)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
373 // leave room for "start"
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
374 ++gap->ga_len;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
375 }
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
376
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
377 // Don't evaluate the expression.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
378 if (evalarg != NULL)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
379 evalarg->eval_flags &= ~EVAL_EVALUATE;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
380 *end = skipwhite(*end);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
381 res = eval1(end, &rettv, evalarg);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
382 if (evalarg != NULL)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
383 evalarg->eval_flags = save_flags;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
384
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
385 if (vim9script && evalarg->eval_cookie != NULL
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
386 && evalarg->eval_ga.ga_len > 1)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
387 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
388 char_u *p;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
389 size_t endoff = STRLEN(*end);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
390
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
391 // Line breaks encountered, concatenate all the lines.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
392 *((char_u **)gap->ga_data) = *start;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
393 p = ga_concat_strings(gap, "");
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
394 *((char_u **)gap->ga_data) = NULL;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
395 ga_clear_strings(gap);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
396 gap->ga_itemsize = 0;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
397 if (p == NULL)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
398 return FAIL;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
399 *start = p;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
400 vim_free(evalarg->eval_tofree);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
401 evalarg->eval_tofree = p;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
402 // Compute "end" relative to the end.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
403 *end = *start + STRLEN(*start) - endoff;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
404 }
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
405
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
406 return res;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
407 }
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
408
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
409 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 * Top level evaluation function, returning a string.
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
411 * When "convert" is TRUE convert a List into a sequence of lines and convert
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
412 * a Float to a String.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 * Return pointer to allocated memory, or NULL for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
416 eval_to_string(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
417 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
418 int convert)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
420 typval_T tv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 char_u *retval;
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
422 garray_T ga;
1851
e7f6ca5594cf updated for version 7.2-149
vimboss
parents: 1800
diff changeset
423 #ifdef FEAT_FLOAT
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
424 char_u numbuf[NUMBUFLEN];
1851
e7f6ca5594cf updated for version 7.2-149
vimboss
parents: 1800
diff changeset
425 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
427 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 {
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
431 if (convert && tv.v_type == VAR_LIST)
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
432 {
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
433 ga_init2(&ga, (int)sizeof(char), 80);
1690
c6b06a4a8f92 updated for version 7.2b-023
vimboss
parents: 1683
diff changeset
434 if (tv.vval.v_list != NULL)
3000
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
435 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
436 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0);
3000
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
437 if (tv.vval.v_list->lv_len > 0)
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
438 ga_append(&ga, NL);
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
439 }
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
440 ga_append(&ga, NUL);
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
441 retval = (char_u *)ga.ga_data;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
442 }
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
443 #ifdef FEAT_FLOAT
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
444 else if (convert && tv.v_type == VAR_FLOAT)
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
445 {
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
446 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float);
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
447 retval = vim_strsave(numbuf);
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
448 }
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
449 #endif
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
450 else
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
451 retval = vim_strsave(tv_get_string(&tv));
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
452 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 /*
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
459 * Call eval_to_string() without using current local variables and using
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
460 * textwinlock. When "use_sandbox" is TRUE use the sandbox.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
463 eval_to_string_safe(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
464 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
465 int use_sandbox)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 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
468 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
469
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14897
diff changeset
470 save_funccal(&funccal_entry);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
471 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
472 ++sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
473 ++textwinlock;
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
474 retval = eval_to_string(arg, FALSE);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
475 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
476 --sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
477 --textwinlock;
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14897
diff changeset
478 restore_funccal();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 * Top level evaluation function, returning a number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 * Evaluates "expr" silently.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 * Returns -1 for an error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
487 varnumber_T
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
488 eval_to_number(char_u *expr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
490 typval_T rettv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
491 varnumber_T retval;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
492 char_u *p = skipwhite(expr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 ++emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
496 if (eval1(&p, &rettv, &EVALARG_EVALUATE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 retval = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
500 retval = tv_get_number_chk(&rettv, NULL);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
501 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 --emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
508 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
509 * Top level evaluation function.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
510 * Returns an allocated typval_T with the result.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
511 * Returns NULL when there is an error.
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
512 */
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
513 typval_T *
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
514 eval_expr(char_u *arg, exarg_T *eap)
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
515 {
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
516 typval_T *tv;
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
517
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
518 tv = ALLOC_ONE(typval_T);
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
519 if (tv != NULL && eval0(arg, tv, eap, &EVALARG_EVALUATE) == FAIL)
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
520 VIM_CLEAR(tv);
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
521
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
522 return tv;
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
523 }
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
524
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
526 * 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
527 * 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
528 * should have type VAR_UNKNOWN.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
529 * Returns OK or FAIL.
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
530 */
3078
2cbde6bcc623 updated for version 7.3.311
Bram Moolenaar <bram@vim.org>
parents: 3066
diff changeset
531 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
532 call_vim_function(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
533 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
534 int argc,
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
535 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
536 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
537 {
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
538 int ret;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
539 funcexe_T funcexe;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
541 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
542 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
543 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
544 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
545 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
546 ret = call_func(func, -1, rettv, argc, argv, &funcexe);
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
547 if (ret == FAIL)
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
548 clear_tv(rettv);
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
549
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
550 return ret;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
551 }
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
552
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
553 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
554 * Call Vim script function "func" and return the result as a number.
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
555 * 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
556 * 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
557 * have type VAR_UNKNOWN.
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
558 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
559 varnumber_T
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
560 call_func_retnr(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
561 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
562 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
563 typval_T *argv)
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
564 {
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
565 typval_T rettv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
566 varnumber_T retval;
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
567
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
568 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
569 return -1;
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
570
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
571 retval = tv_get_number_chk(&rettv, NULL);
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
572 clear_tv(&rettv);
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
573 return retval;
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
574 }
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
575
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
576 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
577 * Call Vim script function "func" and return the result as a string.
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
578 * 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
579 * 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
580 * have type VAR_UNKNOWN.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
581 */
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
582 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
583 call_func_retstr(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
584 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
585 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
586 typval_T *argv)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
587 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
588 typval_T rettv;
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
589 char_u *retval;
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
590
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
591 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
592 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
593
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
594 retval = vim_strsave(tv_get_string(&rettv));
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
595 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 }
1322
4ce0a7e4c6b3 updated for version 7.1-036
vimboss
parents: 1320
diff changeset
598
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
599 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
600 * 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
601 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
602 * have type VAR_UNKNOWN.
1690
c6b06a4a8f92 updated for version 7.2b-023
vimboss
parents: 1683
diff changeset
603 * Returns NULL when there is something wrong.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
604 */
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
605 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
606 call_func_retlist(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
607 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
608 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
609 typval_T *argv)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
610 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
611 typval_T rettv;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
612
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
613 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
614 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
615
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
616 if (rettv.v_type != VAR_LIST)
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
617 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
618 clear_tv(&rettv);
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
619 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
620 }
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
621
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
622 return rettv.vval.v_list;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
623 }
1322
4ce0a7e4c6b3 updated for version 7.1-036
vimboss
parents: 1320
diff changeset
624
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 * it in "*cp". Doesn't give error messages.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
631 eval_foldexpr(char_u *arg, int *cp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
633 typval_T tv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
634 varnumber_T retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 char_u *s;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
636 int use_sandbox = was_set_insecurely((char_u *)"foldexpr",
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
637 OPT_LOCAL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 ++emsg_off;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
640 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
641 ++sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
642 ++textwinlock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 *cp = NUL;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
644 if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
648 // If the result is a number, just return the number.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
649 if (tv.v_type == VAR_NUMBER)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
650 retval = tv.vval.v_number;
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
651 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
655 // 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
656 // the number.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
657 s = tv.vval.v_string;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 if (!VIM_ISDIGIT(*s) && *s != '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 *cp = *s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 retval = atol((char *)s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
662 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 --emsg_off;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
665 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
666 --sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
667 --textwinlock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
669 return (int)retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 /*
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
674 * Get an lval: variable, Dict item or List item that can be assigned a value
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
675 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]",
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
676 * "name.key", "name.key[expr]" etc.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
677 * Indexing only works if "name" is an existing List or Dictionary.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
678 * "name" points to the start of the name.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
679 * If "rettv" is not NULL it points to the value to be assigned.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
680 * "unlet" is TRUE for ":unlet": slightly different behavior when something is
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
681 * wrong; must end in space or cmd separator.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
682 *
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
683 * flags:
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
684 * 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
685 * GLV_READ_ONLY: will not change the variable
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
686 * GLV_NO_AUTOLOAD: do not use script autoloading
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
687 *
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
688 * Returns a pointer to just after the name, including indexes.
124
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
689 * When an evaluation error occurs "lp->ll_name" is NULL;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
690 * Returns NULL for a parsing error. Still need to free items in "lp"!
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
691 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
692 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
693 get_lval(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
694 char_u *name,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
695 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
696 lval_T *lp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
697 int unlet,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
698 int skip,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
699 int flags, // GLV_ values
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
700 int fne_flags) // flags for find_name_end()
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
701 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
702 char_u *p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
703 char_u *expr_start, *expr_end;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
704 int cc;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
705 dictitem_T *v;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
706 typval_T var1;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
707 typval_T var2;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
708 int empty1 = FALSE;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
709 listitem_T *ni;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
710 char_u *key = NULL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
711 int len;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
712 hashtab_T *ht;
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
713 int quiet = flags & GLV_QUIET;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
714
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
715 // Clear everything in "lp".
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
716 CLEAR_POINTER(lp);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
717
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
718 if (skip)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
719 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
720 // When skipping just find the end of the name.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
721 lp->ll_name = name;
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
722 return find_name_end(name, NULL, NULL, FNE_INCL_BR | fne_flags);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
723 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
724
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
725 // Find the end of the name.
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
726 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
727 lp->ll_name_end = p;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
728 if (expr_start != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
729 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
730 // 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
731 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
732 && *p != '[' && *p != '.')
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
733 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
734 emsg(_(e_trailing));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
735 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
736 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
737
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
738 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
739 if (lp->ll_exp_name == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
740 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
741 // 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
742 // 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
743 // aborting error, an interrupt, or an exception.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
744 if (!aborting() && !quiet)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
745 {
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
746 emsg_severe = TRUE;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
747 semsg(_(e_invarg2), name);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
748 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
749 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
750 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
751 lp->ll_name = lp->ll_exp_name;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
752 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
753 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
754 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
755 lp->ll_name = name;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
756
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
757 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
758 {
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
759 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
760 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
761
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
762 // 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
763 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
764 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
765 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
766 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
767
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
768 // Without [idx] or .key we are done.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
769 if ((*p != '[' && *p != '.') || lp->ll_name == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
770 return p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
771
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
772 cc = *p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
773 *p = NUL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
774 // 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
775 // 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
776 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
777 flags & GLV_NO_AUTOLOAD);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
778 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
779 semsg(_(e_undefvar), lp->ll_name);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
780 *p = cc;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
781 if (v == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
782 return NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
783
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
784 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
785 * Loop until no more [idx] or .key is following.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
786 */
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
787 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
788 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
789 var2.v_type = VAR_UNKNOWN;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
790 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
791 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
792 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
793 && !(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
794 && 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
795 && !(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
796 && lp->ll_tv->vval.v_blob != NULL))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
797 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
798 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
799 emsg(_("E689: Can only index a List, Dictionary or Blob"));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
800 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
801 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
802 if (lp->ll_range)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
803 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
804 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
805 emsg(_("E708: [:] must come last"));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
806 return NULL;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
807 }
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
808
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
809 len = -1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
810 if (*p == '.')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
811 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
812 key = p + 1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
813 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
814 ;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
815 if (len == 0)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
816 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
817 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
818 emsg(_(e_emptykey));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
819 return NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
820 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
821 p = key + len;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
822 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
823 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
824 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
825 // Get the index [expr] or the first index [expr: ].
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
826 p = skipwhite(p + 1);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
827 if (*p == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
828 empty1 = TRUE;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
829 else
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
830 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
831 empty1 = FALSE;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
832 if (eval1(&p, &var1, &EVALARG_EVALUATE) == FAIL) // recursive!
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
833 return NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
834 if (tv_get_string_chk(&var1) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
835 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
836 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
837 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
838 return NULL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
839 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
840 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
841
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
842 // Optionally get the second index [ :expr].
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
843 if (*p == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
844 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
845 if (lp->ll_tv->v_type == VAR_DICT)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
846 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
847 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
848 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
849 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
850 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
851 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
852 if (rettv != NULL
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
853 && !(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
854 && rettv->vval.v_list != NULL)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
855 && !(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
856 && rettv->vval.v_blob != NULL))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
857 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
858 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
859 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
860 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
861 return NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
862 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
863 p = skipwhite(p + 1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
864 if (*p == ']')
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
865 lp->ll_empty2 = TRUE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
866 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
867 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
868 lp->ll_empty2 = FALSE;
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
869 // recursive!
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
870 if (eval1(&p, &var2, &EVALARG_EVALUATE) == FAIL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
871 {
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
872 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
873 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
874 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
875 if (tv_get_string_chk(&var2) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
876 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
877 // 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
878 clear_tv(&var1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
879 clear_tv(&var2);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
880 return NULL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
881 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
882 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
883 lp->ll_range = TRUE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
884 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
885 else
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
886 lp->ll_range = FALSE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
887
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
888 if (*p != ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
889 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
890 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
891 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
892 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
893 clear_tv(&var2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
894 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
895 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
896
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
897 // Skip to past ']'.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
898 ++p;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
899 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
900
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
901 if (lp->ll_tv->v_type == VAR_DICT)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
902 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
903 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
904 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
905 // "[key]": get key from "var1"
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
906 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
907 if (key == NULL)
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8831
diff changeset
908 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
909 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
910 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
911 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
912 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
913 lp->ll_list = NULL;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
914 lp->ll_dict = lp->ll_tv->vval.v_dict;
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
915 lp->ll_di = dict_find(lp->ll_dict, key, len);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
916
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
917 // 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
918 // 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
919 // g: dictionary). Disallow overwriting a builtin function.
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
920 if (rettv != NULL && lp->ll_dict->dv_scope != 0)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
921 {
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
922 int prevval;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
923 int wrong;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
924
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
925 if (len != -1)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
926 {
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
927 prevval = key[len];
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
928 key[len] = NUL;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
929 }
4819
8c4324e6f477 updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
930 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
931 prevval = 0; // avoid compiler warning
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
932 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
933 && rettv->v_type == VAR_FUNC
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
934 && var_check_func_name(key, lp->ll_di == NULL))
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
935 || !valid_varname(key);
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
936 if (len != -1)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
937 key[len] = prevval;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
938 if (wrong)
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
939 {
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
940 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
941 return NULL;
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
942 }
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
943 }
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
944
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
945 if (lp->ll_di == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
946 {
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
947 // 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
948 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
949 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht())
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
950 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
951 semsg(_(e_illvar), name);
16013
93b08b92a049 patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents: 15969
diff changeset
952 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
953 return NULL;
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
954 }
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
955
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
956 // Key does not exist in dict: may need to add it.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
957 if (*p == '[' || *p == '.' || unlet)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
958 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
959 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
960 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
961 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
962 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
963 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
964 if (len == -1)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
965 lp->ll_newkey = vim_strsave(key);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
966 else
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
967 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
968 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
969 if (lp->ll_newkey == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
970 p = NULL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
971 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
972 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
973 // 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
974 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
975 && 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
976 {
8bff367672a4 patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents: 10908
diff changeset
977 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
978 return NULL;
10910
8bff367672a4 patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents: 10908
diff changeset
979 }
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
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(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
982 lp->ll_tv = &lp->ll_di->di_tv;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
983 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
984 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
985 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
986 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
987
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
988 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
989 * 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
990 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
991 if (empty1)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
992 lp->ll_n1 = 0;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
993 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
994 // is number or string
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
995 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
996 clear_tv(&var1);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
997
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
998 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
999 || lp->ll_n1 > bloblen
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1000 || (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
1001 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1002 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1003 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
1004 clear_tv(&var2);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1005 return NULL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1006 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1007 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
1008 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1009 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
1010 clear_tv(&var2);
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1011 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
1012 || lp->ll_n2 >= bloblen
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1013 || 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
1014 {
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
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_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
1017 return NULL;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1018 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1019 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1020 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
1021 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
1022 break;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1023 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1024 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1025 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1026 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1027 * Get the number and item for the only or first index of the List.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1028 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1029 if (empty1)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1030 lp->ll_n1 = 0;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1031 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1032 // 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
1033 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
1034 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
1035
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1036 lp->ll_dict = NULL;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1037 lp->ll_list = lp->ll_tv->vval.v_list;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1038 lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1039 if (lp->ll_li == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1040 {
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1041 if (lp->ll_n1 < 0)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1042 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1043 lp->ll_n1 = 0;
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1044 lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1045 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1046 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1047 if (lp->ll_li == NULL)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
1048 {
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
1049 clear_tv(&var2);
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1050 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1051 semsg(_(e_listidx), lp->ll_n1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1052 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1053 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1054
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1055 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1056 * May need to find the item or absolute index for the second
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1057 * index of a range.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1058 * When no index given: "lp->ll_empty2" is TRUE.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1059 * Otherwise "lp->ll_n2" is set to the second index.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1060 */
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1061 if (lp->ll_range && !lp->ll_empty2)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1062 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1063 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
1064 // is number or string
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1065 clear_tv(&var2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1066 if (lp->ll_n2 < 0)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1067 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1068 ni = list_find(lp->ll_list, lp->ll_n2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1069 if (ni == NULL)
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1070 {
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1071 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1072 semsg(_(e_listidx), lp->ll_n2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1073 return NULL;
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1074 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1075 lp->ll_n2 = list_idx_of_item(lp->ll_list, ni);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1076 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1077
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1078 // Check that lp->ll_n2 isn't before lp->ll_n1.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1079 if (lp->ll_n1 < 0)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1080 lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1081 if (lp->ll_n2 < lp->ll_n1)
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1082 {
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1083 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1084 semsg(_(e_listidx), lp->ll_n2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1085 return NULL;
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1086 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1087 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1088
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1089 lp->ll_tv = &lp->ll_li->li_tv;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1090 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1091 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1092
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
1093 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
1094 lp->ll_name_end = p;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1095 return p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1096 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1097
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1098 /*
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1099 * Clear lval "lp" that was filled by get_lval().
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1100 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1101 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1102 clear_lval(lval_T *lp)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1103 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1104 vim_free(lp->ll_exp_name);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1105 vim_free(lp->ll_newkey);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1106 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1107
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1108 /*
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1109 * Set a variable that was parsed by get_lval() to "rettv".
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1110 * "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
1111 * "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
1112 * "%" for "%=", "." for ".=" or "=" for "=".
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1113 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
1114 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1115 set_var_lval(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1116 lval_T *lp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1117 char_u *endp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1118 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1119 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
1120 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
1121 char_u *op)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1122 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1123 int cc;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1124 listitem_T *ri;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1125 dictitem_T *di;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1126
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1127 if (lp->ll_tv == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1128 {
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1129 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
1130 *endp = NUL;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1131 if (lp->ll_blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1132 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1133 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
1134
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1135 if (op != NULL && *op != '=')
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1136 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1137 semsg(_(e_letwrong), op);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1138 return;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1139 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1140
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1141 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
1142 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1143 int il, ir;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1144
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1145 if (lp->ll_empty2)
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1146 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
1147
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1148 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
1149 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1150 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
1151 return;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1152 }
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1153 if (lp->ll_empty2)
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1154 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
1155
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1156 ir = 0;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1157 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
1158 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
1159 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
1160 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1161 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1162 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1163 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
1164 if (!error)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1165 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1166 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
1167
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1168 // 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
1169 // the end is an error otherwise.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1170 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
1171 || (lp->ll_n1 == gap->ga_len
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1172 && 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
1173 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1174 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
1175 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
1176 ++gap->ga_len;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1177 }
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1178 // 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
1179 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1180 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1181 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1182 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
1183 {
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1184 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
1185
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1186 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
1187 {
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1188 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
1189 *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
1190 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1191 }
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1192
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1193 // 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
1194 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
1195 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
1196 &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
1197 {
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1198 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
1199 || (!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
1200 && !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
1201 && 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
1202 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
1203 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
1204 }
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1205 }
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1206 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1207 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
1208 *endp = cc;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1209 }
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
1210 else if (var_check_lock(lp->ll_newkey == NULL
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1211 ? lp->ll_tv->v_lock
6773
eb4b705a5d6a patch 7.4.708
Bram Moolenaar <bram@vim.org>
parents: 6761
diff changeset
1212 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE))
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1213 ;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1214 else if (lp->ll_range)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1215 {
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1216 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
1217 int ll_n1 = lp->ll_n1;
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1218
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1219 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
1220 {
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1221 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
1222 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1223 }
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1224
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1225 /*
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1226 * Check whether any of the list items is locked
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1227 */
6422
9fbb9c60ab41 updated for version 7.4.541
Bram Moolenaar <bram@vim.org>
parents: 6388
diff changeset
1228 for (ri = rettv->vval.v_list->lv_first; ri != NULL && ll_li != NULL; )
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1229 {
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
1230 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE))
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1231 return;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1232 ri = ri->li_next;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1233 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == ll_n1))
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1234 break;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1235 ll_li = ll_li->li_next;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1236 ++ll_n1;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1237 }
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1238
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1239 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1240 * Assign the List values to the list items.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1241 */
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1242 for (ri = rettv->vval.v_list->lv_first; ri != NULL; )
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1243 {
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1244 if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1245 tv_op(&lp->ll_li->li_tv, &ri->li_tv, op);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1246 else
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1247 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1248 clear_tv(&lp->ll_li->li_tv);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1249 copy_tv(&ri->li_tv, &lp->ll_li->li_tv);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1250 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1251 ri = ri->li_next;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1252 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1))
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1253 break;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1254 if (lp->ll_li->li_next == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1255 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1256 // Need to add an empty item.
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1257 if (list_append_number(lp->ll_list, 0) == FAIL)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1258 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1259 ri = NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1260 break;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1261 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1262 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1263 lp->ll_li = lp->ll_li->li_next;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1264 ++lp->ll_n1;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1265 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1266 if (ri != NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1267 emsg(_("E710: List value has more items than target"));
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1268 else if (lp->ll_empty2
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1269 ? (lp->ll_li != NULL && lp->ll_li->li_next != NULL)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1270 : 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
1271 emsg(_("E711: List value has not enough items"));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1272 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1273 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1274 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1275 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1276 * Assign to a List or Dictionary item.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1277 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1278 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
1279 {
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1280 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
1281 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1282 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1283 if (lp->ll_newkey != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1284 {
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1285 if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1286 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1287 semsg(_(e_letwrong), op);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1288 return;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1289 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1290
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1291 // Need to add an item to the Dictionary.
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1292 di = dictitem_alloc(lp->ll_newkey);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1293 if (di == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1294 return;
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1295 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL)
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1296 {
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1297 vim_free(di);
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1298 return;
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1299 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1300 lp->ll_tv = &di->di_tv;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1301 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1302 else if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1303 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1304 tv_op(lp->ll_tv, rettv, op);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1305 return;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1306 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1307 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1308 clear_tv(lp->ll_tv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1309
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1310 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1311 * Assign the value to the variable or list item.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1312 */
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1313 if (copy)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1314 copy_tv(rettv, lp->ll_tv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1315 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1316 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1317 *lp->ll_tv = *rettv;
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
1318 lp->ll_tv->v_lock = 0;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1319 init_tv(rettv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1320 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1321 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1324 /*
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1325 * 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
1326 * and "tv1 .= tv2"
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1327 * Returns OK or FAIL.
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1328 */
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1329 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1330 tv_op(typval_T *tv1, typval_T *tv2, char_u *op)
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1331 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
1332 varnumber_T n;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1333 char_u numbuf[NUMBUFLEN];
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1334 char_u *s;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1335
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1336 // 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
1337 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
1338 && tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL)
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1339 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1340 switch (tv1->v_type)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1341 {
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
1342 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
1343 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
1344 case VAR_VOID:
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1345 case VAR_DICT:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1346 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
1347 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
1348 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
1349 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
1350 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
1351 case VAR_CHANNEL:
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1352 break;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1353
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1354 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1355 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
1356 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1357 // BLOB += BLOB
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1358 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
1359 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1360 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
1361 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
1362 int i, len = blob_len(b2);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1363 for (i = 0; i < len; i++)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1364 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
1365 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1366 return OK;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1367
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1368 case VAR_LIST:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1369 if (*op != '+' || tv2->v_type != VAR_LIST)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1370 break;
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1371 // List += List
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1372 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1373 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1374 return OK;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1375
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1376 case VAR_NUMBER:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1377 case VAR_STRING:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1378 if (tv2->v_type == VAR_LIST)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1379 break;
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1380 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
1381 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1382 // 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
1383 n = tv_get_number(tv1);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1384 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1385 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1386 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1387 float_T f = n;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1388
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1389 if (*op == '%')
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1390 break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1391 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1392 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1393 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
1394 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
1395 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
1396 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
1397 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1398 clear_tv(tv1);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1399 tv1->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1400 tv1->vval.v_float = f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1401 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1402 else
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1403 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1404 {
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1405 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1406 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1407 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
1408 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
1409 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
1410 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
1411 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
1412 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1413 clear_tv(tv1);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1414 tv1->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1415 tv1->vval.v_number = n;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1416 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1417 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1418 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1419 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1420 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1421 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1422
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1423 // str .= str
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1424 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
1425 s = concat_str(s, tv_get_string_buf(tv2, numbuf));
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1426 clear_tv(tv1);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1427 tv1->v_type = VAR_STRING;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1428 tv1->vval.v_string = s;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1429 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1430 return OK;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1431
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1432 case VAR_FLOAT:
8364
991d8fd4d841 commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents: 8350
diff changeset
1433 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1434 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1435 float_T f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1436
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1437 if (*op == '%' || *op == '.'
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1438 || (tv2->v_type != VAR_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1439 && tv2->v_type != VAR_NUMBER
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1440 && tv2->v_type != VAR_STRING))
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1441 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1442 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1443 f = tv2->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1444 else
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1445 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
1446 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1447 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1448 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
1449 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
1450 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
1451 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
1452 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1453 }
8364
991d8fd4d841 commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents: 8350
diff changeset
1454 #endif
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1455 return OK;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1456 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1457 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1458
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1459 semsg(_(e_letwrong), op);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1460 return FAIL;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1461 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1462
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1463 /*
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1464 * Evaluate the expression used in a ":for var in expr" command.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1465 * "arg" points to "var".
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1466 * Set "*errp" to TRUE for an error, FALSE otherwise;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1467 * Return a pointer that holds the info. Null when there is an error.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1468 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1469 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1470 eval_for_line(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1471 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1472 int *errp,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1473 exarg_T *eap,
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1474 int skip)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1475 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1476 forinfo_T *fi;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1477 char_u *expr;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1478 typval_T tv;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1479 list_T *l;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1480 evalarg_T evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1481
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1482 CLEAR_FIELD(evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1483 evalarg.eval_flags = skip ? 0 : EVAL_EVALUATE;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1484 *errp = TRUE; // default: there is an error
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1485
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
1486 fi = ALLOC_CLEAR_ONE(forinfo_T);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1487 if (fi == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1488 return NULL;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1489
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20751
diff changeset
1490 expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon, FALSE);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1491 if (expr == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1492 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1493
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1494 expr = skipwhite(expr);
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1495 if (expr[0] != 'i' || expr[1] != 'n' || !VIM_ISWHITE(expr[2]))
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1496 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1497 emsg(_(e_missing_in));
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1498 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1499 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1500
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1501 if (skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1502 ++emsg_skip;
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1503 if (eval0(skipwhite(expr + 2), &tv, eap, &evalarg) == OK)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1504 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1505 *errp = FALSE;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1506 if (!skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1507 {
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1508 if (tv.v_type == VAR_LIST)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1509 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1510 l = tv.vval.v_list;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1511 if (l == NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1512 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1513 // 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
1514 clear_tv(&tv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1515 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1516 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1517 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1518 // Need a real list here.
20392
4c317d8c1051 patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
1519 CHECK_LIST_MATERIALIZE(l);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1520
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1521 // 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
1522 // the list being used in "tv".
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1523 fi->fi_list = l;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1524 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
1525 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
1526 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1527 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1528 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
1529 {
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1530 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
1531 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
1532 {
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1533 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
1534
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1535 // 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
1536 // 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
1537 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
1538 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
1539 }
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1540 clear_tv(&tv);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1541 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1542 else
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1543 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1544 emsg(_(e_listreq));
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1545 clear_tv(&tv);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1546 }
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1547 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1548 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1549 if (skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1550 --emsg_skip;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1551
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1552 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1553 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1554
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1555 /*
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1556 * Use the first item in a ":for" list. Advance to the next.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1557 * Assign the values to the variable (list). "arg" points to the first one.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1558 * Return TRUE when a valid item was found, FALSE when at end of list or
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1559 * something wrong.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1560 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1561 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1562 next_for_item(void *fi_void, char_u *arg)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1563 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4936
diff changeset
1564 forinfo_T *fi = (forinfo_T *)fi_void;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1565 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
1566 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
1567 LET_NO_COMMAND : 0;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1568 listitem_T *item;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1569
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1570 if (fi->fi_blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1571 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1572 typval_T tv;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1573
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1574 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
1575 return FALSE;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1576 tv.v_type = VAR_NUMBER;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1577 tv.v_lock = VAR_FIXED;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1578 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
1579 ++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
1580 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
1581 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
1582 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1583
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1584 item = fi->fi_lw.lw_item;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1585 if (item == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1586 result = FALSE;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1587 else
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1588 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1589 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
1590 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
1591 fi->fi_varcount, flag, NULL) == OK);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1592 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1593 return result;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1594 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1595
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1596 /*
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1597 * Free the structure used to store info used by ":for".
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1598 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1599 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1600 free_for_info(void *fi_void)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1601 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1602 forinfo_T *fi = (forinfo_T *)fi_void;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1603
92
a9e90b3356b6 updated for version 7.0036
vimboss
parents: 88
diff changeset
1604 if (fi != NULL && fi->fi_list != NULL)
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1605 {
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1606 list_rem_watch(fi->fi_list, &fi->fi_lw);
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1607 list_unref(fi->fi_list);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1608 }
15460
543cff56dd3f patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15458
diff changeset
1609 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
1610 blob_unref(fi->fi_blob);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1611 vim_free(fi);
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1612 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1613
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1615 set_context_for_expression(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1616 expand_T *xp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1617 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1618 cmdidx_T cmdidx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 int got_eq = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 int c;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1622 char_u *p;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1623
18713
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
1624 if (cmdidx == CMD_let || cmdidx == CMD_const)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1625 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1626 xp->xp_context = EXPAND_USER_VARS;
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
1627 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1628 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1629 // ":let var1 var2 ...": find last space.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
1630 for (p = arg + STRLEN(arg); p >= arg; )
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1631 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1632 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
1633 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
1634 if (VIM_ISWHITE(*p))
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1635 break;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1636 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1637 return;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1638 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1639 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1640 else
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1641 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1642 : EXPAND_EXPRESSION;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 while ((xp->xp_pattern = vim_strpbrk(arg,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 c = *xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 if (c == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 c = xp->xp_pattern[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 if (c == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 xp->xp_context = cmdidx != CMD_let || got_eq
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 ? EXPAND_EXPRESSION : EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 else if (c != ' ')
201
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1657 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 xp->xp_context = EXPAND_SETTINGS;
201
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1659 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':')
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1660 xp->xp_pattern += 2;
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1661
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1662 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 else if (c == '$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1666 // environment variable
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 xp->xp_context = EXPAND_ENV_VARS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 else if (c == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 got_eq = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 }
8763
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1674 else if (c == '#'
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1675 && xp->xp_context == EXPAND_EXPRESSION)
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1676 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1677 // Autoload function/variable contains '#'.
8763
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1678 break;
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1679 }
6367
81c9b19ee0fb updated for version 7.4.516
Bram Moolenaar <bram@vim.org>
parents: 6361
diff changeset
1680 else if ((c == '<' || c == '#')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 && xp->xp_context == EXPAND_FUNCTIONS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 && vim_strchr(xp->xp_pattern, '(') == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1684 // Function name can start with "<SNR>" and contain '#'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 else if (cmdidx != CMD_let || got_eq)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1689 if (c == '"') // string
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 while ((c = *++xp->xp_pattern) != NUL && c != '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 if (c == '\\' && xp->xp_pattern[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 xp->xp_context = EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1696 else if (c == '\'') // literal string
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1698 // Trick: '' is like stopping and starting a literal string.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 while ((c = *++xp->xp_pattern) != NUL && c != '\'')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 /* skip */ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 xp->xp_context = EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 else if (c == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 if (xp->xp_pattern[1] == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 xp->xp_context = EXPAND_COMMANDS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1717 // 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
1718 // anyway.
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1719 xp->xp_context = EXPAND_EXPRESSION;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 arg = xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 if (*arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 while ((c = *++arg) != NUL && (c == ' ' || c == '\t'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 /* skip */ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 xp->xp_pattern = arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 /*
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1729 * Return TRUE if "pat" matches "text".
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1730 * 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
1731 */
17377
cb008de2a6ec patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17375
diff changeset
1732 int
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1733 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
1734 {
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1735 int matches = FALSE;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1736 char_u *save_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1737 regmatch_T regmatch;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1738
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1739 // avoid 'l' flag in 'cpoptions'
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1740 save_cpo = p_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1741 p_cpo = (char_u *)"";
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1742 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
1743 if (regmatch.regprog != NULL)
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1744 {
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1745 regmatch.rm_ic = ic;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1746 matches = vim_regexec_nl(&regmatch, text, (colnr_T)0);
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1747 vim_regfree(regmatch.regprog);
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1748 }
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1749 p_cpo = save_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1750 return matches;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1751 }
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1752
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1753 /*
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1754 * 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
1755 * "expr->name(arg)".
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1756 * Returns OK or FAIL.
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1757 */
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1758 static int
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1759 eval_func(
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1760 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
1761 char_u *name,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1762 int name_len,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1763 typval_T *rettv,
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1764 int flags,
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1765 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
1766 {
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1767 int evaluate = flags & EVAL_EVALUATE;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1768 char_u *s = name;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1769 int len = name_len;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1770 partial_T *partial;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1771 int ret = OK;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1772
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1773 if (!evaluate)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1774 check_vars(s, len);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1775
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1776 // 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
1777 // use its contents.
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1778 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
1779
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1780 // 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
1781 // the name invalid.
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1782 s = vim_strsave(s);
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1783 if (s == NULL || (flags & EVAL_CONSTANT))
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1784 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1785 else
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1786 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1787 funcexe_T funcexe;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1788
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1789 // Invoke the function.
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
1790 CLEAR_FIELD(funcexe);
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1791 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
1792 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
1793 funcexe.evaluate = evaluate;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1794 funcexe.partial = partial;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1795 funcexe.basetv = basetv;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1796 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
1797 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1798 vim_free(s);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1799
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1800 // 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
1801 // 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
1802 // 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
1803 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
1804 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1805 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
1806 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
1807 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1808
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1809 // 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
1810 // 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
1811 // 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
1812 if (evaluate && aborting())
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1813 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1814 if (ret == OK)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1815 clear_tv(rettv);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1816 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1817 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1818 return ret;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1819 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1820
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1821 /*
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1822 * If inside Vim9 script, "arg" points to the end of a line (ignoring comments)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1823 * and there is a next line, return the next line (skipping blanks) and set
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1824 * "getnext".
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1825 * Otherwise just return "arg" unmodified and set "getnext" to FALSE.
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1826 * "arg" must point somewhere inside a line, not at the start.
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1827 */
21028
7acceb76669f patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents: 21026
diff changeset
1828 char_u *
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1829 eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1830 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1831 *getnext = FALSE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1832 if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1833 && evalarg != NULL
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1834 && evalarg->eval_cookie != NULL
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1835 && (*arg == NUL || (VIM_ISWHITE(arg[-1])
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1836 && (*arg == '"' || *arg == '#')))
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1837 && source_nextline(evalarg->eval_cookie) != NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1838 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1839 char_u *p = source_nextline(evalarg->eval_cookie);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1840
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1841 if (p != NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1842 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1843 *getnext = TRUE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1844 return skipwhite(p);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1845 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1846 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1847 return arg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1848 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1849
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1850 /*
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1851 * To be called after eval_next_non_blank() sets "getnext" to TRUE.
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1852 */
21028
7acceb76669f patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents: 21026
diff changeset
1853 char_u *
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1854 eval_next_line(evalarg_T *evalarg)
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1855 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1856 garray_T *gap = &evalarg->eval_ga;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1857 char_u *line;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1858
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1859 line = getsourceline(0, evalarg->eval_cookie, 0, TRUE);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1860 if (gap->ga_itemsize > 0 && ga_grow(gap, 1) == OK)
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1861 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1862 // Going to concatenate the lines after parsing.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1863 ((char_u **)gap->ga_data)[gap->ga_len] = line;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1864 ++gap->ga_len;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1865 }
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1866 else
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1867 {
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1868 vim_free(evalarg->eval_tofree);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1869 evalarg->eval_tofree = line;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1870 }
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1871 return skipwhite(line);
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1872 }
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1873
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1874 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 * The "evaluate" argument: When FALSE, the argument is only parsed but not
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1876 * executed. The function may return OK, but the rettv will be of type
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 * VAR_UNKNOWN. The function still returns FAIL for a syntax error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 * Handle zero level expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 * This calls eval1() and handles error message and nextcmd.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1883 * Put the result in "rettv" when returning OK and "evaluate" is TRUE.
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1884 * Note: "rettv.v_lock" is not set.
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1885 * "evalarg" can be NULL, EVALARG_EVALUATE or a pointer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1888 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1889 eval0(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1890 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1891 typval_T *rettv,
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1892 exarg_T *eap,
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1893 evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 int ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 char_u *p;
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1897 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
1898 int called_emsg_before = called_emsg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1899 int flags = evalarg == NULL ? 0 : evalarg->eval_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 p = skipwhite(arg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1902 ret = eval1(&p, rettv, evalarg);
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1903
20111
f40231487a49 patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
1904 if (ret == FAIL || !ends_excmd2(arg, p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 if (ret != FAIL)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1907 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 * Report the invalid expression unless the expression evaluation has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 * 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
1911 * 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
1912 * Also check called_emsg for when using assert_fails().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 */
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1914 if (!aborting()
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1915 && did_emsg == did_emsg_before
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1916 && called_emsg == called_emsg_before
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1917 && (flags & EVAL_CONSTANT) == 0)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1918 semsg(_(e_invexpr2), arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 }
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1921
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1922 if (eap != NULL)
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1923 eap->nextcmd = check_nextcmd(p);
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1924
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1925 if (evalarg != NULL && eap != NULL && evalarg->eval_tofree != NULL)
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1926 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1927 // We may need to keep the original command line, e.g. for
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1928 // ":let" it has the variable names. But we may also need the
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1929 // new one, "nextcmd" points into it. Keep both.
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1930 vim_free(eap->cmdline_tofree);
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1931 eap->cmdline_tofree = *eap->cmdlinep;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1932 *eap->cmdlinep = evalarg->eval_tofree;
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
1933 evalarg->eval_tofree = NULL;
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
1934 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 * Handle top level expression:
1800
e7633eb32cfd updated for version 7.2-098
vimboss
parents: 1794
diff changeset
1941 * expr2 ? expr1 : expr1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 *
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1946 * Note: "rettv.v_lock" is not set.
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1947 *
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
1950 int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1951 eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 {
21022
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1953 char_u *p;
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1954 int getnext;
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1955
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1959 if (eval2(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961
21022
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1962 p = eval_next_non_blank(*arg, evalarg, &getnext);
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1963 if (*p == '?')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1965 int result;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1966 typval_T var2;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1967 evalarg_T nested_evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1968 int orig_flags;
21002
4852db420162 patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1969 int evaluate;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1970
21022
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1971 if (getnext)
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1972 *arg = eval_next_line(evalarg);
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
1973
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1974 if (evalarg == NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1975 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1976 CLEAR_FIELD(nested_evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1977 orig_flags = 0;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1978 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1979 else
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1980 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1981 nested_evalarg = *evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1982 orig_flags = evalarg->eval_flags;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1983 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1984
21002
4852db420162 patch 8.2.1052: build failure with older compilers
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
1985 evaluate = nested_evalarg.eval_flags & EVAL_EVALUATE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 result = FALSE;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1987 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1989 int error = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1990
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1991 if (tv_get_number_chk(rettv, &error) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 result = TRUE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1993 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1994 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1995 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 /*
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
1999 * Get the second variable. Recursive!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 *arg = skipwhite(*arg + 1);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2002 nested_evalarg.eval_flags = result ? orig_flags
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2003 : orig_flags & ~EVAL_EVALUATE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2004 if (eval1(arg, rettv, &nested_evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 * Check for the ":".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 */
21022
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2010 p = eval_next_non_blank(*arg, evalarg, &getnext);
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2011 if (*p != ':')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2013 emsg(_(e_missing_colon));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 if (evaluate && result)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2015 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 }
21022
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2018 if (getnext)
9d8634e91d1b patch 8.2.1062: Vim9: no line break allowed inside "cond ? val1 : val2"
Bram Moolenaar <Bram@vim.org>
parents: 21002
diff changeset
2019 *arg = eval_next_line(evalarg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 /*
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2022 * Get the third variable. Recursive!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 *arg = skipwhite(*arg + 1);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2025 nested_evalarg.eval_flags = !result ? orig_flags
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2026 : orig_flags & ~EVAL_EVALUATE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2027 if (eval1(arg, &var2, &nested_evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 if (evaluate && result)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2030 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 if (evaluate && !result)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2034 *rettv = var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 * Handle first level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 * expr2 || expr2 || expr2 logical OR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2050 eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 {
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2052 char_u *p;
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2053 int getnext;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2054 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 long result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 int first;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2057 int error = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2062 if (eval3(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 * Repeat until there is no following "||".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 first = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 result = FALSE;
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2070 p = eval_next_non_blank(*arg, evalarg, &getnext);
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2071 while (p[0] == '|' && p[1] == '|')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2073 evalarg_T nested_evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2074 int evaluate;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2075 int orig_flags;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2076
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2077 if (getnext)
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2078 *arg = eval_next_line(evalarg);
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2079
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2080 if (evalarg == NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2081 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2082 CLEAR_FIELD(nested_evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2083 orig_flags = 0;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2084 evaluate = FALSE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2085 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2086 else
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2087 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2088 nested_evalarg = *evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2089 orig_flags = evalarg->eval_flags;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2090 evaluate = orig_flags & EVAL_EVALUATE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2091 }
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2092
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 if (evaluate && first)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2095 if (tv_get_number_chk(rettv, &error) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 result = TRUE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2097 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2098 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2099 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 first = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 *arg = skipwhite(*arg + 2);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2107 nested_evalarg.eval_flags = !result ? orig_flags
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2108 : orig_flags & ~EVAL_EVALUATE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2109 if (eval3(arg, &var2, &nested_evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 * Compute the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 if (evaluate && !result)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2117 if (tv_get_number_chk(&var2, &error) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 result = TRUE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2119 clear_tv(&var2);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2120 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2121 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2125 rettv->v_type = VAR_NUMBER;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2126 rettv->vval.v_number = result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 }
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2128
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2129 p = eval_next_non_blank(*arg, evalarg, &getnext);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 * Handle second level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 * expr3 && expr3 && expr3 logical AND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2145 eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 {
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2147 char_u *p;
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2148 int getnext;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2149 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 long result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 int first;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2152 int error = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2157 if (eval4(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 * Repeat until there is no following "&&".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 first = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 result = TRUE;
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2165 p = eval_next_non_blank(*arg, evalarg, &getnext);
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2166 while (p[0] == '&' && p[1] == '&')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2168 evalarg_T nested_evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2169 int orig_flags;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2170 int evaluate;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2171
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2172 if (getnext)
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2173 *arg = eval_next_line(evalarg);
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2174
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2175 if (evalarg == NULL)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2176 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2177 CLEAR_FIELD(nested_evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2178 orig_flags = 0;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2179 evaluate = FALSE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2180 }
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2181 else
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2182 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2183 nested_evalarg = *evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2184 orig_flags = evalarg->eval_flags;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2185 evaluate = orig_flags & EVAL_EVALUATE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2186 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 if (evaluate && first)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2189 if (tv_get_number_chk(rettv, &error) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 result = FALSE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2191 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2192 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2193 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 first = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 *arg = skipwhite(*arg + 2);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2201 nested_evalarg.eval_flags = result ? orig_flags
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2202 : orig_flags & ~EVAL_EVALUATE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2203 if (eval4(arg, &var2, &nested_evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 * Compute the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 if (evaluate && result)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2211 if (tv_get_number_chk(&var2, &error) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 result = FALSE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2213 clear_tv(&var2);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2214 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2215 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2219 rettv->v_type = VAR_NUMBER;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2220 rettv->vval.v_number = result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 }
21024
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2222
02b03915855d patch 8.2.1063: Vim9: no line break allowed before || or &&
Bram Moolenaar <Bram@vim.org>
parents: 21022
diff changeset
2223 p = eval_next_non_blank(*arg, evalarg, &getnext);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 * Handle third level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 * var1 == var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 * var1 =~ var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 * var1 != var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 * var1 !~ var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 * var1 > var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 * var1 >= var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 * var1 < var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 * var1 <= var2
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2239 * var1 is var2
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2240 * var1 isnot var2
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2248 eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2250 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 char_u *p;
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2252 int getnext;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 int i;
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2254 exptype_T type = EXPR_UNKNOWN;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 int len = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 int ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2261 if (eval5(arg, rettv, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2264 p = eval_next_non_blank(*arg, evalarg, &getnext);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 switch (p[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 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
2268 type = EXPR_EQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 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
2270 type = EXPR_MATCH;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 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
2273 type = EXPR_NEQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 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
2275 type = EXPR_NOMATCH;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 case '>': if (p[1] != '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2279 type = EXPR_GREATER;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 else
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2283 type = EXPR_GEQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 case '<': if (p[1] != '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2287 type = EXPR_SMALLER;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 else
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2291 type = EXPR_SEQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 break;
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2293 case 'i': if (p[1] == 's')
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2294 {
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2295 if (p[2] == 'n' && p[3] == 'o' && p[4] == 't')
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2296 len = 5;
7064
5fc5c5bf2233 commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents: 7046
diff changeset
2297 i = p[len];
5fc5c5bf2233 commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents: 7046
diff changeset
2298 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
2299 type = len == 2 ? EXPR_IS : EXPR_ISNOT;
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2300 }
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2301 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 /*
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2305 * If there is a comparative operator, use it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 */
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2307 if (type != EXPR_UNKNOWN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 {
21026
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2309 if (getnext)
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2310 *arg = eval_next_line(evalarg);
fe2ed85db946 patch 8.2.1064: Vim9: no line break allowed before comperators
Bram Moolenaar <Bram@vim.org>
parents: 21024
diff changeset
2311
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2312 // extra question mark appended: ignore case
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 if (p[len] == '?')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 ic = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2318 // extra '#' appended: match case
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 else if (p[len] == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 ic = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2324 // nothing appended: use 'ignorecase'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 ic = p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 *arg = skipwhite(p + len);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2332 if (eval5(arg, &var2, evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2334 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 }
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2337 if (evalarg != NULL && (evalarg->eval_flags & EVAL_EVALUATE))
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2338 {
18966
6bd715870e32 patch 8.2.0044: expression type is used inconsistently
Bram Moolenaar <Bram@vim.org>
parents: 18939
diff changeset
2339 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
2340
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2341 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
2342 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
2343 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2349 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2350 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
2351 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2352 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
2353 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
2354 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
2355 int i;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2356
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2357 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
2358 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2359 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
2360 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
2361 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
2362 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
2363
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2364 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
2365 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
2366 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2367 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2368
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2369 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2370 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
2371 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2372 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
2373
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2374 // concatenate Lists
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2375 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
2376 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2377 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
2378 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
2379 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2380 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2381 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
2382 *tv1 = var3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2383 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2384 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2385
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387 * Handle fourth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 * + number addition
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 * - number subtraction
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2390 * . 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
2391 * .. string concatenation
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 static int
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2399 eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2401 int evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2406 if (eval6(arg, rettv, evalarg, FALSE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 * Repeat computing, until no '+', '-' or '.' is following.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2414 int getnext;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2415 char_u *p;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2416 int op;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2417 int concat;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2418 typval_T var2;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2419
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2420 // "." is only string concatenation when scriptversion is 1
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2421 p = eval_next_non_blank(*arg, evalarg, &getnext);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2422 op = *p;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2423 concat = op == '.' && (*(p + 1) == '.' || current_sctx.sc_version < 2);
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2424 if (op != '+' && op != '-' && !concat)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 break;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2426 if (getnext)
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2427 *arg = eval_next_line(evalarg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2429 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
2430 && rettv->v_type != VAR_BLOB))
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2431 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2432 && (op == '.' || rettv->v_type != VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2433 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2434 )
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2435 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2436 // 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
2437 // 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
2438 // 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
2439 // 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
2440 // 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
2441 // 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
2442 // side effects after an error.
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2443 if (evaluate && tv_get_string_chk(rettv) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2444 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2445 clear_tv(rettv);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2446 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2447 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2448 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2449
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 */
16219
bd49e1656c72 patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents: 16170
diff changeset
2453 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
2454 ++*arg;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 *arg = skipwhite(*arg + 1);
21044
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2456 eval_next_non_blank(*arg, evalarg, &getnext);
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2457 if (getnext)
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2458 *arg = eval_next_line(evalarg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2459 if (eval6(arg, &var2, evalarg, op == '.') == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2461 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2465 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 * Compute the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 if (op == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2472 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2473 char_u *s1 = tv_get_string_buf(rettv, buf1);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2474 char_u *s2 = tv_get_string_buf_chk(&var2, buf2);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2475
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2476 if (s2 == NULL) // type error ?
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2477 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2478 clear_tv(rettv);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2479 clear_tv(&var2);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2480 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2481 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
2482 p = concat_str(s1, s2);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2483 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2484 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2485 rettv->vval.v_string = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2487 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
2488 && 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
2489 eval_addblob(rettv, &var2);
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2490 else if (op == '+' && rettv->v_type == VAR_LIST
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2491 && var2.v_type == VAR_LIST)
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2492 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2493 if (eval_addlist(rettv, &var2) == FAIL)
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2494 return FAIL;
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2495 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2498 int error = FALSE;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2499 varnumber_T n1, n2;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2500 #ifdef FEAT_FLOAT
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2501 float_T f1 = 0, f2 = 0;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2502
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2503 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2504 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2505 f1 = rettv->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2506 n1 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2507 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2508 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2509 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2510 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2511 n1 = tv_get_number_chk(rettv, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2512 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2513 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2514 // 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
2515 // "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
2516 // before evaluating the 2nd operand.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2517 clear_tv(rettv);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2518 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2519 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2520 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2521 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2522 f1 = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2523 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2524 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2525 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2526 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2527 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2528 f2 = var2.vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2529 n2 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2530 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2531 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2532 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2533 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2534 n2 = tv_get_number_chk(&var2, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2535 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2536 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2537 clear_tv(rettv);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2538 clear_tv(&var2);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2539 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2540 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2541 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2542 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2543 f2 = n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2544 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2545 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2546 clear_tv(rettv);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2547
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2548 #ifdef FEAT_FLOAT
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2549 // If there is a float on either side the result is a float.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2550 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2551 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2552 if (op == '+')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2553 f1 = f1 + f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2554 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2555 f1 = f1 - f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2556 rettv->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2557 rettv->vval.v_float = f1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2558 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2559 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2560 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2561 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2562 if (op == '+')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2563 n1 = n1 + n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2564 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2565 n1 = n1 - n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2566 rettv->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2567 rettv->vval.v_number = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2568 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2569 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2570 clear_tv(&var2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577 * Handle fifth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 * * number multiplication
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 * / number division
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580 * % number modulo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2587 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2588 eval6(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2589 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2590 typval_T *rettv,
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2591 evalarg_T *evalarg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2592 int want_string) // after "." operator
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2594 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2595 int op;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2596 varnumber_T n1, n2;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2597 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2598 int use_float = FALSE;
16405
840fa633ad64 patch 8.1.1207: some compilers give warning messages
Bram Moolenaar <Bram@vim.org>
parents: 16366
diff changeset
2599 float_T f1 = 0, f2 = 0;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2600 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2601 int error = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2606 if (eval7(arg, rettv, evalarg, want_string) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 * Repeat computing, until no '*', '/' or '%' is following.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2614 int evaluate = evalarg == NULL ? 0
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2615 : (evalarg->eval_flags & EVAL_EVALUATE);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2616 int getnext;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2617
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2618 op = *eval_next_non_blank(*arg, evalarg, &getnext);
17387
2558f90045e5 patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 17377
diff changeset
2619 if (op != '*' && op != '/' && op != '%')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 break;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2621 if (getnext)
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
2622 *arg = eval_next_line(evalarg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2623
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2624 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2626 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2627 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2628 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2629 f1 = rettv->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2630 use_float = TRUE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2631 n1 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2632 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2633 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2634 #endif
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2635 n1 = tv_get_number_chk(rettv, &error);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2636 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2637 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2638 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 n1 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2643 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 *arg = skipwhite(*arg + 1);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2647 if (eval7(arg, &var2, evalarg, FALSE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2650 if (evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2652 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2653 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2654 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2655 if (!use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2656 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2657 f1 = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2658 use_float = TRUE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2659 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2660 f2 = var2.vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2661 n2 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2662 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2663 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2664 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2665 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2666 n2 = tv_get_number_chk(&var2, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2667 clear_tv(&var2);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2668 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2669 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2670 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2671 if (use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2672 f2 = n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2673 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2674 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 * Compute the result.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2678 * When either side is a float the result is a float.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679 */
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2680 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2681 if (use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2682 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2683 if (op == '*')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2684 f1 = f1 * f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2685 else if (op == '/')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2686 {
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2687 # ifdef VMS
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2688 // 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
2689 if (f2 == 0.0)
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2690 {
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2691 if (f1 == 0)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2692 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
2693 else if (f1 < 0)
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
2694 f1 = -1 * __F_FLT_MAX;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2695 else
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
2696 f1 = __F_FLT_MAX;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2697 }
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2698 else
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2699 f1 = f1 / f2;
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2700 # else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2701 // 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
2702 // by zero to result in "inf" and not a crash.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2703 f1 = f1 / f2;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2704 # endif
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2705 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2706 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2707 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2708 emsg(_(e_modulus));
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2709 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2710 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2711 rettv->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2712 rettv->vval.v_float = f1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2713 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2714 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2715 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2716 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2717 if (op == '*')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2718 n1 = n1 * n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2719 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
2720 n1 = num_divide(n1, n2);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2721 else
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
2722 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
2723
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2724 rettv->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2725 rettv->vval.v_number = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2726 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 * Handle sixth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 * number number constant
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2736 * 0zFFFFFFFF Blob constant
1228
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1109
diff changeset
2737 * "string" string constant
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1109
diff changeset
2738 * 'string' literal string constant
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 * &option-name option value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 * @r register contents
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 * identifier variable value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 * function() function call
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 * $VAR environment variable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 * (expression) nested expression
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
2745 * [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
2746 * {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
2747 * {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
2748 * #{key: val, key: val} Dictionary with literal keys
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 * Also handle:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 * ! in front logical NOT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 * - in front unary minus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 * + in front unary plus (ignored)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2754 * trailing [] subscript in String or List
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2755 * 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
2756 * trailing ->name() method call
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2764 eval7(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2765 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2766 typval_T *rettv,
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2767 evalarg_T *evalarg,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2768 int want_string) // after "." operator
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 {
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2770 int flags = evalarg == NULL ? 0 : evalarg->eval_flags;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2771 int evaluate = evalarg != NULL
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2772 && (evalarg->eval_flags & EVAL_EVALUATE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 char_u *start_leader, *end_leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 int ret = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 char_u *alias;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 /*
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2780 * Initialise variable so that clear_tv() can't mistake this for a
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2781 * string and free a string that isn't there.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2783 rettv->v_type = VAR_UNKNOWN;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 /*
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 10000
diff changeset
2786 * Skip '!', '-' and '+' characters. They are handled later.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 start_leader = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 while (**arg == '!' || **arg == '-' || **arg == '+')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 *arg = skipwhite(*arg + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 end_leader = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2793 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
2794 #ifdef FEAT_FLOAT
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2795 || 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
2796 #endif
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2797 ))
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2798 {
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2799 semsg(_(e_invexpr2), *arg);
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2800 ++*arg;
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2801 return FAIL;
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2802 }
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2803
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 switch (**arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 * Number constant.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 case '0':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 case '1':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 case '2':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 case '3':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 case '4':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 case '5':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 case '6':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 case '7':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 case '8':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 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
2819 case '.': ret = get_number_tv(arg, rettv, evaluate, want_string);
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2820
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2821 // Apply prefixed "-" and "+" now. Matters especially when
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2822 // "->" follows.
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2823 if (ret == OK && evaluate && end_leader > start_leader)
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2824 ret = eval7_leader(rettv, TRUE, start_leader, &end_leader);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2825 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 * String constant: "string".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2830 case '"': ret = get_string_tv(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 /*
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2834 * Literal string constant: 'str''ing'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2836 case '\'': ret = get_lit_string_tv(arg, rettv, evaluate);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2837 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2838
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2839 /*
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2840 * List: [expr, expr]
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2841 */
21028
7acceb76669f patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents: 21026
diff changeset
2842 case '[': ret = get_list_tv(arg, rettv, evalarg, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 /*
17413
40417757dffd patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents: 17387
diff changeset
2846 * 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
2847 */
17413
40417757dffd patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents: 17387
diff changeset
2848 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
2849 {
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2850 ++*arg;
21034
2f8b0812819f patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents: 21032
diff changeset
2851 ret = eval_dict(arg, rettv, evalarg, TRUE);
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2852 }
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2853 else
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2854 ret = NOTDONE;
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2855 break;
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2856
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2857 /*
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9525
diff changeset
2858 * 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
2859 * Dictionary: {'key': val, 'key': val}
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2860 */
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2861 case '{': ret = get_lambda_tv(arg, rettv, evalarg);
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9525
diff changeset
2862 if (ret == NOTDONE)
21034
2f8b0812819f patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents: 21032
diff changeset
2863 ret = eval_dict(arg, rettv, evalarg, FALSE);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2864 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2865
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2866 /*
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2867 * Option value: &name
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 */
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2869 case '&': ret = get_option_tv(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 * Environment variable: $VAR.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2875 case '$': ret = get_env_tv(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 * Register contents: @r.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 case '@': ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2884 rettv->v_type = VAR_STRING;
5796
f084024c0ddb updated for version 7.4.242
Bram Moolenaar <bram@vim.org>
parents: 5794
diff changeset
2885 rettv->vval.v_string = get_reg_contents(**arg,
f084024c0ddb updated for version 7.4.242
Bram Moolenaar <bram@vim.org>
parents: 5794
diff changeset
2886 GREG_EXPR_SRC);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 if (**arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889 ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893 * nested expression: (expression).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894 */
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2895 case '(': {
21044
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2896 int getnext;
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2897
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2898 *arg = skipwhite(*arg + 1);
21044
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2899 eval_next_non_blank(*arg, evalarg, &getnext);
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2900 if (getnext)
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2901 *arg = eval_next_line(evalarg);
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2902
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2903 ret = eval1(arg, rettv, evalarg); // recursive!
21044
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2904
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2905 eval_next_non_blank(*arg, evalarg, &getnext);
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2906 if (getnext)
dc2ca403a217 patch 8.2.1073: Vim9: no line break allowed in () expression
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2907 *arg = eval_next_line(evalarg);
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2908 if (**arg == ')')
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2909 ++*arg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2910 else if (ret == OK)
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2911 {
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2912 emsg(_(e_missing_close));
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2913 clear_tv(rettv);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2914 ret = FAIL;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
2915 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2919 default: ret = NOTDONE;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2920 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2921 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2922
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2923 if (ret == NOTDONE)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2924 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2925 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2926 * Must be a variable or function name.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2927 * Can also be a curly-braces kind of name: {expr}.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2928 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2929 s = *arg;
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
2930 len = get_name_len(arg, &alias, evaluate, TRUE);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2931 if (alias != NULL)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2932 s = alias;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2933
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
2934 if (len <= 0)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2935 ret = FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2936 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2937 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2938 if (**arg == '(') // recursive!
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
2939 ret = eval_func(arg, s, len, rettv, flags, NULL);
20401
918b9a05cf35 patch 8.2.0755: Vim9: No error when variable initializer is not a constant
Bram Moolenaar <Bram@vim.org>
parents: 20397
diff changeset
2940 else if (flags & EVAL_CONSTANT)
918b9a05cf35 patch 8.2.0755: Vim9: No error when variable initializer is not a constant
Bram Moolenaar <Bram@vim.org>
parents: 20397
diff changeset
2941 ret = FAIL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2942 else if (evaluate)
6791
1805e45ce4d6 patch 7.4.717
Bram Moolenaar <bram@vim.org>
parents: 6773
diff changeset
2943 ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
2944 else
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
2945 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
2946 check_vars(s, len);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
2947 ret = OK;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
2948 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2949 }
2690
3ea3dcbf2cd6 updated for version 7.3.108
Bram Moolenaar <bram@vim.org>
parents: 2687
diff changeset
2950 vim_free(alias);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2951 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2952
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 *arg = skipwhite(*arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2955 // 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
2956 // expr(expr), expr->name(expr)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
2957 if (ret == OK)
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
2958 ret = handle_subscript(arg, rettv, evalarg, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 * Apply logical NOT and unary '-', from right to left, ignore '+'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 if (ret == OK && evaluate && end_leader > start_leader)
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2964 ret = eval7_leader(rettv, FALSE, start_leader, &end_leader);
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2965 return ret;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2966 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2967
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2968 /*
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2969 * Apply the leading "!" and "-" before an eval7 expression to "rettv".
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2970 * When "numeric_only" is TRUE only handle "+" and "-".
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2971 * 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
2972 */
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2973 static int
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2974 eval7_leader(
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2975 typval_T *rettv,
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2976 int numeric_only,
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2977 char_u *start_leader,
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
2978 char_u **end_leaderp)
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2979 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2980 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
2981 int ret = OK;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2982 int error = FALSE;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2983 varnumber_T val = 0;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2984 #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
2985 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
2986
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2987 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
2988 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
2989 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2990 #endif
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2991 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
2992 if (error)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2993 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2994 clear_tv(rettv);
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2995 ret = FAIL;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2996 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2997 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2998 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2999 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
3000 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3001 --end_leader;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3002 if (*end_leader == '!')
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3003 {
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3004 if (numeric_only)
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3005 {
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3006 ++end_leader;
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3007 break;
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
3008 }
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3009 #ifdef FEAT_FLOAT
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3010 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
3011 f = !f;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3012 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3013 #endif
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3014 val = !val;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3015 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3016 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
3017 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3018 #ifdef FEAT_FLOAT
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3019 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
3020 f = -f;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3021 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3022 #endif
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3023 val = -val;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3024 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3025 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3026 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3027 if (rettv->v_type == VAR_FLOAT)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3028 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3029 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
3030 rettv->vval.v_float = f;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3031 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3032 else
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3033 #endif
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3034 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3035 clear_tv(rettv);
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3036 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
3037 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
3038 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3039 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
3040 *end_leaderp = end_leader;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 /*
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3045 * 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
3046 */
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3047 static int
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3048 call_func_rettv(
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3049 char_u **arg,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3050 typval_T *rettv,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3051 int evaluate,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3052 dict_T *selfdict,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3053 typval_T *basetv)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3054 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3055 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
3056 funcexe_T funcexe;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3057 typval_T functv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3058 char_u *s;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3059 int ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3060
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3061 // 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
3062 if (evaluate)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3063 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3064 functv = *rettv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3065 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
3066
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3067 // 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
3068 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
3069 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3070 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
3071 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
3072 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3073 else
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3074 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
3075 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3076 else
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3077 s = (char_u *)"";
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3078
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
3079 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
3080 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
3081 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
3082 funcexe.evaluate = evaluate;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3083 funcexe.partial = pt;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3084 funcexe.selfdict = selfdict;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3085 funcexe.basetv = basetv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3086 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
3087
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3088 // 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
3089 // 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
3090 if (evaluate)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3091 clear_tv(&functv);
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3092
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3093 return ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3094 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3095
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3096 /*
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3097 * Evaluate "->method()".
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3098 * "*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
3099 * 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
3100 */
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3101 static int
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3102 eval_lambda(
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3103 char_u **arg,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3104 typval_T *rettv,
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3105 evalarg_T *evalarg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3106 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
3107 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3108 int evaluate = evalarg != NULL
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3109 && (evalarg->eval_flags & EVAL_EVALUATE);
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3110 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
3111 int ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3112
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3113 // Skip over the ->.
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3114 *arg += 2;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3115 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
3116
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3117 ret = get_lambda_tv(arg, rettv, evalarg);
18851
3cf9529b3a4a patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents: 18777
diff changeset
3118 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
3119 return FAIL;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3120 else if (**arg != '(')
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3121 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3122 if (verbose)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3123 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3124 if (*skipwhite(*arg) == '(')
19760
9daed26b788b patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents: 19568
diff changeset
3125 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
3126 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3127 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
3128 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3129 clear_tv(rettv);
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
3130 ret = FAIL;
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3131 }
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
3132 else
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
3133 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
3134
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
3135 // 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
3136 // 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
3137 if (evaluate)
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
3138 clear_tv(&base);
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
3139
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
3140 return ret;
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3141 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3142
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3143 /*
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3144 * Evaluate "->method()".
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3145 * "*arg" points to the '-'.
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3146 * 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
3147 */
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3148 static int
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3149 eval_method(
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3150 char_u **arg,
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3151 typval_T *rettv,
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3152 int evaluate,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3153 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
3154 {
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3155 char_u *name;
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3156 long len;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3157 char_u *alias;
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3158 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
3159 int ret;
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3160
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3161 // Skip over the ->.
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3162 *arg += 2;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3163 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
3164
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3165 name = *arg;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3166 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
3167 if (alias != NULL)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3168 name = alias;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3169
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3170 if (len <= 0)
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3171 {
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3172 if (verbose)
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3173 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
3174 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3175 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3176 else
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3177 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3178 if (**arg != '(')
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3179 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3180 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
3181 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
3182 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3183 }
17661
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
3184 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
3185 {
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
3186 if (verbose)
19760
9daed26b788b patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents: 19568
diff changeset
3187 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
3188 ret = FAIL;
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
3189 }
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3190 else
20397
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
3191 ret = eval_func(arg, name, len, rettv,
c225be44692a patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
3192 evaluate ? EVAL_EVALUATE : 0, &base);
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
3193 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3194
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
3195 // 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
3196 // 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
3197 if (evaluate)
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3198 clear_tv(&base);
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3199
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3200 return ret;
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3201 }
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3202
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3203 /*
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3204 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3205 * "*arg" points to the '[' or '.'.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3206 * Returns FAIL or OK. "*arg" is advanced to after the ']'.
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3207 */
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3208 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3209 eval_index(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3210 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3211 typval_T *rettv,
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3212 evalarg_T *evalarg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3213 int verbose) // give error messages
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3214 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3215 int evaluate = evalarg != NULL
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3216 && (evalarg->eval_flags & EVAL_EVALUATE);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3217 int empty1 = FALSE, empty2 = FALSE;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
3218 typval_T var1, var2;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3219 long i;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3220 long n1, n2 = 0;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3221 long len = -1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3222 int range = FALSE;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3223 char_u *s;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3224 char_u *key = NULL;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3225
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3226 switch (rettv->v_type)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3227 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3228 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
3229 case VAR_PARTIAL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3230 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3231 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
3232 return FAIL;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3233 case VAR_FLOAT:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3234 #ifdef FEAT_FLOAT
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3235 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3236 emsg(_(e_float_as_string));
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3237 return FAIL;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3238 #endif
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
3239 case VAR_BOOL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3240 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3241 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
3242 case VAR_CHANNEL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
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(_("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
3245 return FAIL;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3246 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
3247 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
3248 case VAR_VOID:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3249 if (evaluate)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3250 return FAIL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3251 // FALLTHROUGH
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3252
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3253 case VAR_STRING:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3254 case VAR_NUMBER:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3255 case VAR_LIST:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3256 case VAR_DICT:
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3257 case VAR_BLOB:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3258 break;
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3259 }
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3260
7046
fd409a0800fd commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents: 7042
diff changeset
3261 init_tv(&var1);
fd409a0800fd commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents: 7042
diff changeset
3262 init_tv(&var2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3263 if (**arg == '.')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3264 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3265 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3266 * dict.name
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3267 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3268 key = *arg + 1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3269 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3270 ;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3271 if (len == 0)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3272 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3273 *arg = skipwhite(key + len);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3274 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3275 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3276 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3277 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3278 * something[idx]
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3279 *
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3280 * Get the (first) variable from inside the [].
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3281 */
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3282 *arg = skipwhite(*arg + 1);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3283 if (**arg == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3284 empty1 = TRUE;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3285 else if (eval1(arg, &var1, evalarg) == FAIL) // recursive!
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3286 return FAIL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3287 else if (evaluate && tv_get_string_chk(&var1) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3288 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3289 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3290 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3291 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3292 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3293
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3294 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3295 * Get the second variable from inside the [:].
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3296 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3297 if (**arg == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3298 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3299 range = TRUE;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3300 *arg = skipwhite(*arg + 1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3301 if (**arg == ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3302 empty2 = TRUE;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
3303 else if (eval1(arg, &var2, evalarg) == FAIL) // recursive!
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3304 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3305 if (!empty1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3306 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3307 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3308 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3309 else if (evaluate && tv_get_string_chk(&var2) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3310 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3311 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3312 if (!empty1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3313 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3314 clear_tv(&var2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3315 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3316 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3317 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3318
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3319 // Check for the ']'.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3320 if (**arg != ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3321 {
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3322 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3323 emsg(_(e_missbrac));
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3324 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3325 if (range)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3326 clear_tv(&var2);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3327 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3328 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3329 *arg = skipwhite(*arg + 1); // skip the ']'
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3330 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3331
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3332 if (evaluate)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3333 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3334 n1 = 0;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3335 if (!empty1 && rettv->v_type != VAR_DICT)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3336 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3337 n1 = tv_get_number(&var1);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3338 clear_tv(&var1);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3339 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3340 if (range)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3341 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3342 if (empty2)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3343 n2 = -1;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3344 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3345 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3346 n2 = tv_get_number(&var2);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3347 clear_tv(&var2);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3348 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3349 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3350
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3351 switch (rettv->v_type)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3352 {
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3353 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
3354 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
3355 case VAR_VOID:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3356 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
3357 case VAR_PARTIAL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3358 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
3359 case VAR_BOOL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3360 case VAR_SPECIAL:
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3361 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
3362 case VAR_CHANNEL:
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3363 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
3364
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3365 case VAR_NUMBER:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3366 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
3367 s = tv_get_string(rettv);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3368 len = (long)STRLEN(s);
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3369 if (range)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3370 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3371 // 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
3372 // are out of range the result is empty.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3373 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3374 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3375 n1 = len + n1;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3376 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3377 n1 = 0;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3378 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3379 if (n2 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3380 n2 = len + n2;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3381 else if (n2 >= len)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3382 n2 = len;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3383 if (n1 >= len || n2 < 0 || n1 > n2)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3384 s = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3385 else
20751
d9a2e5dcfd9f patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20731
diff changeset
3386 s = vim_strnsave(s + n1, n2 - n1 + 1);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3387 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3388 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3389 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3390 // 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
3391 // 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
3392 // result is empty.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3393 if (n1 >= len || n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3394 s = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3395 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3396 s = vim_strnsave(s + n1, 1);
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3397 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3398 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3399 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3400 rettv->vval.v_string = s;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3401 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3402
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3403 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3404 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
3405 if (range)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3406 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
3407 // 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
3408 // 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
3409 if (n1 < 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3410 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3411 n1 = len + n1;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3412 if (n1 < 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3413 n1 = 0;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3414 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3415 if (n2 < 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3416 n2 = len + n2;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3417 else if (n2 >= len)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3418 n2 = len - 1;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3419 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
3420 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3421 clear_tv(rettv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3422 rettv->v_type = VAR_BLOB;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3423 rettv->vval.v_blob = NULL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3424 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3425 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3426 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3427 blob_T *blob = blob_alloc();
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3428
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3429 if (blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3430 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3431 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
3432 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3433 blob_free(blob);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3434 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3435 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3436 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
3437 for (i = n1; i <= n2; i++)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3438 blob_set(blob, i - n1,
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3439 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
3440
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3441 clear_tv(rettv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3442 rettv_blob_set(rettv, blob);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3443 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3444 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3445 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3446 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3447 {
15589
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
3448 // 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
3449 // 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
3450 if (n1 < 0)
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
3451 n1 = len + n1;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3452 if (n1 < len && n1 >= 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3453 {
15589
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
3454 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
3455
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3456 clear_tv(rettv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3457 rettv->v_type = VAR_NUMBER;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3458 rettv->vval.v_number = v;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3459 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3460 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3461 semsg(_(e_blobidx), n1);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3462 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3463 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3464
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3465 case VAR_LIST:
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3466 len = list_len(rettv->vval.v_list);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3467 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3468 n1 = len + n1;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3469 if (!empty1 && (n1 < 0 || n1 >= len))
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3470 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3471 // 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
3472 // list. A list index out of range is an error.
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3473 if (!range)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3474 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3475 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3476 semsg(_(e_listidx), n1);
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3477 return FAIL;
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3478 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3479 n1 = len;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3480 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3481 if (range)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3482 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
3483 list_T *l;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3484
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3485 if (n2 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3486 n2 = len + n2;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3487 else if (n2 >= len)
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3488 n2 = len - 1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3489 if (!empty2 && (n2 < 0 || n2 + 1 < n1))
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3490 n2 = -1;
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3491 l = list_slice(rettv->vval.v_list, n1, n2);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3492 if (l == NULL)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3493 return FAIL;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3494 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
3495 rettv_list_set(rettv, l);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3496 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3497 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3498 {
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3499 copy_tv(&list_find(rettv->vval.v_list, n1)->li_tv, &var1);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3500 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3501 *rettv = var1;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3502 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3503 break;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3504
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3505 case VAR_DICT:
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3506 if (range)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3507 {
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3508 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3509 emsg(_(e_dictrange));
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3510 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3511 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3512 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3513 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3514 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
3515 dictitem_T *item;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3516
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3517 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3518 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3519 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
3520 if (key == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3521 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3522 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3523 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3524 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3525 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3526
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
3527 item = dict_find(rettv->vval.v_dict, key, (int)len);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3528
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3529 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
3530 semsg(_(e_dictkey), key);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3531 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3532 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3533 if (item == NULL)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3534 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3535
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3536 copy_tv(&item->di_tv, &var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3537 clear_tv(rettv);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3538 *rettv = var1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3539 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3540 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3541 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3542 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3543
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3544 return OK;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3545 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3546
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3547 /*
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
3548 * 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
3549 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3550 char_u *
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3551 partial_name(partial_T *pt)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3552 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3553 if (pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3554 return pt->pt_name;
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
3555 if (pt->pt_func != NULL)
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
3556 return pt->pt_func->uf_name;
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
3557 return (char_u *)"";
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3558 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3559
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3560 static void
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3561 partial_free(partial_T *pt)
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3562 {
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3563 int i;
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3564
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3565 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
3566 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
3567 vim_free(pt->pt_argv);
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3568 dict_unref(pt->pt_dict);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3569 if (pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3570 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3571 func_unref(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3572 vim_free(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3573 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3574 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3575 func_ptr_unref(pt->pt_func);
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3576
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3577 if (pt->pt_funcstack != NULL)
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3578 {
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3579 // Decrease the reference count for the context of a closure. If down
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3580 // to zero free it and clear the variables on the stack.
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3581 if (--pt->pt_funcstack->fs_refcount == 0)
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3582 {
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3583 garray_T *gap = &pt->pt_funcstack->fs_ga;
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3584 typval_T *stack = gap->ga_data;
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3585
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3586 for (i = 0; i < gap->ga_len; ++i)
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3587 clear_tv(stack + i);
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3588 ga_clear(gap);
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3589 vim_free(pt->pt_funcstack);
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3590 }
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3591 pt->pt_funcstack = NULL;
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3592 }
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
3593
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3594 vim_free(pt);
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3595 }
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3596
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3597 /*
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3598 * 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
3599 * becomes zero.
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3600 */
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3601 void
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3602 partial_unref(partial_T *pt)
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3603 {
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3604 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
3605 partial_free(pt);
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3606 }
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3607
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3608 /*
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3609 * Return the next (unique) copy ID.
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3610 * Used for serializing nested structures.
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3611 */
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3612 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3613 get_copyID(void)
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3614 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3615 current_copyID += COPYID_INC;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3616 return current_copyID;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3617 }
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3618
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3619 /*
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3620 * Garbage collection for lists and dictionaries.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3621 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3622 * We use reference counts to be able to free most items right away when they
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3623 * are no longer used. But for composite items it's possible that it becomes
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3624 * unused while the reference count is > 0: When there is a recursive
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3625 * reference. Example:
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3626 * :let l = [1, 2, 3]
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3627 * :let d = {9: l}
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3628 * :let l[1] = d
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3629 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3630 * Since this is quite unusual we handle this with garbage collection: every
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3631 * once in a while find out which lists and dicts are not referenced from any
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3632 * variable.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3633 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3634 * Here is a good reference text about garbage collection (refers to Python
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3635 * but it applies to all reference-counting mechanisms):
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3636 * http://python.ca/nas/python/gc/
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3637 */
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3638
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3639 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3640 * 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
3641 * When "testing" is TRUE this is called from test_garbagecollect_now().
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3642 * Return TRUE if some memory was freed.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3643 */
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3644 int
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3645 garbage_collect(int testing)
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3646 {
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3647 int copyID;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3648 int abort = FALSE;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3649 buf_T *buf;
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3650 win_T *wp;
6588
1ffe91b5e514 updated for version 7.4.620
Bram Moolenaar <bram@vim.org>
parents: 6577
diff changeset
3651 int did_free = FALSE;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3652 tabpage_T *tp;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3653
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3654 if (!testing)
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3655 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3656 // Only do this once.
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3657 want_garbage_collect = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3658 may_garbage_collect = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3659 garbage_collect_at_exit = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3660 }
958
e88950f0d4f6 updated for version 7.0-084
vimboss
parents: 956
diff changeset
3661
19001
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3662 // 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
3663 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
3664 {
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3665 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
3666 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
3667 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
3668
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3669 // 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
3670 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
3671 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
3672 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
3673
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3674 // 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
3675 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
3676 {
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3677 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
3678 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
3679 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
3680 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
3681 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
3682 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
3683 }
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3684 }
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3685
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3686 // 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
3687 // previous_funccal.
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3688 copyID = get_copyID();
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3689
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3690 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3691 * 1. Go through all accessible variables and mark all lists and dicts
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3692 * with copyID.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3693 */
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3694
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3695 // 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
3696 // 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
3697 // 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
3698 abort = abort || set_ref_in_previous_funccal(copyID);
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3699
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3700 // 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
3701 abort = abort || garbage_collect_scriptvars(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3702
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3703 // buffer-local variables
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9636
diff changeset
3704 FOR_ALL_BUFFERS(buf)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3705 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3706 NULL, NULL);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3707
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3708 // window-local variables
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3709 FOR_ALL_TAB_WINDOWS(tp, wp)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3710 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3711 NULL, NULL);
4309
bdab73bf24a8 updated for version 7.3.904
Bram Moolenaar <bram@vim.org>
parents: 4297
diff changeset
3712 if (aucmd_win != NULL)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3713 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3714 NULL, NULL);
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
3715 #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
3716 FOR_ALL_POPUPWINS(wp)
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3717 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
3718 NULL, NULL);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3719 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
3720 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
3721 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
3722 NULL, NULL);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3723 #endif
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3724
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3725 // tabpage-local variables
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9636
diff changeset
3726 FOR_ALL_TABPAGES(tp)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3727 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3728 NULL, NULL);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3729 // 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
3730 abort = abort || garbage_collect_globvars(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3731
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3732 // function-local variables
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
3733 abort = abort || set_ref_in_call_stack(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3734
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3735 // named functions (matters for closures)
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
3736 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
3737
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3738 // 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
3739 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
3740
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3741 // 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
3742 abort = abort || garbage_collect_vimvars(copyID);
1733
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1730
diff changeset
3743
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
3744 // callbacks in buffers
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
3745 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
3746
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
3747 #ifdef FEAT_LUA
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3748 abort = abort || set_ref_in_lua(copyID);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
3749 #endif
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
3750
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
3751 #ifdef FEAT_PYTHON
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3752 abort = abort || set_ref_in_python(copyID);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
3753 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
3754
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
3755 #ifdef FEAT_PYTHON3
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3756 abort = abort || set_ref_in_python3(copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3757 #endif
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3758
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
3759 #ifdef FEAT_JOB_CHANNEL
8877
50e40f322e78 commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents: 8870
diff changeset
3760 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
3761 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
3762 #endif
9052
3a6b66c02d6d commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents: 9027
diff changeset
3763 #ifdef FEAT_NETBEANS_INTG
3a6b66c02d6d commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents: 9027
diff changeset
3764 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
3765 #endif
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7895
diff changeset
3766
9153
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
3767 #ifdef FEAT_TIMERS
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
3768 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
3769 #endif
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
3770
11412
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
3771 #ifdef FEAT_QUICKFIX
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
3772 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
3773 #endif
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
3774
11804
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
3775 #ifdef FEAT_TERMINAL
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
3776 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
3777 #endif
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
3778
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
3779 #ifdef FEAT_PROP_POPUP
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
3780 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
3781 #endif
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
3782
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3783 if (!abort)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3784 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3785 /*
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3786 * 2. Free lists and dictionaries that are not referenced.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3787 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3788 did_free = free_unref_items(copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3789
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3790 /*
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3791 * 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
3792 * This may call us back recursively.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3793 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
3794 free_unref_funccal(copyID, testing);
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3795 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3796 else if (p_verbose > 0)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3797 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
3798 verb_msg(_("Not enough memory to set references, garbage collection aborted!"));
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3799 }
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3800
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3801 return did_free;
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3802 }
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3803
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3804 /*
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3805 * Free lists, dictionaries, channels and jobs that are no longer referenced.
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3806 */
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3807 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3808 free_unref_items(int copyID)
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3809 {
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3810 int did_free = FALSE;
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3811
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3812 // 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
3813 // 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
3814 // do that here.
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3815 in_free_unref_items = TRUE;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3816
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3817 /*
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3818 * 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
3819 * 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
3820 */
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3821
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3822 // 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
3823 did_free |= dict_free_nonref(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3824
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3825 // 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
3826 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
3827
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3828 #ifdef FEAT_JOB_CHANNEL
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3829 // 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
3830 // 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
3831 // 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
3832 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
3833
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3834 // 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
3835 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
3836 #endif
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3837
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3838 /*
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3839 * PASS 2: free the items themselves.
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3840 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
3841 dict_free_items(copyID);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents: 9556
diff changeset
3842 list_free_items(copyID);
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3843
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3844 #ifdef FEAT_JOB_CHANNEL
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3845 // 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
3846 // 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
3847 // 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
3848 free_unused_jobs(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3849
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3850 // 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
3851 free_unused_channels(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3852 #endif
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3853
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3854 in_free_unref_items = FALSE;
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3855
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3856 return did_free;
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3857 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3858
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3859 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3860 * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3861 * "list_stack" is used to add lists to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3862 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3863 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3864 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3865 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3866 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack)
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
3867 {
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
3868 int todo;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3869 int abort = FALSE;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
3870 hashitem_T *hi;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3871 hashtab_T *cur_ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3872 ht_stack_T *ht_stack = NULL;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3873 ht_stack_T *tempitem;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3874
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3875 cur_ht = ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3876 for (;;)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3877 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3878 if (!abort)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3879 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3880 // 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
3881 // 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
3882 // list_stack.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3883 todo = (int)cur_ht->ht_used;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3884 for (hi = cur_ht->ht_array; todo > 0; ++hi)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3885 if (!HASHITEM_EMPTY(hi))
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3886 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3887 --todo;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3888 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3889 &ht_stack, list_stack);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3890 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3891 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3892
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3893 if (ht_stack == NULL)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3894 break;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3895
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3896 // take an item from the stack
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3897 cur_ht = ht_stack->ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3898 tempitem = ht_stack;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3899 ht_stack = ht_stack->prev;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3900 free(tempitem);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3901 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3902
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3903 return abort;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3904 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3905
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3906 /*
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3907 * 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
3908 * 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
3909 */
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3910 int
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3911 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
3912 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3913 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
3914 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3915 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
3916 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
3917 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3918 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
3919 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3920
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3921 /*
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3922 * 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
3923 * 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
3924 */
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3925 int
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3926 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
3927 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3928 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
3929 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3930 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
3931 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
3932 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3933 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
3934 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3935
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3936 /*
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3937 * Mark all lists and dicts referenced through list "l" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3938 * "ht_stack" is used to add hashtabs to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3939 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3940 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3941 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3942 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
3943 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3944 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3945 listitem_T *li;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3946 int abort = FALSE;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3947 list_T *cur_l;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3948 list_stack_T *list_stack = NULL;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3949 list_stack_T *tempitem;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3950
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3951 cur_l = l;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3952 for (;;)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3953 {
19201
e7b4fff348dd patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
3954 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
3955 // 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
3956 // 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
3957 // list_stack.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3958 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3959 abort = abort || set_ref_in_item(&li->li_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3960 ht_stack, &list_stack);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3961 if (list_stack == NULL)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3962 break;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3963
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3964 // take an item from the stack
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3965 cur_l = list_stack->list;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3966 tempitem = list_stack;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3967 list_stack = list_stack->prev;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3968 free(tempitem);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3969 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3970
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3971 return abort;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3972 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3973
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3974 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3975 * Mark all lists and dicts referenced through typval "tv" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3976 * "list_stack" is used to add lists to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3977 * "ht_stack" is used to add hashtabs to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3978 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3979 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3980 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3981 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3982 set_ref_in_item(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3983 typval_T *tv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3984 int copyID,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3985 ht_stack_T **ht_stack,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3986 list_stack_T **list_stack)
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
3987 {
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3988 int abort = FALSE;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
3989
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3990 if (tv->v_type == VAR_DICT)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3991 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3992 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
3993
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3994 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
3995 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3996 // 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
3997 dd->dv_copyID = copyID;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3998 if (ht_stack == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3999 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4000 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
4001 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4002 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4003 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4004 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
4005 if (newitem == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4006 abort = TRUE;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4007 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4008 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4009 newitem->ht = &dd->dv_hashtab;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4010 newitem->prev = *ht_stack;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4011 *ht_stack = newitem;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4012 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4013 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4014 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4015 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4016 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
4017 {
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4018 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
4019
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4020 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
4021 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4022 // 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
4023 ll->lv_copyID = copyID;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4024 if (list_stack == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4025 {
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4026 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
4027 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4028 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4029 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4030 list_stack_T *newitem = (list_stack_T*)malloc(
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4031 sizeof(list_stack_T));
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4032 if (newitem == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4033 abort = TRUE;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4034 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4035 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4036 newitem->list = ll;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4037 newitem->prev = *list_stack;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4038 *list_stack = newitem;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4039 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4040 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4041 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4042 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
4043 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
4044 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4045 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
4046 }
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4047 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
4048 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4049 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
4050 int i;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4051
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
4052 if (pt != NULL && pt->pt_copyID != copyID)
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4053 {
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
4054 // Didn't see this partial yet.
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
4055 pt->pt_copyID = copyID;
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20257
diff changeset
4056
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4057 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
4058
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4059 if (pt->pt_dict != NULL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4060 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4061 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4062
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4063 dtv.v_type = VAR_DICT;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4064 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
4065 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
4066 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4067
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4068 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
4069 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
4070 ht_stack, list_stack);
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4071 if (pt->pt_funcstack != NULL)
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4072 {
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4073 typval_T *stack = pt->pt_funcstack->fs_ga.ga_data;
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4074
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4075 for (i = 0; i < pt->pt_funcstack->fs_ga.ga_len; ++i)
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4076 abort = abort || set_ref_in_item(stack + i, copyID,
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4077 ht_stack, list_stack);
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4078 }
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
4079
8863
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 #ifdef FEAT_JOB_CHANNEL
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4083 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
4084 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4085 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
4086 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4087
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4088 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
4089 {
8870
30988ffb7498 commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
4090 job->jv_copyID = copyID;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4091 if (job->jv_channel != NULL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4092 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4093 dtv.v_type = VAR_CHANNEL;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4094 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
4095 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
4096 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4097 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
4098 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4099 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
4100 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
4101 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
4102 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4103 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4104 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4105 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
4106 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4107 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
4108 ch_part_T part;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4109 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4110 jsonq_T *jq;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4111 cbq_T *cq;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4112
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4113 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
4114 {
8870
30988ffb7498 commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
4115 ch->ch_copyID = copyID;
10259
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10235
diff changeset
4116 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
4117 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4118 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
4119 jq = jq->jq_next)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4120 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
4121 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
4122 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
4123 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
4124 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4125 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
4126 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
4127 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
4128 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4129 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
4130 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4131 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
4132 dtv.vval.v_partial =
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4133 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
4134 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
4135 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4136 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4137 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
4138 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4139 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
4140 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
4141 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
4142 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4143 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
4144 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4145 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
4146 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
4147 set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4148 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4149 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4150 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4151 #endif
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4152 return abort;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4153 }
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4154
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4155 /*
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4156 * Return a string with the string representation of a variable.
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4157 * If the memory is allocated "tofree" is set to it, otherwise NULL.
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
4158 * "numbuf" is used for a number.
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4159 * 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
4160 * 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
4161 * 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
4162 * ":echo" displays values.
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4163 * 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
4164 * are replaced with "...".
1360
8d09c1eed8a5 updated for version 7.1-074
vimboss
parents: 1341
diff changeset
4165 * May return NULL.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4166 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
4167 char_u *
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4168 echo_string_core(
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4169 typval_T *tv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4170 char_u **tofree,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4171 char_u *numbuf,
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4172 int copyID,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4173 int echo_style,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4174 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
4175 int composite_val)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4176 {
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4177 static int recurse = 0;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4178 char_u *r = NULL;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4179
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4180 if (recurse >= DICT_MAXNEST)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4181 {
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4182 if (!did_echo_string_emsg)
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4183 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4184 // 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
4185 // 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
4186 // and dicts.
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4187 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
4188 emsg(_("E724: variable nested too deep for displaying"));
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4189 }
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4190 *tofree = NULL;
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4191 return (char_u *)"{E724}";
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4192 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4193 ++recurse;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4194
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4195 switch (tv->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4196 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4197 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
4198 if (echo_style && !composite_val)
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4199 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4200 *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
4201 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
4202 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
4203 r = (char_u *)"";
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4204 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4205 else
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4206 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4207 *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
4208 r = *tofree;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4209 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4210 break;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4211
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4212 case VAR_FUNC:
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4213 if (echo_style)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4214 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4215 *tofree = NULL;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4216 r = tv->vval.v_string;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4217 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4218 else
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4219 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4220 *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
4221 r = *tofree;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4222 }
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4223 break;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4224
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
4225 case VAR_PARTIAL:
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4226 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4227 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
4228 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
4229 : partial_name(pt), FALSE);
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4230 garray_T ga;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4231 int i;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4232 char_u *tf;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4233
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4234 ga_init2(&ga, 1, 100);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4235 ga_concat(&ga, (char_u *)"function(");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4236 if (fname != NULL)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4237 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4238 ga_concat(&ga, fname);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4239 vim_free(fname);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4240 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4241 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
4242 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4243 ga_concat(&ga, (char_u *)", [");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4244 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
4245 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4246 if (i > 0)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4247 ga_concat(&ga, (char_u *)", ");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4248 ga_concat(&ga,
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4249 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
4250 vim_free(tf);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4251 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4252 ga_concat(&ga, (char_u *)"]");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4253 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4254 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
4255 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4256 typval_T dtv;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4257
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4258 ga_concat(&ga, (char_u *)", ");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4259 dtv.v_type = VAR_DICT;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4260 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
4261 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
4262 vim_free(tf);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4263 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4264 ga_concat(&ga, (char_u *)")");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4265
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4266 *tofree = ga.ga_data;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4267 r = *tofree;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4268 break;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4269 }
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
4270
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
4271 case VAR_BLOB:
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15464
diff changeset
4272 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
4273 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
4274
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4275 case VAR_LIST:
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4276 if (tv->vval.v_list == NULL)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4277 {
20126
831b1ea43020 patch 8.2.0618: echoing a null list results in no output
Bram Moolenaar <Bram@vim.org>
parents: 20111
diff changeset
4278 // NULL list is equivalent to empty list.
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4279 *tofree = NULL;
20126
831b1ea43020 patch 8.2.0618: echoing a null list results in no output
Bram Moolenaar <Bram@vim.org>
parents: 20111
diff changeset
4280 r = (char_u *)"[]";
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4281 }
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4282 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
4283 && tv->vval.v_list->lv_len > 0)
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4284 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4285 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4286 r = (char_u *)"[...]";
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4287 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4288 else
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4289 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4290 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
4291
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4292 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
4293 *tofree = list2string(tv, copyID, restore_copyID);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4294 if (restore_copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4295 tv->vval.v_list->lv_copyID = old_copyID;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4296 r = *tofree;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4297 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4298 break;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4299
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4300 case VAR_DICT:
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4301 if (tv->vval.v_dict == NULL)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4302 {
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
4303 // NULL dict is equivalent to empty dict.
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4304 *tofree = NULL;
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
4305 r = (char_u *)"{}";
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4306 }
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4307 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
4308 && tv->vval.v_dict->dv_hashtab.ht_used != 0)
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4309 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4310 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4311 r = (char_u *)"{...}";
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4312 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4313 else
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4314 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4315 int old_copyID = tv->vval.v_dict->dv_copyID;
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20126
diff changeset
4316
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4317 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
4318 *tofree = dict2string(tv, copyID, restore_copyID);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4319 if (restore_copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4320 tv->vval.v_dict->dv_copyID = old_copyID;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4321 r = *tofree;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4322 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4323 break;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4324
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4325 case VAR_NUMBER:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4326 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
4327 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
4328 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
4329 *tofree = NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
4330 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
4331 break;
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
4332
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
4333 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
4334 case VAR_CHANNEL:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4335 *tofree = NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
4336 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
4337 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
4338 {
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
4339 *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
4340 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
4341 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4342 break;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4343
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4344 case VAR_FLOAT:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
4345 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4346 *tofree = NULL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4347 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4348 r = numbuf;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4349 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4350 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4351
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
4352 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4353 case VAR_SPECIAL:
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4354 *tofree = NULL;
7730
80ce794827c4 commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents: 7720
diff changeset
4355 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
4356 break;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4357 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4358
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4359 if (--recurse == 0)
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4360 did_echo_string_emsg = FALSE;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4361 return r;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4362 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4363
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4364 /*
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4365 * Return a string with the string representation of a variable.
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4366 * If the memory is allocated "tofree" is set to it, otherwise NULL.
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4367 * "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
4368 * 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
4369 * 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
4370 * May return NULL.
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4371 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4372 char_u *
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4373 echo_string(
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4374 typval_T *tv,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4375 char_u **tofree,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4376 char_u *numbuf,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4377 int copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4378 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4379 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
4380 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4381
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4382 /*
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4383 * Return string "str" in ' quotes, doubling ' characters.
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4384 * If "str" is NULL an empty string is assumed.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4385 * If "function" is TRUE make it function('string').
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4386 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
4387 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4388 string_quote(char_u *str, int function)
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4389 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4390 unsigned len;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4391 char_u *p, *r, *s;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4392
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4393 len = (function ? 13 : 3);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4394 if (str != NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4395 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 833
diff changeset
4396 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
4397 for (p = str; *p != NUL; MB_PTR_ADV(p))
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4398 if (*p == '\'')
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4399 ++len;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4400 }
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4401 s = r = alloc(len);
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4402 if (r != NULL)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4403 {
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4404 if (function)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4405 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4406 STRCPY(r, "function('");
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4407 r += 10;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4408 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4409 else
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4410 *r++ = '\'';
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4411 if (str != NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4412 for (p = str; *p != NUL; )
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4413 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4414 if (*p == '\'')
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4415 *r++ = '\'';
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4416 MB_COPY_CHAR(p, r);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4417 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4418 *r++ = '\'';
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4419 if (function)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4420 *r++ = ')';
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4421 *r++ = NUL;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4422 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4423 return s;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4424 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4425
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4426 #if defined(FEAT_FLOAT) || defined(PROTO)
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4427 /*
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4428 * Convert the string "text" to a floating point number.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4429 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4430 * this always uses a decimal point.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4431 * Returns the length of the text that was consumed.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4432 */
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4433 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4434 string2float(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4435 char_u *text,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4436 float_T *value) // result stored here
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4437 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4438 char *s = (char *)text;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4439 float_T f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4440
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4441 // 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
4442 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
4443 {
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4444 *value = INFINITY;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4445 return 3;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4446 }
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4447 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
4448 {
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4449 *value = -INFINITY;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4450 return 4;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4451 }
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4452 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
4453 {
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4454 *value = NAN;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4455 return 3;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4456 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4457 f = strtod(s, &s);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4458 *value = f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4459 return (int)((char_u *)s - text);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4460 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4461 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4462
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4463 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4464 * Translate a String variable into a position.
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4465 * Returns NULL when there is an error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4466 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
4467 pos_T *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4468 var2fpos(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4469 typval_T *varp,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4470 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
4471 int *fnum) // set to fnum for '0, 'A, etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4472 {
700
c78d973dce9e updated for version 7.0211
vimboss
parents: 697
diff changeset
4473 char_u *name;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4474 static pos_T pos;
700
c78d973dce9e updated for version 7.0211
vimboss
parents: 697
diff changeset
4475 pos_T *pp;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4476
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4477 // Argument can be [lnum, col, coladd].
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4478 if (varp->v_type == VAR_LIST)
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4479 {
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4480 list_T *l;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4481 int len;
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4482 int error = FALSE;
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4483 listitem_T *li;
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4484
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4485 l = varp->vval.v_list;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4486 if (l == NULL)
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4487 return NULL;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4488
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4489 // Get the line number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4490 pos.lnum = list_find_nr(l, 0L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4491 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
4492 return NULL; // invalid line number
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4493
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4494 // Get the column number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4495 pos.col = list_find_nr(l, 1L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4496 if (error)
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4497 return NULL;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4498 len = (long)STRLEN(ml_get(pos.lnum));
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4499
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4500 // We accept "$" for the column number: last column.
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4501 li = list_find(l, 1L);
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4502 if (li != NULL && li->li_tv.v_type == VAR_STRING
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4503 && li->li_tv.vval.v_string != NULL
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4504 && STRCMP(li->li_tv.vval.v_string, "$") == 0)
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4505 pos.col = len + 1;
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4506
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4507 // Accept a position up to the NUL after the line.
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
4508 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
4509 return NULL; // invalid column number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4510 --pos.col;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4511
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4512 // Get the virtual offset. Defaults to zero.
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4513 pos.coladd = list_find_nr(l, 2L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4514 if (error)
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4515 pos.coladd = 0;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4516
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4517 return &pos;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4518 }
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4519
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
4520 name = tv_get_string_chk(varp);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4521 if (name == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4522 return NULL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4523 if (name[0] == '.') // cursor
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4524 return &curwin->w_cursor;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4525 if (name[0] == 'v' && name[1] == NUL) // Visual start
1609
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4526 {
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4527 if (VIsual_active)
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4528 return &VIsual;
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4529 return &curwin->w_cursor;
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4530 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4531 if (name[0] == '\'') // mark
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4532 {
4043
80b041b994d1 updated for version 7.3.776
Bram Moolenaar <bram@vim.org>
parents: 3986
diff changeset
4533 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4534 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4535 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4536 return pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 }
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4538
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4539 pos.coladd = 0;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4540
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4541 if (name[0] == 'w' && dollar_lnum)
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4542 {
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4543 pos.col = 0;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4544 if (name[1] == '0') // "w0": first visible line
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4545 {
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
4546 update_topline();
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4547 // 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
4548 // 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
4549 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1;
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4550 return &pos;
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4551 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4552 else if (name[1] == '$') // "w$": last visible line
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4553 {
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
4554 validate_botline();
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4555 // 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
4556 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0;
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4557 return &pos;
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4558 }
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4559 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4560 else if (name[0] == '$') // last column or line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4561 {
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4562 if (dollar_lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4563 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4564 pos.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4565 pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4566 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4567 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4569 pos.lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4570 pos.col = (colnr_T)STRLEN(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4572 return &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4574 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4577 /*
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4578 * Convert list in "arg" into a position and optional file number.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4579 * When "fnump" is NULL there is no file number, only 3 items.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4580 * Note that the column is passed on as-is, the caller may want to decrement
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4581 * it to use 1 for the first column.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4582 * Return FAIL when conversion is not possible, doesn't check the position for
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4583 * validity.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4584 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
4585 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4586 list2fpos(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4587 typval_T *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4588 pos_T *posp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4589 int *fnump,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4590 colnr_T *curswantp)
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4591 {
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4592 list_T *l = arg->vval.v_list;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4593 long i = 0;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4594 long n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4595
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4596 // 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
4597 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional.
915
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4598 if (arg->v_type != VAR_LIST
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4599 || l == NULL
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4600 || l->lv_len < (fnump == NULL ? 2 : 3)
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
4601 || l->lv_len > (fnump == NULL ? 4 : 5))
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4602 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4603
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4604 if (fnump != NULL)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4605 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4606 n = list_find_nr(l, i++, NULL); // fnum
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4607 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4608 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4609 if (n == 0)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4610 n = curbuf->b_fnum; // current buffer
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4611 *fnump = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4612 }
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4613
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4614 n = list_find_nr(l, i++, NULL); // lnum
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4615 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4616 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4617 posp->lnum = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4618
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4619 n = list_find_nr(l, i++, NULL); // col
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4620 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4621 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4622 posp->col = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4623
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4624 n = list_find_nr(l, i, NULL); // off
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4625 if (n < 0)
915
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4626 posp->coladd = 0;
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4627 else
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4628 posp->coladd = n;
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4629
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
4630 if (curswantp != NULL)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4631 *curswantp = list_find_nr(l, i + 1, NULL); // curswant
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
4632
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4633 return OK;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4634 }
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4635
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4636 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4637 * Get the length of an environment variable name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4638 * Advance "arg" to the first character after the name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4639 * Return 0 for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4640 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
4641 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4642 get_env_len(char_u **arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4643 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4644 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4645 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4647 for (p = *arg; vim_isIDc(*p); ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4648 ;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4649 if (p == *arg) // no name found
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4650 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4651
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4652 len = (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4653 *arg = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4654 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4656
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4657 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4658 * Get the length of the name of a function or internal variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4659 * "arg" is advanced to the first non-white character after the name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4660 * Return 0 if something is wrong.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4661 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4662 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4663 get_id_len(char_u **arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4664 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4665 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4666 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4667
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4668 // Find the end of the name.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4669 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
4670 {
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4671 if (*p == ':')
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4672 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4673 // "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
4674 // 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
4675 len = (int)(p - *arg);
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4676 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
4677 || len > 1)
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4678 break;
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4679 }
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4680 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4681 if (p == *arg) // no name found
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4684 len = (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4685 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4687 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4688 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4690 /*
124
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
4691 * Get the length of the name of a variable or function.
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
4692 * Only the name is recognized, does not handle ".key" or "[idx]".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4693 * "arg" is advanced to the first non-white character after the name.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4694 * Return -1 if curly braces expansion failed.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4695 * Return 0 if something else is wrong.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4696 * If the name contains 'magic' {}'s, expand them and return the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4697 * expanded name in an allocated string via 'alias' - caller must free.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4698 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
4699 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4700 get_name_len(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4701 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4702 char_u **alias,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4703 int evaluate,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4704 int verbose)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4705 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4706 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4707 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4708 char_u *expr_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4709 char_u *expr_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4710
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4711 *alias = NULL; // default to no alias
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4712
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4713 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4714 && (*arg)[2] == (int)KE_SNR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4715 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4716 // hard coded <SNR>, already translated
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4717 *arg += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4718 return get_id_len(arg) + 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4719 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4720 len = eval_fname_script(*arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4721 if (len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4722 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4723 // literal "<SID>", "s:" or "<SNR>"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4724 *arg += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4725 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4727 /*
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4728 * Find the end of the name; check for {} construction.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4729 */
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4730 p = find_name_end(*arg, &expr_start, &expr_end,
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4731 len > 0 ? 0 : FNE_CHECK_START);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 if (expr_start != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4733 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4734 char_u *temp_string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4736 if (!evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4737 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4738 len += (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4739 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4741 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4742
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4743 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4744 * Include any <SID> etc in the expanded string:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4745 * Thus the -len here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4746 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4747 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4748 if (temp_string == NULL)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4749 return -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4750 *alias = temp_string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4751 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4752 return (int)STRLEN(temp_string);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4753 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4755 len += get_id_len(arg);
15464
3faa7cc8207c patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 15460
diff changeset
4756 // 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
4757 // reported at a higher level.
3faa7cc8207c patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 15460
diff changeset
4758 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
4759 semsg(_(e_invexpr2), *arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4760
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4761 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4762 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4763
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4764 /*
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4765 * Find the end of a variable or function name, taking care of magic braces.
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4766 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4767 * start and end of the first magic braces item.
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4768 * "flags" can have FNE_INCL_BR and FNE_CHECK_START.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4769 * Return a pointer to just after the name. Equal to "arg" if there is no
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4770 * valid name.
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4771 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4772 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4773 find_name_end(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4774 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4775 char_u **expr_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4776 char_u **expr_end,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4777 int flags)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4778 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4779 int mb_nest = 0;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4780 int br_nest = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 char_u *p;
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4782 int len;
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20061
diff changeset
4783 int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4784
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4785 if (expr_start != NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4786 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4787 *expr_start = NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4788 *expr_end = NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4789 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4790
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4791 // 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
4792 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
4793 && (*arg != '{' || vim9script))
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4794 return arg;
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4795
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4796 for (p = arg; *p != NUL
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4797 && (eval_isnamec(*p)
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20061
diff changeset
4798 || (*p == '{' && !vim9script)
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4799 || ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.'))
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4800 || mb_nest != 0
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
4801 || br_nest != 0); MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4802 {
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4803 if (*p == '\'')
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4804 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4805 // 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
4806 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4807 ;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4808 if (*p == NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4809 break;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4810 }
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4811 else if (*p == '"')
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4812 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4813 // 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
4814 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4815 if (*p == '\\' && p[1] != NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4816 ++p;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4817 if (*p == NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4818 break;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4819 }
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4820 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
4821 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4822 // "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
4823 // 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
4824 len = (int)(p - arg);
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4825 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
4826 || (len > 1 && p[-1] != '}'))
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4827 break;
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4828 }
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4829
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4830 if (mb_nest == 0)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4831 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4832 if (*p == '[')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4833 ++br_nest;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4834 else if (*p == ']')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4835 --br_nest;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4836 }
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
4837
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20061
diff changeset
4838 if (br_nest == 0 && !vim9script)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4839 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4840 if (*p == '{')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4841 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4842 mb_nest++;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4843 if (expr_start != NULL && *expr_start == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4844 *expr_start = p;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4845 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4846 else if (*p == '}')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4847 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4848 mb_nest--;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4849 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4850 *expr_end = p;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4851 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4852 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4853 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4854
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4855 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4857
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4858 /*
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4859 * Expands out the 'magic' {}'s in a variable/function name.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4860 * Note that this can call itself recursively, to deal with
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4861 * constructs like foo{bar}{baz}{bam}
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4862 * The four pointer arguments point to "foo{expre}ss{ion}bar"
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4863 * "in_start" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4864 * "expr_start" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4865 * "expr_end" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4866 * "in_end" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4867 *
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4868 * Returns a new allocated string, which the caller must free.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4869 * Returns NULL for failure.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4870 */
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4871 static char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4872 make_expanded_name(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4873 char_u *in_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4874 char_u *expr_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4875 char_u *expr_end,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4876 char_u *in_end)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4877 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4878 char_u c1;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4879 char_u *retval = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4880 char_u *temp_result;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4881
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4882 if (expr_end == NULL || in_end == NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4883 return NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4884 *expr_start = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4885 *expr_end = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4886 c1 = *in_end;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4887 *in_end = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4888
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
4889 temp_result = eval_to_string(expr_start + 1, FALSE);
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20992
diff changeset
4890 if (temp_result != NULL)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4891 {
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
4892 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
4893 + (in_end - expr_end) + 1);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4894 if (retval != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4895 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4896 STRCPY(retval, in_start);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4897 STRCAT(retval, temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4898 STRCAT(retval, expr_end + 1);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4899 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4900 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4901 vim_free(temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4902
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4903 *in_end = c1; // put char back for error messages
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4904 *expr_start = '{';
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4905 *expr_end = '}';
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4906
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4907 if (retval != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4908 {
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4909 temp_result = find_name_end(retval, &expr_start, &expr_end, 0);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4910 if (expr_start != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4911 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4912 // Further expansion!
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4913 temp_result = make_expanded_name(retval, expr_start,
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4914 expr_end, temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4915 vim_free(retval);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4916 retval = temp_result;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4917 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4918 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4919
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4920 return retval;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4921 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4922
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4923 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4924 * Return TRUE if character "c" can be used in a variable or function name.
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4925 * Does not include '{' or '}' for magic braces.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4926 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4927 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4928 eval_isnamec(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929 {
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4930 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR);
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4931 }
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4932
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4933 /*
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4934 * Return TRUE if character "c" can be used as the first character in a
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4935 * variable or function name (excluding '{' and '}').
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4936 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4937 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4938 eval_isnamec1(int c)
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4939 {
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
4940 return (ASCII_ISALPHA(c) || c == '_');
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4941 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4942
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4943 /*
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4944 * Handle:
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4945 * - 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
4946 * - ".name" lookup
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4947 * - 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
4948 * - method call: var->method()
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4949 *
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4950 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len()
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4951 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4952 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4953 handle_subscript(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4954 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4955 typval_T *rettv,
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4956 evalarg_T *evalarg,
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 21028
diff changeset
4957 int verbose) // give error messages
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4958 {
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4959 int evaluate = evalarg != NULL
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4960 && (evalarg->eval_flags & EVAL_EVALUATE);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4961 int ret = OK;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4962 dict_T *selfdict = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4963
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
4964 // "." 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
4965 // scriptversion is at least 2, where string concatenation is "..".
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4966 while (ret == OK
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4967 && (((**arg == '['
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4968 || (**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
4969 || (!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
4970 && (*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
4971 && 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
4972 || (**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
4973 || 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
4974 && !VIM_ISWHITE(*(*arg - 1)))
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4975 || (**arg == '-' && (*arg)[1] == '>')))
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4976 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4977 if (**arg == '(')
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4978 {
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4979 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
4980
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
4981 // 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
4982 // 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
4983 // but not caught.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4984 if (aborting())
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4985 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4986 if (ret == OK)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4987 clear_tv(rettv);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4988 ret = FAIL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4989 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4990 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4991 selfdict = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
4992 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4993 else if (**arg == '-')
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
4994 {
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
4995 if (ret == OK)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
4996 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
4997 if ((*arg)[2] == '{')
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
4998 // expr->{lambda}()
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
4999 ret = eval_lambda(arg, rettv, evalarg, verbose);
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5000 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5001 // expr->name()
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5002 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
5003 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5004 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5005 else // **arg == '[' || **arg == '.'
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5006 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5007 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5008 if (rettv->v_type == VAR_DICT)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5009 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5010 selfdict = rettv->vval.v_dict;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5011 if (selfdict != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5012 ++selfdict->dv_refcount;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5013 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5014 else
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5015 selfdict = NULL;
21040
d9e0db9b2b99 patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 21034
diff changeset
5016 if (eval_index(arg, rettv, evalarg, verbose) == FAIL)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5017 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5018 clear_tv(rettv);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5019 ret = FAIL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5020 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5021 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5022 }
8575
b5209a4e5baf commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
5023
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5024 // 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
5025 // 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
5026 // explicitly (pt_auto is FALSE).
9104
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5027 if (selfdict != NULL
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5028 && (rettv->v_type == VAR_FUNC
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5029 || (rettv->v_type == VAR_PARTIAL
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5030 && (rettv->vval.v_partial->pt_auto
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5031 || 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
5032 selfdict = make_partial(selfdict, rettv);
8575
b5209a4e5baf commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
5033
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5034 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5035 return ret;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5036 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5037
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5038 /*
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5039 * Make a copy of an item.
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5040 * Lists and Dictionaries are also copied. A deep copy if "deep" is set.
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5041 * For deepcopy() "copyID" is zero for a full copy or the ID for when a
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5042 * reference to an already copied list/dict can be used.
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5043 * Returns FAIL or OK.
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5044 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
5045 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5046 item_copy(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5047 typval_T *from,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5048 typval_T *to,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5049 int deep,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5050 int copyID)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5051 {
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5052 static int recurse = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5053 int ret = OK;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5054
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5055 if (recurse >= DICT_MAXNEST)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5056 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5057 emsg(_("E698: variable nested too deep for making a copy"));
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5058 return FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5059 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5060 ++recurse;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5061
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5062 switch (from->v_type)
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5063 {
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5064 case VAR_NUMBER:
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5065 case VAR_FLOAT:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5066 case VAR_STRING:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5067 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5068 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
5069 case VAR_BOOL:
7862
d4fec9208e7e commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents: 7856
diff changeset
5070 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5071 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5072 case VAR_CHANNEL:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5073 copy_tv(from, to);
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5074 break;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5075 case VAR_LIST:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5076 to->v_type = VAR_LIST;
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
5077 to->v_lock = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5078 if (from->vval.v_list == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5079 to->vval.v_list = NULL;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5080 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5081 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5082 // use the copy made earlier
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5083 to->vval.v_list = from->vval.v_list->lv_copylist;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5084 ++to->vval.v_list->lv_refcount;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5085 }
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5086 else
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5087 to->vval.v_list = list_copy(from->vval.v_list, deep, copyID);
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5088 if (to->vval.v_list == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5089 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5090 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
5091 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
5092 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
5093 break;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5094 case VAR_DICT:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5095 to->v_type = VAR_DICT;
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
5096 to->v_lock = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5097 if (from->vval.v_dict == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5098 to->vval.v_dict = NULL;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5099 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5100 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5101 // use the copy made earlier
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5102 to->vval.v_dict = from->vval.v_dict->dv_copydict;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5103 ++to->vval.v_dict->dv_refcount;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5104 }
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5105 else
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5106 to->vval.v_dict = dict_copy(from->vval.v_dict, deep, copyID);
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5107 if (to->vval.v_dict == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5108 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5109 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5110 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
5111 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
5112 case VAR_VOID:
19554
b38d73f36467 patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
5113 internal_error_no_abort("item_copy(UNKNOWN)");
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5114 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5115 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5116 --recurse;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5117 return ret;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5118 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5119
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5120 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5121 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
5122 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5123 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
5124 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
5125 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
5126
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5127 if (*atstart)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5128 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5129 *atstart = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5130 // 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
5131 // 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
5132 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
5133 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5134 // 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
5135 // 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
5136 // 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
5137 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
5138 msg_start();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5139 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5140 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5141 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
5142 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
5143
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5144 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
5145 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
5146 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5147 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
5148 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5149 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
5150 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5151 // 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
5152 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
5153 *needclr = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5154 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5155 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
5156 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5157 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5158 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5159 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
5160 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5161 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
5162
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5163 (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
5164 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
5165 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5166 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5167 (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
5168 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5169 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5170 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
5171 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5172
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5173 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174 * ":echo expr1 ..." print each argument separated with a space, add a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5175 * newline at the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5176 * ":echon expr1 ..." print each argument plain.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5177 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5178 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5179 ex_echo(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5180 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 char_u *arg = eap->arg;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5182 typval_T rettv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5183 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184 int needclr = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5185 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
5186 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
5187 int called_emsg_before = called_emsg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
5188 evalarg_T evalarg;
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
5189
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
5190 CLEAR_FIELD(evalarg);
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
5191 evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5193 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5194 ++emsg_skip;
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
5195 while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5196 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5197 // 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
5198 // still need to be cleared. E.g., "echo 22,44".
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5199 need_clr_eos = needclr;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5200
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 p = arg;
20992
7ee565134d4a patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
5202 if (eval1(&arg, &rettv, &evalarg) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205 * Report the invalid expression unless the expression evaluation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5206 * has been cancelled due to an aborting error, an interrupt, or an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5207 * exception.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5208 */
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5209 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
5210 && 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
5211 semsg(_(e_invexpr2), p);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5212 need_clr_eos = FALSE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5213 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5214 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5215 need_clr_eos = FALSE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5216
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5217 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
5218 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
5219
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5220 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5221 arg = skipwhite(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5223 eap->nextcmd = check_nextcmd(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5225 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5227 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5229 // remove text that may still be there from the command
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 if (needclr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5231 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232 if (eap->cmdidx == CMD_echo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5233 msg_end();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5238 * ":echohl {name}".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5239 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5240 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5241 ex_echohl(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5242 {
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
5243 echo_attr = syn_name2attr(eap->arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246 /*
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
5247 * 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
5248 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
5249 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
5250 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
5251 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
5252 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
5253 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
5254
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
5255 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 * ":execute expr1 ..." execute the result of an expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 * ":echomsg expr1 ..." Print a message
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 * ":echoerr expr1 ..." Print an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 * Each gets spaces around each argument and a newline at the end for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 * echo commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5263 ex_execute(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5265 char_u *arg = eap->arg;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5266 typval_T rettv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5267 int ret = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5268 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5269 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 ga_init2(&ga, 1, 80);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5274 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5275 ++emsg_skip;
20061
6e6a75800884 patch 8.2.0586: Vim9: # comment not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20059
diff changeset
5276 while (!ends_excmd2(eap->cmd, arg) || *arg == '"')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5277 {
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
5278 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
5279 if (ret == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5280 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 if (!eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5283 {
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5284 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
5285
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5286 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
5287 {
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
5288 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
5289 {
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
5290 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
5291 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
5292 }
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
5293 else
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
5294 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
5295 }
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5296 else
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5297 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
5298 if (p == NULL)
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
5299 {
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
5300 clear_tv(&rettv);
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
5301 ret = FAIL;
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
5302 break;
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
5303 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304 len = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 if (ga_grow(&ga, len + 2) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5307 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5311 if (ga.ga_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5312 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314 ga.ga_len += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5317 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 arg = skipwhite(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 if (ret != FAIL && ga.ga_data != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322 {
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
5323 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
5324 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5325 // 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
5326 // 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
5327 // 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
5328 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
5329 }
404e98047f0b patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
5330
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 if (eap->cmdidx == CMD_echomsg)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
5332 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
5333 msg_attr(ga.ga_data, echo_attr);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
5334 out_flush();
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
5335 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 else if (eap->cmdidx == CMD_echoerr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 {
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
5338 int save_did_emsg = did_emsg;
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
5339
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5340 // We don't want to abort following commands, restore did_emsg.
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5341 emsg(ga.ga_data);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 if (!force_abort)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 did_emsg = save_did_emsg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 else if (eap->cmdidx == CMD_execute)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 do_cmdline((char_u *)ga.ga_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 ga_clear(&ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 eap->nextcmd = check_nextcmd(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 * Skip over the name of an option: "&option", "&g:option" or "&l:option".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 * "arg" points to the "&" or '+' when called, to "option" when returning.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 * Returns NULL when no option name found. Otherwise pointer to the char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 * after the option name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
5364 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5365 find_option_end(char_u **arg, int *opt_flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 char_u *p = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 if (*p == 'g' && p[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 *opt_flags = OPT_GLOBAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 else if (*p == 'l' && p[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377 *opt_flags = OPT_LOCAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381 *opt_flags = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383 if (!ASCII_ISALPHA(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385 *arg = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 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
5388 p += 4; // termcap option
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 while (ASCII_ISALPHA(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395 /*
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5396 * Display script name where an item was last set.
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5397 * Should only be invoked when 'verbose' is non-zero.
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5398 */
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5399 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
5400 last_set_msg(sctx_T script_ctx)
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5401 {
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
5402 char_u *p;
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
5403
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
5404 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
5405 {
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
5406 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid));
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
5407 if (p != NULL)
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
5408 {
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
5409 verbose_enter();
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
5410 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
5411 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
5412 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
5413 {
18939
25ebc35e104f patch 8.2.0030: "gF" does not work on output of "verbose command"
Bram Moolenaar <Bram@vim.org>
parents: 18851
diff changeset
5414 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
5415 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
5416 }
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
5417 verbose_leave();
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
5418 vim_free(p);
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
5419 }
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5420 }
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5421 }
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
5422
17966
46f95606b9ec patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
5423 #endif // FEAT_EVAL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 * 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
5427 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 * "flags" can be "g" to do a global substitute.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 * Returns an allocated string, NULL for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5432 do_string_sub(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5433 char_u *str,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5434 char_u *pat,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5435 char_u *sub,
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
5436 typval_T *expr,
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5437 char_u *flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5439 int sublen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5440 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5441 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 int do_all;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 char_u *tail;
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
5444 char_u *end;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 char_u *save_cpo;
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5448 char_u *zero_width = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5450 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 save_cpo = p_cpo;
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
5452 p_cpo = empty_option;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 ga_init2(&ga, 1, 200);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 do_all = (flags[0] == 'g');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5457
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 regmatch.rm_ic = p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460 if (regmatch.regprog != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462 tail = str;
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
5463 end = str + STRLEN(str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5466 // Skip empty match except for first match.
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5467 if (regmatch.startp[0] == regmatch.endp[0])
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5468 {
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5469 if (zero_width == regmatch.startp[0])
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5470 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5471 // 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
5472 i = mb_ptr2len(tail);
5964
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
5473 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail,
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
5474 (size_t)i);
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
5475 ga.ga_len += i;
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
5476 tail += i;
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5477 continue;
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5478 }
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5479 zero_width = regmatch.startp[0];
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5480 }
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
5481
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 * Get some space for a temporary buffer to do the substitution
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 * into. It will contain:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 * - The text up to where the match is.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 * - The substituted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487 * - The text after the match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 */
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
5489 sublen = vim_regsub(&regmatch, sub, expr, tail, FALSE, TRUE, FALSE);
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
5490 if (ga_grow(&ga, (int)((end - tail) + sublen -
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 ga_clear(&ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5497 // copy the text up to where the match is
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 i = (int)(regmatch.startp[0] - tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 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
5500 // add the substituted text
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
5501 (void)vim_regsub(&regmatch, sub, expr, (char_u *)ga.ga_data
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 + ga.ga_len + i, TRUE, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 ga.ga_len += i + sublen - 1;
5388
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
5504 tail = regmatch.endp[0];
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
5505 if (*tail == NUL)
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
5506 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 if (!do_all)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 if (ga.ga_data != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512 STRCPY((char *)ga.ga_data + ga.ga_len, tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4778
diff changeset
5514 vim_regfree(regmatch.regprog);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 ga_clear(&ga);
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
5519 if (p_cpo == empty_option)
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
5520 p_cpo = save_cpo;
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
5521 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5522 // Darn, evaluating {sub} expression or {expr} changed the value.
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
5523 free_string_option(save_cpo);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 }