annotate src/typval.c @ 35142:21ff041be690 default tip

Added tag v9.1.0400 for changeset 920e132817da6c07f2c7bc4bff9e0441db4de0ee
author Christian Brabandt <cb@256bit.org>
date Thu, 09 May 2024 09:30:08 +0200
parents 5b25ec43f208
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * typval.c: functions that deal with a typval
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * Allocate memory for a variable type-value, and make it empty (0 or NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * value).
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 typval_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 alloc_tv(void)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 return ALLOC_CLEAR_ONE(typval_T);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 * Allocate memory for a variable type-value, and assign a string to it.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 * The string "s" must have been allocated, it is consumed.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 * Return NULL for out of memory, the variable otherwise.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 typval_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 alloc_string_tv(char_u *s)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 typval_T *rettv;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 rettv = alloc_tv();
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 rettv->vval.v_string = s;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 vim_free(s);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 return rettv;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 * Free the memory for a variable type-value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 free_tv(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 {
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
55 if (varp == NULL)
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
56 return;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
57
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
58 switch (varp->v_type)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 {
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
60 case VAR_FUNC:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
61 func_unref(varp->vval.v_string);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
62 // FALLTHROUGH
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
63 case VAR_STRING:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
64 vim_free(varp->vval.v_string);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
65 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
66 case VAR_PARTIAL:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
67 partial_unref(varp->vval.v_partial);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
68 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
69 case VAR_BLOB:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
70 blob_unref(varp->vval.v_blob);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
71 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
72 case VAR_LIST:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
73 list_unref(varp->vval.v_list);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
74 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
75 case VAR_DICT:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
76 dict_unref(varp->vval.v_dict);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
77 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
78 case VAR_JOB:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 #ifdef FEAT_JOB_CHANNEL
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
80 job_unref(varp->vval.v_job);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
81 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 #endif
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
83 case VAR_CHANNEL:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 #ifdef FEAT_JOB_CHANNEL
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
85 channel_unref(varp->vval.v_channel);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
86 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 #endif
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
88 case VAR_CLASS:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
89 class_unref(varp->vval.v_class);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
90 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
91 case VAR_OBJECT:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
92 object_unref(varp->vval.v_object);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
93 break;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
94
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
95 case VAR_TYPEALIAS:
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
96 typealias_unref(varp->vval.v_typealias);
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
97 break;
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
98
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
99 case VAR_NUMBER:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
100 case VAR_FLOAT:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
101 case VAR_ANY:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
102 case VAR_UNKNOWN:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
103 case VAR_VOID:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
104 case VAR_BOOL:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
105 case VAR_SPECIAL:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
106 case VAR_INSTR:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
107 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 }
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
109 vim_free(varp);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 * Free the memory for a variable value and set the value to NULL or 0.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 clear_tv(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 {
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
118 if (varp == NULL)
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
119 return;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
120
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
121 switch (varp->v_type)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 {
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
123 case VAR_FUNC:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
124 func_unref(varp->vval.v_string);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
125 // FALLTHROUGH
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
126 case VAR_STRING:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
127 VIM_CLEAR(varp->vval.v_string);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
128 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
129 case VAR_PARTIAL:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
130 partial_unref(varp->vval.v_partial);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
131 varp->vval.v_partial = NULL;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
132 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
133 case VAR_BLOB:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
134 blob_unref(varp->vval.v_blob);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
135 varp->vval.v_blob = NULL;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
136 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
137 case VAR_LIST:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
138 list_unref(varp->vval.v_list);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
139 varp->vval.v_list = NULL;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
140 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
141 case VAR_DICT:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
142 dict_unref(varp->vval.v_dict);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
143 varp->vval.v_dict = NULL;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
144 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
145 case VAR_NUMBER:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
146 case VAR_BOOL:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
147 case VAR_SPECIAL:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
148 varp->vval.v_number = 0;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
149 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
150 case VAR_FLOAT:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
151 varp->vval.v_float = 0.0;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
152 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
153 case VAR_JOB:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 #ifdef FEAT_JOB_CHANNEL
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
155 job_unref(varp->vval.v_job);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
156 varp->vval.v_job = NULL;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 #endif
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
158 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
159 case VAR_CHANNEL:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 #ifdef FEAT_JOB_CHANNEL
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
161 channel_unref(varp->vval.v_channel);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
162 varp->vval.v_channel = NULL;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 #endif
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
164 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
165 case VAR_INSTR:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
166 VIM_CLEAR(varp->vval.v_instr);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
167 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
168 case VAR_CLASS:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
169 class_unref(varp->vval.v_class);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
170 varp->vval.v_class = NULL;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
171 break;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
172 case VAR_OBJECT:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
173 object_unref(varp->vval.v_object);
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
174 varp->vval.v_object = NULL;
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
175 break;
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
176 case VAR_TYPEALIAS:
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
177 typealias_unref(varp->vval.v_typealias);
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
178 varp->vval.v_typealias = NULL;
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
179 break;
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
180 case VAR_UNKNOWN:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
181 case VAR_ANY:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
182 case VAR_VOID:
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
183 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 }
31825
0d27ddce621d patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
185 varp->v_lock = 0;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 * Set the value of a variable to NULL without freeing items.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 init_tv(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 if (varp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 CLEAR_POINTER(varp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
198 static varnumber_T
32130
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
199 tv_get_bool_or_number_chk(
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
200 typval_T *varp,
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
201 int *denote,
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
202 int want_bool,
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
203 int vim9_string_error) // in Vim9 using a string is an error
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 varnumber_T n = 0L;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 case VAR_NUMBER:
22405
0ef3ae4ec70e patch 8.2.1751: using 2 where bool is expected may throw an error
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
210 if (in_vim9script() && want_bool && varp->vval.v_number != 0
21913
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
211 && varp->vval.v_number != 1)
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
212 {
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
213 semsg(_(e_using_number_as_bool_nr), varp->vval.v_number);
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
214 break;
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
215 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 return varp->vval.v_number;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 case VAR_FLOAT:
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
218 emsg(_(e_using_float_as_number));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 case VAR_PARTIAL:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
222 emsg(_(e_using_funcref_as_number));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 case VAR_STRING:
32130
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
225 if (vim9_string_error && in_vim9script())
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
226 {
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22405
diff changeset
227 emsg_using_string_as(varp, !want_bool);
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
228 break;
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
229 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 if (varp->vval.v_string != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 vim_str2nr(varp->vval.v_string, NULL, NULL,
32098
39f4126d2a0d patch 9.0.1380: CTRL-X on 2**64 subtracts two
Bram Moolenaar <Bram@vim.org>
parents: 31825
diff changeset
232 STR2NR_ALL, &n, NULL, 0, FALSE, NULL);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 return n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 case VAR_LIST:
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
235 emsg(_(e_using_list_as_number));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 case VAR_DICT:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
238 emsg(_(e_using_dictionary_as_number));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 case VAR_SPECIAL:
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
242 if (!want_bool && in_vim9script())
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
243 {
22930
84567584951f patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
244 if (varp->v_type == VAR_BOOL)
84567584951f patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
245 emsg(_(e_using_bool_as_number));
84567584951f patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
246 else
26948
51ddf6740ac6 patch 8.2.4003: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26913
diff changeset
247 emsg(_(e_using_special_as_number));
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
248 break;
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
249 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 return varp->vval.v_number == VVAL_TRUE ? 1 : 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 #ifdef FEAT_JOB_CHANNEL
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
253 emsg(_(e_using_job_as_number));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 #ifdef FEAT_JOB_CHANNEL
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
258 emsg(_(e_using_channel_as_number));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 case VAR_BLOB:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
262 emsg(_(e_using_blob_as_number));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 break;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
264 case VAR_CLASS:
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
265 case VAR_TYPEALIAS:
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
266 check_typval_is_value(varp);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
267 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
268 case VAR_OBJECT:
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
269 {
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
270 class_T *cl = varp->vval.v_object->obj_class;
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
271 if (cl != NULL && IS_ENUM(cl))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
272 semsg(_(e_using_enum_str_as_number), cl->class_name);
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
273 else
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
274 emsg(_(e_using_object_as_number));
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
275 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
276 break;
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
277 case VAR_VOID:
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
278 emsg(_(e_cannot_use_void_value));
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
279 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 case VAR_ANY:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
282 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 internal_error_no_abort("tv_get_number(UNKNOWN)");
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 if (denote == NULL) // useful for values that must be unsigned
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 n = -1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 *denote = TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 return n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
293 /*
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
294 * Get the number value of a variable.
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
295 * If it is a String variable, uses vim_str2nr().
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
296 * For incompatible types, return 0.
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
297 * tv_get_number_chk() is similar to tv_get_number(), but informs the
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
298 * caller of incompatible types: it sets *denote to TRUE if "denote"
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
299 * is not NULL or returns -1 otherwise.
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
300 */
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
301 varnumber_T
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
302 tv_get_number(typval_T *varp)
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
303 {
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
304 int error = FALSE;
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
305
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
306 return tv_get_number_chk(varp, &error); // return 0L on error
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
307 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
308
32130
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
309 /*
33223
def9fc5c92d1 patch 9.0.1886: Various Typos
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
310 * Like tv_get_number() but in Vim9 script do convert a number in a string to a
32130
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
311 * number without giving an error.
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
312 */
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
313 varnumber_T
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
314 tv_to_number(typval_T *varp)
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
315 {
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
316 int error = FALSE;
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
317
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
318 return tv_get_bool_or_number_chk(varp, &error, FALSE, FALSE);
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
319 }
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
320
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
321 varnumber_T
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
322 tv_get_number_chk(typval_T *varp, int *denote)
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
323 {
32130
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
324 return tv_get_bool_or_number_chk(varp, denote, FALSE, TRUE);
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
325 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
326
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
327 /*
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
328 * Get the boolean value of "varp". This is like tv_get_number_chk(),
21913
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
329 * but in Vim9 script accepts Number (0 and 1) and Bool/Special.
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
330 */
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
331 varnumber_T
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
332 tv_get_bool(typval_T *varp)
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
333 {
32130
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
334 return tv_get_bool_or_number_chk(varp, NULL, TRUE, TRUE);
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
335 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
336
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
337 /*
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
338 * Get the boolean value of "varp". This is like tv_get_number_chk(),
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
339 * but in Vim9 script accepts Number and Bool.
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
340 */
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
341 varnumber_T
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
342 tv_get_bool_chk(typval_T *varp, int *denote)
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
343 {
32130
ec0d5bd9083c patch 9.0.1396: sort(list, 'N') does not work in Vim9 script context
Bram Moolenaar <Bram@vim.org>
parents: 32098
diff changeset
344 return tv_get_bool_or_number_chk(varp, denote, TRUE, TRUE);
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
345 }
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
346
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
347 static float_T
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
348 tv_get_float_chk(typval_T *varp, int *error)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 return (float_T)(varp->vval.v_number);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 return varp->vval.v_float;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 case VAR_PARTIAL:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
358 emsg(_(e_using_funcref_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 case VAR_STRING:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
361 emsg(_(e_using_string_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 case VAR_LIST:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
364 emsg(_(e_using_list_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 case VAR_DICT:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
367 emsg(_(e_using_dictionary_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 case VAR_BOOL:
27034
b31cc7630773 patch 8.2.4046: some error messages not in the right place
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
370 emsg(_(e_using_boolean_value_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 case VAR_SPECIAL:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
373 emsg(_(e_using_special_value_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 # ifdef FEAT_JOB_CHANNEL
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
377 emsg(_(e_using_job_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 # endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 # ifdef FEAT_JOB_CHANNEL
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
382 emsg(_(e_using_channel_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 # endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 case VAR_BLOB:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
386 emsg(_(e_using_blob_as_float));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 break;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
388 case VAR_CLASS:
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
389 case VAR_TYPEALIAS:
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
390 check_typval_is_value(varp);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
391 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
392 case VAR_OBJECT:
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
393 emsg(_(e_using_object_as_float));
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
394 break;
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
395 case VAR_VOID:
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
396 emsg(_(e_cannot_use_void_value));
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
397 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 case VAR_ANY:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
400 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 internal_error_no_abort("tv_get_float(UNKNOWN)");
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 }
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
404 if (error != NULL)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
405 *error = TRUE;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 return 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 }
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
408
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
409 float_T
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
410 tv_get_float(typval_T *varp)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
411 {
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
412 return tv_get_float_chk(varp, NULL);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
413 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 /*
28674
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
416 * Give an error and return FAIL unless "args[idx]" is unknown
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
417 */
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
418 int
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
419 check_for_unknown_arg(typval_T *args, int idx)
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
420 {
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
421 if (args[idx].v_type != VAR_UNKNOWN)
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
422 {
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
423 semsg(_(e_too_many_arguments), idx + 1);
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
424 return FAIL;
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
425 }
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
426 return OK;
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
427 }
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
428
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
429 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
430 * Give an error and return FAIL unless "args[idx]" is a string.
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
431 */
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
432 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
433 check_for_string_arg(typval_T *args, int idx)
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
434 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
435 if (args[idx].v_type != VAR_STRING)
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
436 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
437 semsg(_(e_string_required_for_argument_nr), idx + 1);
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
438 return FAIL;
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
439 }
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
440 return OK;
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
441 }
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
442
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
443 /*
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
444 * Give an error and return FAIL unless "args[idx]" is a non-empty string.
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
445 */
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
446 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
447 check_for_nonempty_string_arg(typval_T *args, int idx)
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
448 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
449 if (check_for_string_arg(args, idx) == FAIL)
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
450 return FAIL;
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
451 if (args[idx].vval.v_string == NULL || *args[idx].vval.v_string == NUL)
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
452 {
24424
ddcda424f882 patch 8.2.2752
Bram Moolenaar <Bram@vim.org>
parents: 24260
diff changeset
453 semsg(_(e_non_empty_string_required_for_argument_nr), idx + 1);
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
454 return FAIL;
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
455 }
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
456 return OK;
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
457 }
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
458
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
459 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
460 * Check for an optional string argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
461 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
462 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
463 check_for_opt_string_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
464 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
465 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
466 || check_for_string_arg(args, idx) != FAIL) ? OK : FAIL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
467 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
468
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
469 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
470 * Give an error and return FAIL unless "args[idx]" is a number.
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
471 */
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
472 int
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
473 check_for_number_arg(typval_T *args, int idx)
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
474 {
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
475 if (args[idx].v_type != VAR_NUMBER)
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
476 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
477 semsg(_(e_number_required_for_argument_nr), idx + 1);
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
478 return FAIL;
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
479 }
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
480 return OK;
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
481 }
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
482
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
483 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
484 * Check for an optional number argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
485 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
486 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
487 check_for_opt_number_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
488 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
489 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
490 || check_for_number_arg(args, idx) != FAIL) ? OK : FAIL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
491 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
492
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
493 /*
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
494 * Give an error and return FAIL unless "args[idx]" is a float or a number.
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
495 */
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
496 int
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
497 check_for_float_or_nr_arg(typval_T *args, int idx)
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
498 {
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
499 if (args[idx].v_type != VAR_FLOAT && args[idx].v_type != VAR_NUMBER)
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
500 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
501 semsg(_(e_float_or_number_required_for_argument_nr), idx + 1);
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
502 return FAIL;
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
503 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
504 return OK;
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
505 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
506
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
507 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
508 * Give an error and return FAIL unless "args[idx]" is a bool.
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
509 */
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
510 int
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
511 check_for_bool_arg(typval_T *args, int idx)
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
512 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
513 if (args[idx].v_type != VAR_BOOL
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
514 && !(args[idx].v_type == VAR_NUMBER
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
515 && (args[idx].vval.v_number == 0
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
516 || args[idx].vval.v_number == 1)))
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
517 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
518 semsg(_(e_bool_required_for_argument_nr), idx + 1);
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
519 return FAIL;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
520 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
521 return OK;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
522 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
523
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
524 /*
25802
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
525 * Check for an optional bool argument at 'idx'.
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
526 * Return FAIL if the type is wrong.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
527 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
528 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
529 check_for_opt_bool_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
530 {
25802
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
531 if (args[idx].v_type == VAR_UNKNOWN)
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
532 return OK;
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
533 return check_for_bool_arg(args, idx);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
534 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
535
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
536 /*
25806
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
537 * Give an error and return FAIL unless "args[idx]" is a blob.
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
538 */
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
539 int
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
540 check_for_blob_arg(typval_T *args, int idx)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
541 {
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
542 if (args[idx].v_type != VAR_BLOB)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
543 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
544 semsg(_(e_blob_required_for_argument_nr), idx + 1);
25806
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
545 return FAIL;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
546 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
547 return OK;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
548 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
549
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
550 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
551 * Give an error and return FAIL unless "args[idx]" is a list.
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
552 */
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
553 int
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
554 check_for_list_arg(typval_T *args, int idx)
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
555 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
556 if (args[idx].v_type != VAR_LIST)
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
557 {
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
558 semsg(_(e_list_required_for_argument_nr), idx + 1);
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
559 return FAIL;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
560 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
561 return OK;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
562 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
563
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
564 /*
30015
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
565 * Give an error and return FAIL unless "args[idx]" is a non-NULL list.
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
566 */
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
567 int
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
568 check_for_nonnull_list_arg(typval_T *args, int idx)
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
569 {
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
570 if (check_for_list_arg(args, idx) == FAIL)
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
571 return FAIL;
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
572
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
573 if (args[idx].vval.v_list == NULL)
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
574 {
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
575 semsg(_(e_non_null_list_required_for_argument_nr), idx + 1);
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
576 return FAIL;
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
577 }
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
578 return OK;
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
579 }
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
580
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
581 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
582 * Check for an optional list argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
583 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
584 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
585 check_for_opt_list_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
586 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
587 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
588 || check_for_list_arg(args, idx) != FAIL) ? OK : FAIL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
589 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
590
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
591 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
592 * Give an error and return FAIL unless "args[idx]" is a dict.
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
593 */
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
594 int
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
595 check_for_dict_arg(typval_T *args, int idx)
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
596 {
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
597 if (args[idx].v_type != VAR_DICT)
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
598 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
599 semsg(_(e_dict_required_for_argument_nr), idx + 1);
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
600 return FAIL;
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
601 }
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
602 return OK;
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
603 }
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
604
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
605 /*
29994
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
606 * Give an error and return FAIL unless "args[idx]" is a non-NULL dict.
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
607 */
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
608 int
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
609 check_for_nonnull_dict_arg(typval_T *args, int idx)
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
610 {
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
611 if (check_for_dict_arg(args, idx) == FAIL)
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
612 return FAIL;
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
613
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
614 if (args[idx].vval.v_dict == NULL)
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
615 {
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
616 semsg(_(e_non_null_dict_required_for_argument_nr), idx + 1);
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
617 return FAIL;
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
618 }
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
619 return OK;
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
620 }
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
621
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
622 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
623 * Check for an optional dict argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
624 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
625 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
626 check_for_opt_dict_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
627 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
628 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
629 || check_for_dict_arg(args, idx) != FAIL) ? OK : FAIL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
630 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
631
34264
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
632 /*
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
633 * Check for an optional non-NULL dict argument at 'idx'
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
634 */
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
635 int
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
636 check_for_opt_nonnull_dict_arg(typval_T *args, int idx)
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
637 {
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
638 return (args[idx].v_type == VAR_UNKNOWN
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
639 || check_for_nonnull_dict_arg(args, idx) != FAIL) ? OK : FAIL;
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
640 }
cce6b834635c patch 9.1.0071: Need a diff() Vim script function
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
641
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
642 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
643 /*
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
644 * Give an error and return FAIL unless "args[idx]" is a channel or a job.
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
645 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
646 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
647 check_for_chan_or_job_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
648 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
649 if (args[idx].v_type != VAR_CHANNEL && args[idx].v_type != VAR_JOB)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
650 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
651 semsg(_(e_chan_or_job_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
652 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
653 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
654 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
655 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
656
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
657 /*
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
658 * Give an error and return FAIL unless "args[idx]" is an optional channel or a
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
659 * job.
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
660 */
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
661 int
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
662 check_for_opt_chan_or_job_arg(typval_T *args, int idx)
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
663 {
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
664 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
665 || check_for_chan_or_job_arg(args, idx) != FAIL) ? OK : FAIL;
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
666 }
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
667
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
668 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
669 * Give an error and return FAIL unless "args[idx]" is a job.
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
670 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
671 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
672 check_for_job_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
673 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
674 if (args[idx].v_type != VAR_JOB)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
675 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
676 semsg(_(e_job_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
677 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
678 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
679 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
680 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
681
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
682 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
683 * Check for an optional job argument at 'idx'.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
684 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
685 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
686 check_for_opt_job_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
687 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
688 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
689 || check_for_job_arg(args, idx) != FAIL) ? OK : FAIL;
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
690 }
31289
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
691 #else
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
692 /*
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
693 * Give an error and return FAIL unless "args[idx]" is an optional channel or a
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
694 * job. Used without the +channel feature, thus only VAR_UNKNOWN is accepted.
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
695 */
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
696 int
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
697 check_for_opt_chan_or_job_arg(typval_T *args, int idx)
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
698 {
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
699 return args[idx].v_type == VAR_UNKNOWN ? OK : FAIL;
4f1e70a709bb patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
700 }
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
701 #endif
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
702
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
703 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
704 * Give an error and return FAIL unless "args[idx]" is a string or
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
705 * a number.
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
706 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
707 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
708 check_for_string_or_number_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
709 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
710 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
711 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
712 semsg(_(e_string_or_number_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
713 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
714 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
715 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
716 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
717
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
718 /*
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
719 * Check for an optional string or number argument at 'idx'.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
720 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
721 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
722 check_for_opt_string_or_number_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
723 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
724 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
725 || check_for_string_or_number_arg(args, idx) != FAIL) ? OK : FAIL;
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
726 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
727
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
728 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
729 * Give an error and return FAIL unless "args[idx]" is a buffer number.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
730 * Buffer number can be a number or a string.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
731 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
732 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
733 check_for_buffer_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
734 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
735 return check_for_string_or_number_arg(args, idx);
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
736 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
737
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
738 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
739 * Check for an optional buffer argument at 'idx'
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
740 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
741 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
742 check_for_opt_buffer_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
743 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
744 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
745 || check_for_buffer_arg(args, idx) != FAIL) ? OK : FAIL;
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
746 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
747
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
748 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
749 * Give an error and return FAIL unless "args[idx]" is a line number.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
750 * Line number can be a number or a string.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
751 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
752 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
753 check_for_lnum_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
754 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
755 return check_for_string_or_number_arg(args, idx);
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
756 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
757
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
758 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
759 * Check for an optional line number argument at 'idx'
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
760 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
761 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
762 check_for_opt_lnum_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
763 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
764 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
765 || check_for_lnum_arg(args, idx) != FAIL) ? OK : FAIL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
766 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
767
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
768 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
769 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
770 * Give an error and return FAIL unless "args[idx]" is a string or a blob.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
771 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
772 int
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
773 check_for_string_or_blob_arg(typval_T *args, int idx)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
774 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
775 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
776 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
777 semsg(_(e_string_or_blob_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
778 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
779 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
780 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
781 }
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
782 #endif
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
783
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
784 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
785 * Give an error and return FAIL unless "args[idx]" is a string or a list.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
786 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
787 int
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
788 check_for_string_or_list_arg(typval_T *args, int idx)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
789 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
790 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
791 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
792 semsg(_(e_string_or_list_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
793 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
794 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
795 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
796 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
797
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
798 /*
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
799 * Give an error and return FAIL unless "args[idx]" is a string, a list or a
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
800 * blob.
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
801 */
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
802 int
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
803 check_for_string_or_list_or_blob_arg(typval_T *args, int idx)
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
804 {
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
805 if (args[idx].v_type != VAR_STRING
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
806 && args[idx].v_type != VAR_LIST
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
807 && args[idx].v_type != VAR_BLOB)
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
808 {
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
809 semsg(_(e_string_list_or_blob_required_for_argument_nr), idx + 1);
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
810 return FAIL;
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
811 }
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
812 return OK;
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
813 }
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
814
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
815 /*
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
816 * Check for an optional string or list argument at 'idx'
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
817 */
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
818 int
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
819 check_for_opt_string_or_list_arg(typval_T *args, int idx)
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
820 {
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
821 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
822 || check_for_string_or_list_arg(args, idx) != FAIL) ? OK : FAIL;
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
823 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
824
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
825 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
826 * Give an error and return FAIL unless "args[idx]" is a string or a dict.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
827 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
828 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
829 check_for_string_or_dict_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
830 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
831 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_DICT)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
832 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
833 semsg(_(e_string_or_dict_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
834 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
835 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
836 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
837 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
838
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
839 /*
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
840 * Give an error and return FAIL unless "args[idx]" is a string or a number
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
841 * or a list.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
842 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
843 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
844 check_for_string_or_number_or_list_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
845 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
846 if (args[idx].v_type != VAR_STRING
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
847 && args[idx].v_type != VAR_NUMBER
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
848 && args[idx].v_type != VAR_LIST)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
849 {
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
850 semsg(_(e_string_number_or_list_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
851 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
852 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
853 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
854 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
855
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
856 /*
25390
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
857 * Give an error and return FAIL unless "args[idx]" is an optional string
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
858 * or number or a list
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
859 */
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
860 int
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
861 check_for_opt_string_or_number_or_list_arg(typval_T *args, int idx)
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
862 {
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
863 return (args[idx].v_type == VAR_UNKNOWN
30228
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
864 || check_for_string_or_number_or_list_arg(args, idx)
642b5e748028 patch 9.0.0450: return value of argument check functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 30188
diff changeset
865 != FAIL) ? OK : FAIL;
25390
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
866 }
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
867
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
868 /*
30188
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
869 * Give an error and return FAIL unless "args[idx]" is a string or a number
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
870 * or a list or a blob.
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
871 */
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
872 int
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
873 check_for_string_or_number_or_list_or_blob_arg(typval_T *args, int idx)
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
874 {
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
875 if (args[idx].v_type != VAR_STRING
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
876 && args[idx].v_type != VAR_NUMBER
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
877 && args[idx].v_type != VAR_LIST
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
878 && args[idx].v_type != VAR_BLOB)
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
879 {
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
880 semsg(_(e_string_number_list_or_blob_required_for_argument_nr), idx + 1);
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
881 return FAIL;
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
882 }
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
883 return OK;
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
884 }
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
885
ba22d5536d3e patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
886 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
887 * Give an error and return FAIL unless "args[idx]" is a string or a list
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
888 * or a dict.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
889 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
890 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
891 check_for_string_or_list_or_dict_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
892 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
893 if (args[idx].v_type != VAR_STRING
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
894 && args[idx].v_type != VAR_LIST
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
895 && args[idx].v_type != VAR_DICT)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
896 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
897 semsg(_(e_string_list_or_dict_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
898 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
899 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
900 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
901 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
902
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
903 /*
26731
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
904 * Give an error and return FAIL unless "args[idx]" is a string
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
905 * or a function reference.
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
906 */
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
907 int
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
908 check_for_string_or_func_arg(typval_T *args, int idx)
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
909 {
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
910 if (args[idx].v_type != VAR_PARTIAL
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
911 && args[idx].v_type != VAR_FUNC
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
912 && args[idx].v_type != VAR_STRING)
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
913 {
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
914 semsg(_(e_string_or_function_required_for_argument_nr), idx + 1);
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
915 return FAIL;
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
916 }
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
917 return OK;
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
918 }
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
919
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
920 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
921 * Give an error and return FAIL unless "args[idx]" is a list or a blob.
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
922 */
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
923 int
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
924 check_for_list_or_blob_arg(typval_T *args, int idx)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
925 {
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
926 if (args[idx].v_type != VAR_LIST && args[idx].v_type != VAR_BLOB)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
927 {
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
928 semsg(_(e_list_or_blob_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
929 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
930 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
931 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
932 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
933
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
934 /*
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
935 * Give an error and return FAIL unless "args[idx]" is a list or dict
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
936 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
937 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
938 check_for_list_or_dict_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
939 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
940 if (args[idx].v_type != VAR_LIST
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
941 && args[idx].v_type != VAR_DICT)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
942 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
943 semsg(_(e_list_or_dict_required_for_argument_nr), idx + 1);
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
944 return FAIL;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
945 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
946 return OK;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
947 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
948
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
949 /*
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
950 * Give an error and return FAIL unless "args[idx]" is a list or dict or a
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
951 * blob.
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
952 */
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
953 int
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
954 check_for_list_or_dict_or_blob_arg(typval_T *args, int idx)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
955 {
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
956 if (args[idx].v_type != VAR_LIST
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
957 && args[idx].v_type != VAR_DICT
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
958 && args[idx].v_type != VAR_BLOB)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
959 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
960 semsg(_(e_list_dict_or_blob_required_for_argument_nr), idx + 1);
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
961 return FAIL;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
962 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
963 return OK;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
964 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
965
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
966 /*
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
967 * Give an error and return FAIL unless "args[idx]" is a list or dict or a
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
968 * blob or a string.
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
969 */
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
970 int
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
971 check_for_list_or_dict_or_blob_or_string_arg(typval_T *args, int idx)
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
972 {
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
973 if (args[idx].v_type != VAR_LIST
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
974 && args[idx].v_type != VAR_DICT
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
975 && args[idx].v_type != VAR_BLOB
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
976 && args[idx].v_type != VAR_STRING)
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
977 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
978 semsg(_(e_list_dict_blob_or_string_required_for_argument_nr), idx + 1);
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
979 return FAIL;
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
980 }
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
981 return OK;
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
982 }
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
983
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
984 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
985 * Give an error and return FAIL unless "args[idx]" is an optional buffer
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
986 * number or a dict.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
987 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
988 int
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
989 check_for_opt_buffer_or_dict_arg(typval_T *args, int idx)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
990 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
991 if (args[idx].v_type != VAR_UNKNOWN
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
992 && args[idx].v_type != VAR_STRING
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
993 && args[idx].v_type != VAR_NUMBER
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
994 && args[idx].v_type != VAR_DICT)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
995 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
996 semsg(_(e_string_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
997 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
998 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
999 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
1000 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
1001
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
1002 /*
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1003 * Give an error and return FAIL unless "args[idx]" is an object.
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1004 */
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1005 int
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1006 check_for_object_arg(typval_T *args, int idx)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1007 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1008 if (args[idx].v_type != VAR_OBJECT)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1009 {
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
1010 semsg(_(e_object_required_for_argument_nr), idx + 1);
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1011 return FAIL;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1012 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1013 return OK;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1014 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1015
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1016 /*
33682
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1017 * Returns TRUE if "tv" is a type alias for a class
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1018 */
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1019 int
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1020 tv_class_alias(typval_T *tv)
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1021 {
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1022 return tv->v_type == VAR_TYPEALIAS &&
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1023 tv->vval.v_typealias->ta_type->tt_type == VAR_OBJECT;
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1024 }
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1025
f126ffc85f7c patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
1026 /*
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1027 * Give an error and return FAIL unless "args[idx]" is a class
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1028 * or class typealias.
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1029 */
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1030 int
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1031 check_for_class_or_typealias_args(typval_T *args, int idx)
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1032 {
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1033 for (int i = idx; args[i].v_type != VAR_UNKNOWN; ++i)
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1034 {
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1035 if (args[i].v_type != VAR_CLASS && !tv_class_alias(&args[idx]))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1036 {
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1037 semsg(_(e_class_or_typealias_required_for_argument_nr), i + 1);
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1038 return FAIL;
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33682
diff changeset
1039 }
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1040 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1041 return OK;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1042 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1043
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32130
diff changeset
1044 /*
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 * Get the string value of a variable.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 * If it is a Number variable, the number is converted into a string.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 * tv_get_string_buf() uses a given buffer.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 * If the String variable has never been set, return an empty string.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 * Never returns NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 * tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 * NULL on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 tv_get_string(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 return tv_get_string_buf(varp, mybuf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1062 /*
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1063 * Like tv_get_string() but don't allow number to string conversion for Vim9.
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1064 */
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1065 char_u *
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1066 tv_get_string_strict(typval_T *varp)
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1067 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1068 static char_u mybuf[NUMBUFLEN];
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1069 char_u *res = tv_get_string_buf_chk_strict(
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1070 varp, mybuf, in_vim9script());
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1071
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1072 return res != NULL ? res : (char_u *)"";
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1073 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1074
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 tv_get_string_buf(typval_T *varp, char_u *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 {
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1078 char_u *res = tv_get_string_buf_chk(varp, buf);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 return res != NULL ? res : (char_u *)"";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 tv_get_string_chk(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 return tv_get_string_buf_chk(varp, mybuf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 tv_get_string_buf_chk(typval_T *varp, char_u *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 {
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1097 return tv_get_string_buf_chk_strict(varp, buf, FALSE);
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1098 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1099
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1100 char_u *
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1101 tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1102 {
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 case VAR_NUMBER:
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1106 if (strict)
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1107 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1108 emsg(_(e_using_number_as_string));
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1109 break;
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
1110 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 vim_snprintf((char *)buf, NUMBUFLEN, "%lld",
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 (varnumber_T)varp->vval.v_number);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 case VAR_PARTIAL:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1116 emsg(_(e_using_funcref_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 case VAR_LIST:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1119 emsg(_(e_using_list_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 case VAR_DICT:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1122 emsg(_(e_using_dictionary_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 case VAR_FLOAT:
24820
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1125 if (strict)
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1126 {
26885
ed39730119bd patch 8.2.3971: build fails
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1127 emsg(_(e_using_float_as_string));
24820
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1128 break;
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1129 }
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1130 vim_snprintf((char *)buf, NUMBUFLEN, "%g", varp->vval.v_float);
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1131 return buf;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 if (varp->vval.v_string != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 return varp->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 return (char_u *)"";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 STRCPY(buf, get_var_special_name(varp->vval.v_number));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 return buf;
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28718
diff changeset
1140 case VAR_BLOB:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
1141 emsg(_(e_using_blob_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 break;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1143 case VAR_CLASS:
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1144 case VAR_TYPEALIAS:
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1145 check_typval_is_value(varp);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1146 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1147 case VAR_OBJECT:
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
1148 {
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
1149 class_T *cl = varp->vval.v_object->obj_class;
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
1150 if (cl != NULL && IS_ENUM(cl))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
1151 semsg(_(e_using_enum_str_as_string), cl->class_name);
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
1152 else
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
1153 emsg(_(e_using_object_as_string));
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34264
diff changeset
1154 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1155 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 #ifdef FEAT_JOB_CHANNEL
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1158 if (in_vim9script())
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 {
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1160 semsg(_(e_using_invalid_value_as_string_str), "job");
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1161 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 }
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1163 return job_to_string_buf(varp, buf);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 #ifdef FEAT_JOB_CHANNEL
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1168 if (in_vim9script())
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 {
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1170 semsg(_(e_using_invalid_value_as_string_str), "channel");
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1171 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 }
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
1173 return channel_to_string_buf(varp, buf);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 break;
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
1176 case VAR_VOID:
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
1177 emsg(_(e_cannot_use_void_value));
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
1178 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 case VAR_ANY:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1181 case VAR_INSTR:
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24610
diff changeset
1182 semsg(_(e_using_invalid_value_as_string_str),
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24610
diff changeset
1183 vartype_name(varp->v_type));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 * Turn a typeval into a string. Similar to tv_get_string_buf() but uses
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 * string() on Dict, List, etc.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 tv_stringify(typval_T *varp, char_u *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 if (varp->v_type == VAR_LIST
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 || varp->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 || varp->v_type == VAR_BLOB
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 || varp->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 || varp->v_type == VAR_PARTIAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 || varp->v_type == VAR_FLOAT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 typval_T tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 f_string(varp, &tmp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 tv_get_string_buf(&tmp, buf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 clear_tv(varp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 *varp = tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 return tmp.vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 return tv_get_string_buf(varp, buf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 * Return TRUE if typeval "tv" and its value are set to be locked (immutable).
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 * Also give an error message, using "name" or _("name") when use_gettext is
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 * TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 tv_check_lock(typval_T *tv, char_u *name, int use_gettext)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 int lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 switch (tv->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 if (tv->vval.v_blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 lock = tv->vval.v_blob->bv_lock;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 if (tv->vval.v_list != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 lock = tv->vval.v_list->lv_lock;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 if (tv->vval.v_dict != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 lock = tv->vval.v_dict->dv_lock;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 default:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 }
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22043
diff changeset
1241 return value_check_lock(tv->v_lock, name, use_gettext)
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22043
diff changeset
1242 || (lock != 0 && value_check_lock(lock, name, use_gettext));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 * Copy the values from typval_T "from" to typval_T "to".
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 * When needed allocates string or increases reference count.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 * Does not make a copy of a list, blob or dict but copies the reference!
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 * It is OK for "from" and "to" to point to the same item. This is used to
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 * make a copy later.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 copy_tv(typval_T *from, typval_T *to)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 to->v_type = from->v_type;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 to->v_lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 switch (from->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 to->vval.v_number = from->vval.v_number;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 to->vval.v_float = from->vval.v_float;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 to->vval.v_job = from->vval.v_job;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 if (to->vval.v_job != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 ++to->vval.v_job->jv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 to->vval.v_channel = from->vval.v_channel;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 if (to->vval.v_channel != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 ++to->vval.v_channel->ch_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1281 case VAR_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1282 to->vval.v_instr = from->vval.v_instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1283 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1284
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1285 case VAR_CLASS:
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1286 copy_class(from, to);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1287 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1288
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1289 case VAR_OBJECT:
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1290 copy_object(from, to);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1291 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
1292
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 if (from->vval.v_string == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 to->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 to->vval.v_string = vim_strsave(from->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 if (from->v_type == VAR_FUNC)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 func_ref(to->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 if (from->vval.v_partial == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 to->vval.v_partial = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 to->vval.v_partial = from->vval.v_partial;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 ++to->vval.v_partial->pt_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 if (from->vval.v_blob == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 to->vval.v_blob = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 to->vval.v_blob = from->vval.v_blob;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 ++to->vval.v_blob->bv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 if (from->vval.v_list == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 to->vval.v_list = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 to->vval.v_list = from->vval.v_list;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 ++to->vval.v_list->lv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 if (from->vval.v_dict == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 to->vval.v_dict = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 to->vval.v_dict = from->vval.v_dict;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 ++to->vval.v_dict->dv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 break;
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1340 case VAR_TYPEALIAS:
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1341 if (from->vval.v_typealias == NULL)
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1342 to->vval.v_typealias = NULL;
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1343 else
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1344 {
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1345 to->vval.v_typealias = from->vval.v_typealias;
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1346 ++to->vval.v_typealias->ta_refcount;
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1347 }
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1348 break;
24940
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1349 case VAR_VOID:
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1350 emsg(_(e_cannot_use_void_value));
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1351 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 internal_error_no_abort("copy_tv(UNKNOWN)");
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 /*
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1360 * Compare "tv1" and "tv2".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1361 * Put the result in "tv1". Caller should clear "tv2".
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 typval_compare(
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1365 typval_T *tv1, // first operand
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1366 typval_T *tv2, // second operand
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1367 exprtype_T type, // operator
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1368 int ic) // ignore case
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 varnumber_T n1, n2;
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1371 int res = 0;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 int type_is = type == EXPR_IS || type == EXPR_ISNOT;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1374 if (check_typval_is_value(tv1) == FAIL
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1375 || check_typval_is_value(tv2) == FAIL)
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1376 {
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1377 clear_tv(tv1);
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1378 return FAIL;
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1379 }
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
1380 else if (type_is && tv1->v_type != tv2->v_type)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 {
29994
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29525
diff changeset
1382 // For "is" a different type always means FALSE, for "isnot"
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 // it means TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 n1 = (type == EXPR_ISNOT);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 }
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1386 else if (((tv1->v_type == VAR_SPECIAL && tv1->vval.v_number == VVAL_NULL)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1387 || (tv2->v_type == VAR_SPECIAL
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1388 && tv2->vval.v_number == VVAL_NULL))
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1389 && tv1->v_type != tv2->v_type
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1390 && (type == EXPR_EQUAL || type == EXPR_NEQUAL))
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1391 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1392 n1 = typval_compare_null(tv1, tv2);
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1393 if (n1 == MAYBE)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1394 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1395 clear_tv(tv1);
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1396 return FAIL;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1397 }
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1398 if (type == EXPR_NEQUAL)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1399 n1 = !n1;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1400 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1401 else if (tv1->v_type == VAR_BLOB || tv2->v_type == VAR_BLOB)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1403 if (typval_compare_blob(tv1, tv2, type, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1405 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1408 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1410 else if (tv1->v_type == VAR_LIST || tv2->v_type == VAR_LIST)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1412 if (typval_compare_list(tv1, tv2, type, ic, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1414 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1417 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 }
31604
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1419 else if (tv1->v_type == VAR_OBJECT || tv2->v_type == VAR_OBJECT)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1420 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1421 if (typval_compare_object(tv1, tv2, type, ic, &res) == FAIL)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1422 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1423 clear_tv(tv1);
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1424 return FAIL;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1425 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1426 n1 = res;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1427 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1428 else if (tv1->v_type == VAR_DICT || tv2->v_type == VAR_DICT)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1430 if (typval_compare_dict(tv1, tv2, type, ic, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1432 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1435 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1437 else if (tv1->v_type == VAR_FUNC || tv2->v_type == VAR_FUNC
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1438 || tv1->v_type == VAR_PARTIAL || tv2->v_type == VAR_PARTIAL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1440 if (typval_compare_func(tv1, tv2, type, ic, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1442 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1445 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 // If one of the two variables is a float, compare as a float.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 // When using "=~" or "!~", always compare as string.
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1450 else if ((tv1->v_type == VAR_FLOAT || tv2->v_type == VAR_FLOAT)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 && type != EXPR_MATCH && type != EXPR_NOMATCH)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 float_T f1, f2;
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1454 int error = FALSE;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1456 f1 = tv_get_float_chk(tv1, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1457 if (!error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1458 f2 = tv_get_float_chk(tv2, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1459 if (error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1460 {
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1461 clear_tv(tv1);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1462 return FAIL;
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1463 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 n1 = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 case EXPR_EQUAL: n1 = (f1 == f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 case EXPR_NEQUAL: n1 = (f1 != f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 case EXPR_GREATER: n1 = (f1 > f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 case EXPR_GEQUAL: n1 = (f1 >= f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 case EXPR_SMALLER: n1 = (f1 < f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 case EXPR_SEQUAL: n1 = (f1 <= f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 // If one of the two variables is a number, compare as a number.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 // When using "=~" or "!~", always compare as string.
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1483 else if ((tv1->v_type == VAR_NUMBER || tv2->v_type == VAR_NUMBER)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 && type != EXPR_MATCH && type != EXPR_NOMATCH)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 {
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1486 int error = FALSE;
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1487
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1488 n1 = tv_get_number_chk(tv1, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1489 if (!error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1490 n2 = tv_get_number_chk(tv2, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1491 if (error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1492 {
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1493 clear_tv(tv1);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1494 return FAIL;
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1495 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 case EXPR_EQUAL: n1 = (n1 == n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 case EXPR_NEQUAL: n1 = (n1 != n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 case EXPR_GREATER: n1 = (n1 > n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 case EXPR_GEQUAL: n1 = (n1 >= n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 case EXPR_SMALLER: n1 = (n1 < n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 case EXPR_SEQUAL: n1 = (n1 <= n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1511 else if (in_vim9script() && (tv1->v_type == VAR_BOOL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1512 || tv2->v_type == VAR_BOOL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1513 || (tv1->v_type == VAR_SPECIAL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1514 && tv2->v_type == VAR_SPECIAL)))
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1515 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1516 if (tv1->v_type != tv2->v_type)
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1517 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1518 semsg(_(e_cannot_compare_str_with_str),
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1519 vartype_name(tv1->v_type), vartype_name(tv2->v_type));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1520 clear_tv(tv1);
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1521 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1522 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1523 n1 = tv1->vval.v_number;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1524 n2 = tv2->vval.v_number;
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1525 switch (type)
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1526 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1527 case EXPR_IS:
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1528 case EXPR_EQUAL: n1 = (n1 == n2); break;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1529 case EXPR_ISNOT:
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1530 case EXPR_NEQUAL: n1 = (n1 != n2); break;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1531 default:
25278
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1532 semsg(_(e_invalid_operation_for_str),
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1533 vartype_name(tv1->v_type));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1534 clear_tv(tv1);
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1535 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1536 }
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1537 }
28217
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1538 #ifdef FEAT_JOB_CHANNEL
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1539 else if (tv1->v_type == tv2->v_type
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1540 && (tv1->v_type == VAR_CHANNEL || tv1->v_type == VAR_JOB)
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1541 && (type == EXPR_NEQUAL || type == EXPR_EQUAL))
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1542 {
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1543 if (tv1->v_type == VAR_CHANNEL)
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1544 n1 = tv1->vval.v_channel == tv2->vval.v_channel;
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1545 else
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1546 n1 = tv1->vval.v_job == tv2->vval.v_job;
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1547 if (type == EXPR_NEQUAL)
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1548 n1 = !n1;
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1549 }
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1550 #endif
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1553 if (typval_compare_string(tv1, tv2, type, ic, &res) == FAIL)
25278
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1554 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1555 clear_tv(tv1);
25278
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1556 return FAIL;
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1557 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1558 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1560 clear_tv(tv1);
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1561 if (in_vim9script())
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1562 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1563 tv1->v_type = VAR_BOOL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1564 tv1->vval.v_number = n1 ? VVAL_TRUE : VVAL_FALSE;
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1565 }
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1566 else
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1567 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1568 tv1->v_type = VAR_NUMBER;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1569 tv1->vval.v_number = n1;
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1570 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1575 /*
30986
360f286b5869 patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents: 30761
diff changeset
1576 * Compare "tv1" to "tv2" as lists according to "type" and "ic".
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1577 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1578 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1579 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1580 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1581 typval_compare_list(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1582 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1583 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1584 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1585 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1586 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1587 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1588 int val = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1589
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1590 if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1591 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1592 val = (tv1->v_type == tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1593 && tv1->vval.v_list == tv2->vval.v_list);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1594 if (type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1595 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1596 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1597 else if (tv1->v_type != tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1598 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1599 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1600 if (tv1->v_type != tv2->v_type)
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1601 emsg(_(e_can_only_compare_list_with_list));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1602 else
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1603 emsg(_(e_invalid_operation_for_list));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1604 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1605 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1606 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1607 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1608 val = list_equal(tv1->vval.v_list, tv2->vval.v_list,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1609 ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1610 if (type == EXPR_NEQUAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1611 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1612 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1613 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1614 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1615 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1616
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1617 /*
28011
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 27928
diff changeset
1618 * Compare v:null with another type. Return TRUE if the value is NULL.
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1619 */
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1620 int
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1621 typval_compare_null(typval_T *tv1, typval_T *tv2)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1622 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1623 if ((tv1->v_type == VAR_SPECIAL && tv1->vval.v_number == VVAL_NULL)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1624 || (tv2->v_type == VAR_SPECIAL && tv2->vval.v_number == VVAL_NULL))
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1625 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1626 typval_T *tv = tv1->v_type == VAR_SPECIAL ? tv2 : tv1;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1627
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1628 switch (tv->v_type)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1629 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1630 case VAR_BLOB: return tv->vval.v_blob == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1631 #ifdef FEAT_JOB_CHANNEL
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1632 case VAR_CHANNEL: return tv->vval.v_channel == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1633 #endif
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
1634 // TODO: null_class handling
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
1635 // case VAR_CLASS: return tv->vval.v_class == NULL;
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1636 case VAR_DICT: return tv->vval.v_dict == NULL;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1637 case VAR_FUNC: return tv->vval.v_string == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1638 #ifdef FEAT_JOB_CHANNEL
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1639 case VAR_JOB: return tv->vval.v_job == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1640 #endif
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1641 case VAR_LIST: return tv->vval.v_list == NULL;
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
1642 case VAR_OBJECT: return tv->vval.v_object == NULL;
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1643 case VAR_PARTIAL: return tv->vval.v_partial == NULL;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1644 case VAR_STRING: return tv->vval.v_string == NULL;
27928
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1645
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1646 case VAR_NUMBER: if (!in_vim9script())
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1647 return tv->vval.v_number == 0;
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1648 break;
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1649 case VAR_FLOAT: if (!in_vim9script())
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1650 return tv->vval.v_float == 0.0;
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1651 break;
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
1652 case VAR_TYPEALIAS: return tv->vval.v_typealias == NULL;
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1653 default: break;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1654 }
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1655 }
28217
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1656 // although comparing null with number, float or bool is not very useful
28103
1615d305c71d patch 8.2.4576: Vim9: error for comparing with null can be annoying
Bram Moolenaar <Bram@vim.org>
parents: 28019
diff changeset
1657 // we won't give an error
1615d305c71d patch 8.2.4576: Vim9: error for comparing with null can be annoying
Bram Moolenaar <Bram@vim.org>
parents: 28019
diff changeset
1658 return FALSE;
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1659 }
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1660
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1661 /*
30986
360f286b5869 patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents: 30761
diff changeset
1662 * Compare "tv1" to "tv2" as blobs according to "type".
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1663 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1664 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1665 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1666 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1667 typval_compare_blob(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1668 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1669 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1670 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1671 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1672 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1673 int val = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1674
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1675 if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1676 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1677 val = (tv1->v_type == tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1678 && tv1->vval.v_blob == tv2->vval.v_blob);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1679 if (type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1680 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1681 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1682 else if (tv1->v_type != tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1683 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1684 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1685 if (tv1->v_type != tv2->v_type)
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
1686 emsg(_(e_can_only_compare_blob_with_blob));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1687 else
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26782
diff changeset
1688 emsg(_(e_invalid_operation_for_blob));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1689 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1690 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1691 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1692 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1693 val = blob_equal(tv1->vval.v_blob, tv2->vval.v_blob);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1694 if (type == EXPR_NEQUAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1695 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1696 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1697 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1698 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1699 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1700
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1701 /*
31604
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1702 * Compare "tv1" to "tv2" as classes according to "type".
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1703 * Put the result, false or true, in "res".
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1704 * Return FAIL and give an error message when the comparison can't be done.
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1705 */
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1706 int
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1707 typval_compare_class(
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1708 typval_T *tv1,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1709 typval_T *tv2,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1710 exprtype_T type UNUSED,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1711 int ic UNUSED,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1712 int *res)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1713 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1714 // TODO: use "type"
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1715 *res = tv1->vval.v_class == tv2->vval.v_class;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1716 return OK;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1717 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1718
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1719 /*
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1720 * Compare "tv1" to "tv2" as objects according to "type".
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1721 * Put the result, false or true, in "res".
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1722 * Return FAIL and give an error message when the comparison can't be done.
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1723 */
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1724 int
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1725 typval_compare_object(
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1726 typval_T *tv1,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1727 typval_T *tv2,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1728 exprtype_T type,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1729 int ic,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1730 int *res)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1731 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1732 int res_match = type == EXPR_EQUAL || type == EXPR_IS ? TRUE : FALSE;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1733
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1734 if (tv1->vval.v_object == NULL && tv2->vval.v_object == NULL)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1735 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1736 *res = res_match;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1737 return OK;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1738 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1739 if (tv1->vval.v_object == NULL || tv2->vval.v_object == NULL)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1740 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1741 *res = !res_match;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1742 return OK;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1743 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1744
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1745 class_T *cl1 = tv1->vval.v_object->obj_class;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1746 class_T *cl2 = tv2->vval.v_object->obj_class;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1747 if (cl1 != cl2 || cl1 == NULL || cl2 == NULL)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1748 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1749 *res = !res_match;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1750 return OK;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1751 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1752
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1753 object_T *obj1 = tv1->vval.v_object;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1754 object_T *obj2 = tv2->vval.v_object;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1755 if (type == EXPR_IS || type == EXPR_ISNOT)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1756 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1757 *res = obj1 == obj2 ? res_match : !res_match;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1758 return OK;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1759 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1760
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1761 for (int i = 0; i < cl1->class_obj_member_count; ++i)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1762 if (!tv_equal((typval_T *)(obj1 + 1) + i,
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1763 (typval_T *)(obj2 + 1) + i, ic, TRUE))
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1764 {
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1765 *res = !res_match;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1766 return OK;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1767 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1768 *res = res_match;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1769 return OK;
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1770 }
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1771
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
1772 /*
30986
360f286b5869 patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents: 30761
diff changeset
1773 * Compare "tv1" to "tv2" as dictionaries according to "type" and "ic".
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1774 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1775 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1776 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1777 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1778 typval_compare_dict(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1779 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1780 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1781 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1782 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1783 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1784 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1785 int val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1786
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1787 if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1788 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1789 val = (tv1->v_type == tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1790 && tv1->vval.v_dict == tv2->vval.v_dict);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1791 if (type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1792 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1793 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1794 else if (tv1->v_type != tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1795 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1796 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1797 if (tv1->v_type != tv2->v_type)
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1798 emsg(_(e_can_only_compare_dictionary_with_dictionary));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1799 else
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1800 emsg(_(e_invalid_operation_for_dictionary));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1801 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1802 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1803 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1804 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1805 val = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1806 if (type == EXPR_NEQUAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1807 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1808 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1809 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1810 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1811 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1812
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1813 /*
30986
360f286b5869 patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents: 30761
diff changeset
1814 * Compare "tv1" to "tv2" as funcrefs according to "type" and "ic".
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1815 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1816 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1817 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1818 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1819 typval_compare_func(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1820 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1821 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1822 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1823 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1824 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1825 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1826 int val = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1827
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1828 if (type != EXPR_EQUAL && type != EXPR_NEQUAL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1829 && type != EXPR_IS && type != EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1830 {
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1831 emsg(_(e_invalid_operation_for_funcrefs));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1832 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1833 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1834 if ((tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial == NULL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1835 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial == NULL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1836 // When both partials are NULL, then they are equal.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1837 // Otherwise they are not equal.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1838 val = (tv1->vval.v_partial == tv2->vval.v_partial);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1839 else if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1840 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1841 if (tv1->v_type == VAR_FUNC && tv2->v_type == VAR_FUNC)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1842 // strings are considered the same if their value is
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1843 // the same
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1844 val = tv_equal(tv1, tv2, ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1845 else if (tv1->v_type == VAR_PARTIAL && tv2->v_type == VAR_PARTIAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1846 val = (tv1->vval.v_partial == tv2->vval.v_partial);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1847 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1848 val = FALSE;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1849 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1850 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1851 val = tv_equal(tv1, tv2, ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1852 if (type == EXPR_NEQUAL || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1853 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1854 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1855 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1856 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1857
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1858 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1859 * Compare "tv1" to "tv2" as strings according to "type" and "ic".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1860 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1861 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1862 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1863 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1864 typval_compare_string(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1865 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1866 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1867 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1868 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1869 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1870 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1871 int i = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1872 int val = FALSE;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1873 char_u *s1, *s2;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1874 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1875
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1876 if (in_vim9script()
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1877 && ((tv1->v_type != VAR_STRING && tv1->v_type != VAR_SPECIAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1878 || (tv2->v_type != VAR_STRING && tv2->v_type != VAR_SPECIAL)))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1879 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1880 semsg(_(e_cannot_compare_str_with_str),
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1881 vartype_name(tv1->v_type), vartype_name(tv2->v_type));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1882 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1883 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1884 s1 = tv_get_string_buf(tv1, buf1);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1885 s2 = tv_get_string_buf(tv2, buf2);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1886 if (type != EXPR_MATCH && type != EXPR_NOMATCH)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1887 i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1888 switch (type)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1889 {
28019
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1890 case EXPR_IS: if (in_vim9script())
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1891 {
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1892 // Really check it is the same string, not just
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1893 // the same value.
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1894 val = tv1->vval.v_string == tv2->vval.v_string;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1895 break;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1896 }
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1897 // FALLTHROUGH
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1898 case EXPR_EQUAL: val = (i == 0); break;
28019
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1899 case EXPR_ISNOT: if (in_vim9script())
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1900 {
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1901 // Really check it is not the same string, not
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1902 // just a different value.
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1903 val = tv1->vval.v_string != tv2->vval.v_string;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1904 break;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1905 }
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1906 // FALLTHROUGH
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1907 case EXPR_NEQUAL: val = (i != 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1908 case EXPR_GREATER: val = (i > 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1909 case EXPR_GEQUAL: val = (i >= 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1910 case EXPR_SMALLER: val = (i < 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1911 case EXPR_SEQUAL: val = (i <= 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1912
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1913 case EXPR_MATCH:
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1914 case EXPR_NOMATCH:
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1915 val = pattern_match(s2, s1, ic);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1916 if (type == EXPR_NOMATCH)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1917 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1918 break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1919
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1920 default: break; // avoid gcc warning
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1921 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1922 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1923 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1924 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1925 /*
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1926 * Convert any type to a string, never give an error.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1927 * When "quotes" is TRUE add quotes to a string.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1928 * Returns an allocated string.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1929 */
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 char_u *
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1931 typval_tostring(typval_T *arg, int quotes)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 char_u *tofree;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 char_u numbuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 char_u *ret = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 if (arg == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 return vim_strsave((char_u *)"(does not exist)");
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1939 if (!quotes && arg->v_type == VAR_STRING)
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1940 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1941 ret = vim_strsave(arg->vval.v_string == NULL ? (char_u *)""
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1942 : arg->vval.v_string);
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1943 }
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1944 else
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1945 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1946 ret = tv2string(arg, &tofree, numbuf, 0);
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1947 // Make a copy if we have a value but it's not in allocated memory.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1948 if (ret != NULL && tofree == NULL)
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1949 ret = vim_strsave(ret);
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1950 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 return ret;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 * Return TRUE if typeval "tv" is locked: Either that value is locked itself
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 * or it refers to a List or Dictionary that is locked.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 tv_islocked(typval_T *tv)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 return (tv->v_lock & VAR_LOCKED)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 || (tv->v_type == VAR_LIST
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 && tv->vval.v_list != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 && (tv->vval.v_list->lv_lock & VAR_LOCKED))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 || (tv->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 && tv->vval.v_dict != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 && (tv->vval.v_dict->dv_lock & VAR_LOCKED));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 static int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 func_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 int ic) // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 dict_T *d1, *d2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 int a1, a2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 int i;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 // empty and NULL function name considered the same
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 : partial_name(tv1->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 if (s1 != NULL && *s1 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 s1 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 : partial_name(tv2->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 if (s2 != NULL && *s2 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 s2 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 if (s1 == NULL || s2 == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 if (s1 != s2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 else if (STRCMP(s1, s2) != 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 // empty dict and NULL dict is different
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 d1 = tv1->v_type == VAR_FUNC ? NULL : tv1->vval.v_partial->pt_dict;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 d2 = tv2->v_type == VAR_FUNC ? NULL : tv2->vval.v_partial->pt_dict;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 if (d1 == NULL || d2 == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 if (d1 != d2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 else if (!dict_equal(d1, d2, ic, TRUE))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 // empty list and no list considered the same
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 a1 = tv1->v_type == VAR_FUNC ? 0 : tv1->vval.v_partial->pt_argc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 a2 = tv2->v_type == VAR_FUNC ? 0 : tv2->vval.v_partial->pt_argc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 if (a1 != a2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 for (i = 0; i < a1; ++i)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 if (!tv_equal(tv1->vval.v_partial->pt_argv + i,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 tv2->vval.v_partial->pt_argv + i, ic, TRUE))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 return TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 * Return TRUE if "tv1" and "tv2" have the same value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 * Compares the items just like "==" would compare them, but strings and
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 * numbers are different. Floats and numbers are also different.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 tv_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 int ic, // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 int recursive) // TRUE when used recursively
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 static int recursive_cnt = 0; // catch recursive loops
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 int r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 static int tv_equal_recurse_limit;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 // Catch lists and dicts that have an endless loop by limiting
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 // recursiveness to a limit. We guess they are equal then.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 // A fixed limit has the problem of still taking an awful long time.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 // Reduce the limit every time running into it. That should work fine for
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 // deeply linked structures that are not recursively linked and catch
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 // recursiveness quickly.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 if (!recursive)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 tv_equal_recurse_limit = 1000;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 if (recursive_cnt >= tv_equal_recurse_limit)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 --tv_equal_recurse_limit;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 return TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 // For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 // arguments.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 if ((tv1->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 && (tv2->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial != NULL)))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 r = func_equal(tv1, tv2, ic);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066
23909
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
2067 if (tv1->v_type != tv2->v_type
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
2068 && ((tv1->v_type != VAR_BOOL && tv1->v_type != VAR_SPECIAL)
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
2069 || (tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL)))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 switch (tv1->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 return blob_equal(tv1->vval.v_blob, tv2->vval.v_blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 return tv1->vval.v_number == tv2->vval.v_number;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095 s1 = tv_get_string_buf(tv1, buf1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 s2 = tv_get_string_buf(tv2, buf2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 return tv1->vval.v_float == tv2->vval.v_float;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 return tv1->vval.v_job == tv2->vval.v_job;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 return tv1->vval.v_channel == tv2->vval.v_channel;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
2109 case VAR_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
2110 return tv1->vval.v_instr == tv2->vval.v_instr;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
2112 case VAR_CLASS:
31604
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
2113 // A class only exists once, equality is identity.
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
2114 return tv1->vval.v_class == tv2->vval.v_class;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
2115
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
2116 case VAR_OBJECT:
31604
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
2117 (void)typval_compare_object(tv1, tv2, EXPR_EQUAL, ic, &r);
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
2118 return r;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31289
diff changeset
2119
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 return tv1->vval.v_partial == tv2->vval.v_partial;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 return tv1->vval.v_string == tv2->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
2126 case VAR_TYPEALIAS:
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
2127 return tv1->vval.v_typealias == tv2->vval.v_typealias;
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33594
diff changeset
2128
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 case VAR_VOID:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 // VAR_UNKNOWN can be the result of a invalid expression, let's say it
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 // does not equal anything, not even itself.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 * Get an option value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 * "arg" points to the '&' or '+' before the option name.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 * "arg" is advanced to character after the option name.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
2147 eval_option(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 typval_T *rettv, // when NULL, only check if option exists
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 int evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 char_u *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 long numval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 char_u *stringval;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2155 getoption_T opt_type;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 int c;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 int working = (**arg == '+'); // has("+option")
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 int ret = OK;
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26342
diff changeset
2159 int scope;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 // Isolate the option name and find its value.
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26342
diff changeset
2162 option_end = find_option_end(arg, &scope);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 if (option_end == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 if (rettv != NULL)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
2166 semsg(_(e_option_name_missing_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 c = *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 *option_end = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 opt_type = get_option_value(*arg, &numval,
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26342
diff changeset
2179 rettv == NULL ? NULL : &stringval, NULL, scope);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2181 if (opt_type == gov_unknown)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 if (rettv != NULL)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
2184 semsg(_(e_unknown_option_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 else if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 {
23519
cb66613dd9d5 patch 8.2.2302: Vim9: using an option value may use uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
2189 rettv->v_lock = 0;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2190 if (opt_type == gov_hidden_string)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 rettv->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2195 else if (opt_type == gov_hidden_bool || opt_type == gov_hidden_number)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2197 rettv->v_type = in_vim9script() && opt_type == gov_hidden_bool
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2198 ? VAR_BOOL : VAR_NUMBER;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 rettv->vval.v_number = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2201 else if (opt_type == gov_bool || opt_type == gov_number)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2203 if (in_vim9script() && opt_type == gov_bool)
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2204 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2205 rettv->v_type = VAR_BOOL;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2206 rettv->vval.v_number = numval ? VVAL_TRUE : VVAL_FALSE;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2207 }
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2208 else
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2209 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2210 rettv->v_type = VAR_NUMBER;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2211 rettv->vval.v_number = numval;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2212 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 else // string option
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 rettv->vval.v_string = stringval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2220 else if (working && (opt_type == gov_hidden_bool
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2221 || opt_type == gov_hidden_number
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
2222 || opt_type == gov_hidden_string))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 *option_end = c; // put back for error messages
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 return ret;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 * Allocate a variable for a number constant. Also deals with "0z" for blob.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
2236 eval_number(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 typval_T *rettv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 int evaluate,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 int want_string UNUSED)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 int len;
25622
15b54e0a576b patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 25585
diff changeset
2243 int skip_quotes = !in_old_script(4);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 char_u *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 int get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 // We accept a float when the format matches
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249 // strict to avoid backwards compatibility problems.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 // With script version 2 and later the leading digit can be
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 // omitted.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 // Don't look for a float after the "." operator, so that
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253 // ":let vers = 1.2.3" doesn't fail.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 if (**arg == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 p = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 else
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2257 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2258 p = *arg + 1;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2259 if (skip_quotes)
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2260 for (;;)
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2261 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2262 if (*p == '\'')
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2263 ++p;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2264 if (!vim_isdigit(*p))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2265 break;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2266 p = skipdigits(p);
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2267 }
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2268 else
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2269 p = skipdigits(p);
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2270 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 if (!want_string && p[0] == '.' && vim_isdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 get_float = TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 p = skipdigits(p + 2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 if (*p == 'e' || *p == 'E')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278 if (*p == '-' || *p == '+')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 if (!vim_isdigit(*p))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283 p = skipdigits(p + 1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 if (ASCII_ISALPHA(*p) || *p == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 if (get_float)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 float_T f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2292 *arg += string2float(*arg, &f, skip_quotes);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 rettv->v_type = VAR_FLOAT;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 rettv->vval.v_float = f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 if (**arg == '0' && ((*arg)[1] == 'z' || (*arg)[1] == 'Z'))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 char_u *bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 blob_T *blob = NULL; // init for gcc
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 // Blob constant: 0z0123456789abcdef
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 blob = blob_alloc();
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 for (bp = *arg + 2; vim_isxdigit(bp[0]); bp += 2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2309 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 if (!vim_isxdigit(bp[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313 {
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
2314 emsg(_(e_blob_literal_should_have_an_even_number_of_hex_characters));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 ga_clear(&blob->bv_ga);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316 VIM_CLEAR(blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 ga_append(&blob->bv_ga,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 (hex2nr(*bp) << 4) + hex2nr(*(bp+1)));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323 if (bp[2] == '.' && vim_isxdigit(bp[3]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 ++bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 rettv_blob_set(rettv, blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 *arg = bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332 varnumber_T n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 // decimal, hex or octal number
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
2335 vim_str2nr(*arg, NULL, &len, skip_quotes
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 ? STR2NR_NO_OCT + STR2NR_QUOTE
32098
39f4126d2a0d patch 9.0.1380: CTRL-X on 2**64 subtracts two
Bram Moolenaar <Bram@vim.org>
parents: 31825
diff changeset
2337 : STR2NR_ALL, &n, NULL, 0, TRUE, NULL);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2339 {
26342
936f77929f16 patch 8.2.3702: first key in dict is seen as curly expression and fails
Bram Moolenaar <Bram@vim.org>
parents: 25806
diff changeset
2340 if (evaluate)
936f77929f16 patch 8.2.3702: first key in dict is seen as curly expression and fails
Bram Moolenaar <Bram@vim.org>
parents: 25806
diff changeset
2341 semsg(_(e_invalid_expression_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 *arg += len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 rettv->v_type = VAR_NUMBER;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 rettv->vval.v_number = n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 /*
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2355 * Evaluate a string constant and put the result in "rettv".
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2356 * "*arg" points to the double quote or to after it when "interpolate" is TRUE.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2357 * When "interpolate" is TRUE reduce "{{" to "{", reduce "}}" to "}" and stop
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2358 * at a single "{".
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 int
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2362 eval_string(char_u **arg, typval_T *rettv, int evaluate, int interpolate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 char_u *p;
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2365 char_u *end;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2366 int extra = interpolate ? 1 : 0;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2367 int off = interpolate ? 0 : 1;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 // Find the end of the string, skipping backslashed characters.
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2371 for (p = *arg + off; *p != NUL && *p != '"'; MB_PTR_ADV(p))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2373 if (*p == '\\' && p[1] != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 // A "\<x>" form occupies at least 4 characters, and produces up
28668
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2377 // to 9 characters (6 for the char and 3 for a modifier):
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2378 // reserve space for 5 extra.
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 if (*p == '<')
29525
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2380 {
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2381 int modifiers = 0;
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2382 int flags = FSK_KEYCODE | FSK_IN_STRING;
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2383
28668
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2384 extra += 5;
29525
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2385
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2386 // Skip to the '>' to avoid using '{' inside for string
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2387 // interpolation.
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2388 if (p[1] != '*')
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2389 flags |= FSK_SIMPLIFY;
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2390 if (find_special_key(&p, &modifiers, flags, NULL) != 0)
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2391 --p; // leave "p" on the ">"
5063dfe96a59 patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents: 28821
diff changeset
2392 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 }
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2394 else if (interpolate && (*p == '{' || *p == '}'))
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2395 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2396 if (*p == '{' && p[1] != '{') // start of expression
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2397 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2398 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2399 if (p[-1] == '}' && *p != '}') // single '}' is an error
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2400 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2401 semsg(_(e_stray_closing_curly_str), *arg);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2402 return FAIL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2403 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2404 --extra; // "{{" becomes "{", "}}" becomes "}"
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2405 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2408 if (*p != '"' && !(interpolate && *p == '{'))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
2410 semsg(_(e_missing_double_quote_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 // If only parsing, set *arg and return here
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 {
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2417 *arg = p + off;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 // Copy the string into allocated memory, handling backslashed
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 // characters.
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2423 rettv->v_type = VAR_STRING;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 len = (int)(p - *arg + extra);
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2425 rettv->vval.v_string = alloc(len);
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2426 if (rettv->vval.v_string == NULL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 return FAIL;
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2428 end = rettv->vval.v_string;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2430 for (p = *arg + off; *p != NUL && *p != '"'; )
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 if (*p == '\\')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 switch (*++p)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2436 case 'b': *end++ = BS; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2437 case 'e': *end++ = ESC; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2438 case 'f': *end++ = FF; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2439 case 'n': *end++ = NL; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2440 case 'r': *end++ = CAR; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2441 case 't': *end++ = TAB; ++p; break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 case 'X': // hex: "\x1", "\x12"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 case 'x':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 case 'u': // Unicode: "\u0023"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 case 'U':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 if (vim_isxdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 int n, nr;
34074
1629cc65d78d patch 9.1.0006: is*() and to*() function may be unsafe
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
2450 int c = SAFE_toupper(*p);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 if (c == 'X')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 n = 2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 else if (*p == 'u')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 n = 4;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 n = 8;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 nr = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459 while (--n >= 0 && vim_isxdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 nr = (nr << 4) + hex2nr(*p);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465 // For "\u" store the number according to
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466 // 'encoding'.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 if (c != 'X')
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2468 end += (*mb_char2bytes)(nr, end);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 else
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2470 *end++ = nr;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2472 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 // octal: "\1", "\12", "\123"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 case '0':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 case '1':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 case '2':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 case '3':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 case '4':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 case '5':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 case '6':
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2482 case '7': *end = *p++ - '0';
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 if (*p >= '0' && *p <= '7')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2485 *end = (*end << 3) + *p++ - '0';
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 if (*p >= '0' && *p <= '7')
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2487 *end = (*end << 3) + *p++ - '0';
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2489 ++end;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
2492 // Special key, e.g.: "\<C-W>"
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2493 case '<':
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 {
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2495 int flags = FSK_KEYCODE | FSK_IN_STRING;
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2496
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
2497 if (p[1] != '*')
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2498 flags |= FSK_SIMPLIFY;
28668
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2499 extra = trans_special(&p, end, flags, FALSE, NULL);
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2500 if (extra != 0)
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2501 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2502 end += extra;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2503 if (end >= rettv->vval.v_string + len)
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
2504 iemsg("eval_string() used more space than allocated");
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2505 break;
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
2506 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 // FALLTHROUGH
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2510 default: MB_COPY_CHAR(p, end);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 else
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2515 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2516 if (interpolate && (*p == '{' || *p == '}'))
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2517 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2518 if (*p == '{' && p[1] != '{') // start of expression
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2519 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2520 ++p; // reduce "{{" to "{" and "}}" to "}"
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2521 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2522 MB_COPY_CHAR(p, end);
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2523 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2525 *end = NUL;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2526 if (*p == '"' && !interpolate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 *arg = p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 * Allocate a variable for a 'str''ing' constant.
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2535 * When "interpolate" is TRUE reduce "{{" to "{" and stop at a single "{".
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2536 * Return OK when a "rettv" was set to the string.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2537 * Return FAIL on error, "rettv" is not set.
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 int
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2540 eval_lit_string(char_u **arg, typval_T *rettv, int evaluate, int interpolate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 char_u *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 char_u *str;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2544 int reduce = interpolate ? -1 : 0;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2545 int off = interpolate ? 0 : 1;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 // Find the end of the string, skipping ''.
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2548 for (p = *arg + off; *p != NUL; MB_PTR_ADV(p))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 ++reduce;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 }
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2557 else if (interpolate)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2558 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2559 if (*p == '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2560 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2561 if (p[1] != '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2562 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2563 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2564 ++reduce;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2565 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2566 else if (*p == '}')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2567 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2568 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2569 if (*p != '}')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2570 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2571 semsg(_(e_stray_closing_curly_str), *arg);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2572 return FAIL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2573 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2574 ++reduce;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2575 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2576 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2579 if (*p != '\'' && !(interpolate && *p == '{'))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
2581 semsg(_(e_missing_single_quote_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 // If only parsing return after setting "*arg"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 {
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2588 *arg = p + off;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2592 // Copy the string into allocated memory, handling '' to ' reduction and
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2593 // any expressions.
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 str = alloc((p - *arg) - reduce);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 if (str == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2596 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 rettv->vval.v_string = str;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2600 for (p = *arg + off; *p != NUL; )
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 }
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2608 else if (interpolate && (*p == '{' || *p == '}'))
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2609 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2610 if (*p == '{' && p[1] != '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2611 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2612 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2613 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614 MB_COPY_CHAR(p, str);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616 *str = NUL;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2617 *arg = p + off;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2618
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2620 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2622 /*
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2623 * Evaluate a single or double quoted string possibly containing expressions.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2624 * "arg" points to the '$'. The result is put in "rettv".
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2625 * Returns OK or FAIL.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2626 */
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2627 int
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2628 eval_interp_string(char_u **arg, typval_T *rettv, int evaluate)
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2629 {
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2630 typval_T tv;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2631 int ret = OK;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2632 int quote;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2633 garray_T ga;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2634 char_u *p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2635
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2636 ga_init2(&ga, 1, 80);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2637
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2638 // *arg is on the '$' character, move it to the first string character.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2639 ++*arg;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2640 quote = **arg;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2641 ++*arg;
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2642
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2643 for (;;)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2644 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2645 // Get the string up to the matching quote or to a single '{'.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2646 // "arg" is advanced to either the quote or the '{'.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2647 if (quote == '"')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2648 ret = eval_string(arg, &tv, evaluate, TRUE);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2649 else
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2650 ret = eval_lit_string(arg, &tv, evaluate, TRUE);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2651 if (ret == FAIL)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2652 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2653 if (evaluate)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2654 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2655 ga_concat(&ga, tv.vval.v_string);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2656 clear_tv(&tv);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2657 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2658
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2659 if (**arg != '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2660 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2661 // found terminating quote
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2662 ++*arg;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2663 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2664 }
28821
006d525419fa patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
2665 p = eval_one_expr_in_str(*arg, &ga, evaluate);
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2666 if (p == NULL)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2667 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2668 ret = FAIL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2669 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2670 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2671 *arg = p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2672 }
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2673
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2674 rettv->v_type = VAR_STRING;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2675 if (ret == FAIL || !evaluate || ga_append(&ga, NUL) == FAIL)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2676 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2677 ga_clear(&ga);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2678 rettv->vval.v_string = NULL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2679 return ret;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2680 }
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2681
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2682 rettv->vval.v_string = ga.ga_data;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2683 return OK;
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2684 }
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2685
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2687 * Return a string with the string representation of a variable.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2688 * If the memory is allocated "tofree" is set to it, otherwise NULL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2689 * "numbuf" is used for a number.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 * Puts quotes around strings, so that they can be parsed back by eval().
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2691 * May return NULL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2692 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2693 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2694 tv2string(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2695 typval_T *tv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2696 char_u **tofree,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2697 char_u *numbuf,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698 int copyID)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2699 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 return echo_string_core(tv, tofree, numbuf, copyID, FALSE, TRUE, FALSE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2701 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2702
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2703 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2704 * Get the value of an environment variable.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2705 * "arg" is pointing to the '$'. It is advanced to after the name.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2706 * If the environment variable was not set, silently assume it is empty.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2707 * Return FAIL if the name is invalid.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2708 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2709 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
2710 eval_env_var(char_u **arg, typval_T *rettv, int evaluate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2711 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2712 char_u *string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2713 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2714 int cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 char_u *name;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 int mustfree = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2718 ++*arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2719 name = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 len = get_env_len(arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2722 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2723 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 return FAIL; // invalid empty name
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2726 cc = name[len];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2727 name[len] = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2728 // first try vim_getenv(), fast for normal environment vars
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2729 string = vim_getenv(name, &mustfree);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2730 if (string != NULL && *string != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2731 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 if (!mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733 string = vim_strsave(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2734 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2737 if (mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2738 vim_free(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740 // next try expanding things like $VIM and ${HOME}
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2741 string = expand_env_save(name - 1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2742 if (string != NULL && *string == '$')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743 VIM_CLEAR(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2744 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2745 name[len] = cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2746
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2747 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748 rettv->vval.v_string = string;
25585
10edc624b171 patch 8.2.3329: v_lock not set when getting value of environment variable
Bram Moolenaar <Bram@vim.org>
parents: 25563
diff changeset
2749 rettv->v_lock = 0;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2750 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2751
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2752 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2754
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2756 * Get the lnum from the first argument.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2757 * Also accepts ".", "$", etc., but that only works for the current buffer.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2758 * Returns -1 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2761 tv_get_lnum(typval_T *argvars)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2762 {
23276
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
2763 linenr_T lnum = -1;
30761
c9b31c8eb3b3 patch 9.0.0715: wrong argument for append() gives two error messages
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
2764 int did_emsg_before = did_emsg;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
2766 if (argvars[0].v_type != VAR_STRING || !in_vim9script())
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
2767 lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL);
30761
c9b31c8eb3b3 patch 9.0.0715: wrong argument for append() gives two error messages
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
2768 if (lnum <= 0 && did_emsg_before == did_emsg
c9b31c8eb3b3 patch 9.0.0715: wrong argument for append() gives two error messages
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
2769 && argvars[0].v_type != VAR_NUMBER)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2770 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2771 int fnum;
26782
b7b82279426f patch 8.2.3919: Vim9: wrong argument for append() results in two errors
Bram Moolenaar <Bram@vim.org>
parents: 26731
diff changeset
2772 pos_T *fp;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773
24260
ad065f64eb20 patch 8.2.2671: error for line number in legacy script
Bram Moolenaar <Bram@vim.org>
parents: 24258
diff changeset
2774 // no valid number, try using arg like line()
26782
b7b82279426f patch 8.2.3919: Vim9: wrong argument for append() results in two errors
Bram Moolenaar <Bram@vim.org>
parents: 26731
diff changeset
2775 fp = var2fpos(&argvars[0], TRUE, &fnum, FALSE);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2776 if (fp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2777 lnum = fp->lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2779 return lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2782 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 * Get the lnum from the first argument.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2784 * Also accepts "$", then "buf" is used.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785 * Returns 0 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2788 tv_get_lnum_buf(typval_T *argvars, buf_T *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2790 if (argvars[0].v_type == VAR_STRING
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2791 && argvars[0].vval.v_string != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2792 && argvars[0].vval.v_string[0] == '$'
26782
b7b82279426f patch 8.2.3919: Vim9: wrong argument for append() results in two errors
Bram Moolenaar <Bram@vim.org>
parents: 26731
diff changeset
2793 && argvars[0].vval.v_string[1] == NUL
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2794 && buf != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795 return buf->b_ml.ml_line_count;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 return (linenr_T)tv_get_number_chk(&argvars[0], NULL);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2798
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2799 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2800 * Get buffer by number or pattern.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802 buf_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2803 tv_get_buf(typval_T *tv, int curtab_only)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2804 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2805 char_u *name = tv->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 buf_T *buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2807
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808 if (tv->v_type == VAR_NUMBER)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2809 return buflist_findnr((int)tv->vval.v_number);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2810 if (tv->v_type != VAR_STRING)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 if (name == NULL || *name == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2813 return curbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814 if (name[0] == '$' && name[1] == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 return lastbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2816
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 buf = buflist_find_by_name(name, curtab_only);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2818
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 // If not found, try expanding the name, like done for bufexists().
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2820 if (buf == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821 buf = find_buffer(tv);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2825
22025
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2826 /*
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2827 * Like tv_get_buf() but give an error message is the type is wrong.
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2828 */
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2829 buf_T *
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2830 tv_get_buf_from_arg(typval_T *tv)
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2831 {
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2832 buf_T *buf;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2833
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2834 ++emsg_off;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2835 buf = tv_get_buf(tv, FALSE);
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2836 --emsg_off;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2837 if (buf == NULL
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2838 && tv->v_type != VAR_NUMBER
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2839 && tv->v_type != VAR_STRING)
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2840 // issue errmsg for type error
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2841 (void)tv_get_number(tv);
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2842 return buf;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2843 }
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2844
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845 #endif // FEAT_EVAL