Mercurial > vim
annotate src/typval.c @ 31396:307f68a41b03 v9.0.1031
patch 9.0.1031: Vim9 class is not implemented yet
Commit: https://github.com/vim/vim/commit/00b28d6c23d8e662cab27e461825777c0a2e387a
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 8 15:32:33 2022 +0000
patch 9.0.1031: Vim9 class is not implemented yet
Problem: Vim9 class is not implemented yet.
Solution: Add very basic class support.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Dec 2022 16:45:03 +0100 |
parents | 4f1e70a709bb |
children | 60b1d266548d |
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 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 if (varp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 func_unref(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 // FALLTHROUGH |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 vim_free(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 partial_unref(varp->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 blob_unref(varp->vval.v_blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 list_unref(varp->vval.v_list); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 dict_unref(varp->vval.v_dict); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 job_unref(varp->vval.v_job); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 channel_unref(varp->vval.v_channel); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 #endif |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
87 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
88 class_unref(varp); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
89 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
90 case VAR_OBJECT: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
91 object_unref(varp->vval.v_object); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
92 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
93 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 case VAR_SPECIAL: |
24606
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
24424
diff
changeset
|
101 case VAR_INSTR: |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 vim_free(varp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 * 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
|
110 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 clear_tv(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 if (varp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 func_unref(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 // FALLTHROUGH |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 VIM_CLEAR(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 partial_unref(varp->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 varp->vval.v_partial = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 blob_unref(varp->vval.v_blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 varp->vval.v_blob = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 list_unref(varp->vval.v_list); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 varp->vval.v_list = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 dict_unref(varp->vval.v_dict); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 varp->vval.v_dict = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 varp->vval.v_number = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 varp->vval.v_float = 0.0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 job_unref(varp->vval.v_job); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 varp->vval.v_job = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 channel_unref(varp->vval.v_channel); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 varp->vval.v_channel = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 #endif |
24610
c1263588156b
patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents:
24606
diff
changeset
|
159 break; |
c1263588156b
patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents:
24606
diff
changeset
|
160 case VAR_INSTR: |
c1263588156b
patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents:
24606
diff
changeset
|
161 VIM_CLEAR(varp->vval.v_instr); |
c1263588156b
patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents:
24606
diff
changeset
|
162 break; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
163 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
164 class_unref(varp); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
165 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
166 case VAR_OBJECT: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
167 object_unref(varp->vval.v_object); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
168 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 varp->v_lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 * 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
|
180 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 init_tv(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 if (varp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 CLEAR_POINTER(varp); |
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 |
21851
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
188 static 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
|
189 tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool) |
20587
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 varnumber_T n = 0L; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 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
|
196 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
|
197 && 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
|
198 { |
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
|
199 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
|
200 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
|
201 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 return varp->vval.v_number; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 case VAR_FLOAT: |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
204 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
|
205 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 case VAR_PARTIAL: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
208 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
|
209 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 case VAR_STRING: |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
211 if (in_vim9script()) |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
212 { |
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
|
213 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
|
214 break; |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
215 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 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
|
217 vim_str2nr(varp->vval.v_string, NULL, NULL, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 STR2NR_ALL, &n, NULL, 0, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 return n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 case VAR_LIST: |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
221 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
|
222 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 case VAR_DICT: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
224 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
|
225 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 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
|
228 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
|
229 { |
22930
84567584951f
patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents:
22860
diff
changeset
|
230 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
|
231 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
|
232 else |
26948
51ddf6740ac6
patch 8.2.4003: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26913
diff
changeset
|
233 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
|
234 break; |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
235 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 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
|
237 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 #ifdef FEAT_JOB_CHANNEL |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
239 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
|
240 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 #ifdef FEAT_JOB_CHANNEL |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
244 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
|
245 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 case VAR_BLOB: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
248 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
|
249 break; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
250 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
251 emsg(_(e_using_class_as_number)); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
252 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
253 case VAR_OBJECT: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
254 emsg(_(e_using_object_as_number)); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 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
|
261 case VAR_INSTR: |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 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
|
263 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 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
|
266 n = -1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 *denote = TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 return n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 |
21851
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
272 /* |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
273 * 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
|
274 * 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
|
275 * 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
|
276 * 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
|
277 * 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
|
278 * 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
|
279 */ |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
280 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
|
281 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
|
282 { |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
283 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
|
284 |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
285 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
|
286 } |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
287 |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
288 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
|
289 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
|
290 { |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
291 return tv_get_bool_or_number_chk(varp, denote, FALSE); |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
292 } |
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 /* |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
295 * 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
|
296 * 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
|
297 */ |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
298 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
|
299 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
|
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 return tv_get_bool_or_number_chk(varp, NULL, TRUE); |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
302 } |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
303 |
21861
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
304 /* |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
305 * 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
|
306 * 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
|
307 */ |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
308 varnumber_T |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
309 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
|
310 { |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
311 return tv_get_bool_or_number_chk(varp, denote, TRUE); |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
312 } |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
313 |
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
|
314 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
|
315 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
|
316 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 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
|
321 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 return varp->vval.v_float; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 case VAR_PARTIAL: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
325 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
|
326 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 case VAR_STRING: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
328 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
|
329 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 case VAR_LIST: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
331 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
|
332 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 case VAR_DICT: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
334 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
|
335 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 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
|
337 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
|
338 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 case VAR_SPECIAL: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
340 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
|
341 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 # ifdef FEAT_JOB_CHANNEL |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
344 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
|
345 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 # ifdef FEAT_JOB_CHANNEL |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
349 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
|
350 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 case VAR_BLOB: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
353 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
|
354 break; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
355 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
356 emsg(_(e_using_class_as_float)); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
357 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
358 case VAR_OBJECT: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
359 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
|
360 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
|
361 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
|
362 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
|
363 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 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
|
366 case VAR_INSTR: |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 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
|
368 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 } |
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
|
370 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
|
371 *error = TRUE; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 return 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 } |
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
|
374 |
1cee572f2fd7
patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents:
26644
diff
changeset
|
375 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
|
376 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
|
377 { |
1cee572f2fd7
patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents:
26644
diff
changeset
|
378 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
|
379 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 /* |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
382 * 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
|
383 */ |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
384 int |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
385 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
|
386 { |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
387 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
|
388 { |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
389 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
|
390 return FAIL; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
391 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
392 return OK; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
393 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
394 |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28668
diff
changeset
|
395 /* |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
396 * 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
|
397 */ |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
398 int |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
399 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
|
400 { |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
401 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
|
402 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
403 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
|
404 return FAIL; |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
405 } |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
406 return OK; |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
407 } |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
408 |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
409 /* |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
410 * 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
|
411 */ |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
412 int |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
413 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
|
414 { |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 { |
24424 | 419 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
|
420 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
|
421 } |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
422 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
|
423 } |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
424 |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
425 /* |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
426 * 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
|
427 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
428 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
429 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
|
430 { |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
431 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
|
432 || 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
|
433 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
434 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
435 /* |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
436 * 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
|
437 */ |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
438 int |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
439 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
|
440 { |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
441 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
|
442 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
443 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
|
444 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
|
445 } |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
446 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
|
447 } |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
448 |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
449 /* |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
450 * 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
|
451 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
452 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
453 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
|
454 { |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
455 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
|
456 || 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
|
457 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
458 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
459 /* |
25368
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
460 * 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
|
461 */ |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
462 int |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
463 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
|
464 { |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
465 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
|
466 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
467 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
|
468 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
|
469 } |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
470 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
|
471 } |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
472 |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
473 /* |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
474 * 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
|
475 */ |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
476 int |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
477 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
|
478 { |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
479 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
|
480 && !(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
|
481 && (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
|
482 || 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
|
483 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
484 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
|
485 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
|
486 } |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
487 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
|
488 } |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
489 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
490 /* |
25802
5ef704de7709
patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
491 * 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
|
492 * 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
|
493 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
494 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
495 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
|
496 { |
25802
5ef704de7709
patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
497 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
|
498 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
|
499 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
|
500 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
501 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
502 /* |
25806
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
503 * 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
|
504 */ |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
505 int |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
506 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
|
507 { |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
508 if (args[idx].v_type != VAR_BLOB) |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
509 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
510 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
|
511 return FAIL; |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
512 } |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
513 return OK; |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
514 } |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
515 |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25802
diff
changeset
|
516 /* |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
517 * 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
|
518 */ |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
519 int |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
520 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
|
521 { |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
522 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
|
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 semsg(_(e_list_required_for_argument_nr), idx + 1); |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
525 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
|
526 } |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
527 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
|
528 } |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
529 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
530 /* |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
531 * 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
|
532 */ |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
533 int |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
534 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
|
535 { |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
536 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
|
537 return FAIL; |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
538 |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
539 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
|
540 { |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
541 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
|
542 return FAIL; |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
543 } |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
544 return OK; |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
545 } |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
546 |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
547 /* |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
548 * 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
|
549 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
550 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
551 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
|
552 { |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
553 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
|
554 || 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
|
555 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
556 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
557 /* |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
558 * 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
|
559 */ |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
560 int |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
561 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
|
562 { |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
563 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
|
564 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
565 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
|
566 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
|
567 } |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
568 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
|
569 } |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
570 |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
571 /* |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
572 * 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
|
573 */ |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
574 int |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
575 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
|
576 { |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
577 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
|
578 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
|
579 |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
580 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
|
581 { |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
582 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
|
583 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
|
584 } |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
585 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
|
586 } |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
587 |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
588 /* |
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 * 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
|
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 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
592 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
|
593 { |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
594 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
|
595 || 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
|
596 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
597 |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
598 #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
|
599 /* |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
600 * 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
|
601 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
602 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
603 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
|
604 { |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
605 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
|
606 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
607 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
|
608 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
|
609 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
610 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
|
611 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
612 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
613 /* |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
614 * 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
|
615 * job. |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
616 */ |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
617 int |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
618 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
|
619 { |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
620 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
|
621 || 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
|
622 } |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
623 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
624 /* |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
625 * 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
|
626 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
627 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
628 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
|
629 { |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
630 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
|
631 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
632 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
|
633 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
|
634 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
635 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
|
636 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
637 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
638 /* |
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
|
639 * 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
|
640 */ |
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
|
641 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
|
642 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
|
643 { |
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
|
644 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
|
645 || 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
|
646 } |
31289
4f1e70a709bb
patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
647 #else |
4f1e70a709bb
patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
648 /* |
4f1e70a709bb
patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
649 * 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
|
650 * 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
|
651 */ |
4f1e70a709bb
patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
652 int |
4f1e70a709bb
patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
653 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
|
654 { |
4f1e70a709bb
patch 9.0.0978: build errors without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
655 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
|
656 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
657 #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
|
658 |
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
|
659 /* |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
660 * 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
|
661 * 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
|
662 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
663 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
664 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
|
665 { |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
666 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
|
667 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
668 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
|
669 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
|
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 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
|
672 } |
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 /* |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
675 * 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
|
676 */ |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
677 int |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
678 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
|
679 { |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
680 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
|
681 || 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
|
682 } |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
683 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
684 /* |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
685 * 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
|
686 * 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
|
687 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
688 int |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
689 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
|
690 { |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
691 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
|
692 } |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
693 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
694 /* |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
695 * 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
|
696 */ |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
697 int |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
698 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
|
699 { |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
700 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
|
701 || 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
|
702 } |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
703 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
704 /* |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
705 * 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
|
706 * 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
|
707 */ |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
708 int |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
709 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
|
710 { |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
711 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
|
712 } |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
713 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
714 /* |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
715 * 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
|
716 */ |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
717 int |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
718 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
|
719 { |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
720 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
|
721 || 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
|
722 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
723 |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
724 #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
|
725 /* |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
726 * 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
|
727 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
728 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
|
729 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
|
730 { |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
731 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
|
732 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
733 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
|
734 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
|
735 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
736 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
|
737 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
738 #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
|
739 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
740 /* |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
741 * 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
|
742 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
743 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
|
744 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
|
745 { |
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 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
|
747 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
748 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
|
749 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
|
750 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
751 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
|
752 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
753 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
754 /* |
26638
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
755 * 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
|
756 * blob. |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
757 */ |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
758 int |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
759 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
|
760 { |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
761 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
|
762 && 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
|
763 && 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
|
764 { |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
765 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
|
766 return FAIL; |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
767 } |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
768 return OK; |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
769 } |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
770 |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
771 /* |
25368
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
772 * 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
|
773 */ |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
774 int |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
775 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
|
776 { |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
777 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
|
778 || 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
|
779 } |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
780 |
1ffa8eb30353
patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
781 /* |
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
|
782 * 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
|
783 */ |
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
|
784 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
|
785 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
|
786 { |
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
|
787 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
|
788 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
789 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
|
790 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
|
791 } |
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
|
792 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
|
793 } |
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
|
794 |
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
|
795 /* |
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
|
796 * 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
|
797 * 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
|
798 */ |
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
|
799 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
|
800 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
|
801 { |
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
|
802 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
|
803 && 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
|
804 && 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
|
805 { |
26638
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
806 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
|
807 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
|
808 } |
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
|
809 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
|
810 } |
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
|
811 |
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
|
812 /* |
25390
a6c347a0c6e3
patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
813 * 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
|
814 * 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
|
815 */ |
a6c347a0c6e3
patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
816 int |
a6c347a0c6e3
patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
817 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
|
818 { |
a6c347a0c6e3
patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
819 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
|
820 || 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
|
821 != 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
|
822 } |
a6c347a0c6e3
patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
823 |
a6c347a0c6e3
patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
824 /* |
30188
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
825 * 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
|
826 * 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
|
827 */ |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
828 int |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
829 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
|
830 { |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
831 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
|
832 && 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
|
833 && 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
|
834 && 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
|
835 { |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
836 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
|
837 return FAIL; |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
838 } |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
839 return OK; |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
840 } |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
841 |
ba22d5536d3e
patch 9.0.0430: cannot use repeat() with a blob
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
842 /* |
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
|
843 * 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
|
844 * 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
|
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 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
|
847 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
|
848 { |
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 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
|
850 && 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
|
851 && 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
|
852 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
853 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
|
854 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
|
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 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
|
857 } |
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
|
858 |
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
|
859 /* |
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
|
860 * 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
|
861 * 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
|
862 */ |
7f4cc4e58f75
patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents:
26696
diff
changeset
|
863 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
|
864 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
|
865 { |
7f4cc4e58f75
patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents:
26696
diff
changeset
|
866 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
|
867 && 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
|
868 && 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
|
869 { |
7f4cc4e58f75
patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents:
26696
diff
changeset
|
870 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
|
871 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
|
872 } |
7f4cc4e58f75
patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents:
26696
diff
changeset
|
873 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
|
874 } |
7f4cc4e58f75
patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents:
26696
diff
changeset
|
875 |
7f4cc4e58f75
patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents:
26696
diff
changeset
|
876 /* |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
877 * 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
|
878 */ |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
879 int |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
880 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
|
881 { |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
882 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
|
883 { |
26638
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26622
diff
changeset
|
884 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
|
885 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
|
886 } |
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 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
|
888 } |
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 /* |
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 * 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
|
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 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
|
894 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
|
895 { |
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 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
|
897 && 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
|
898 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
899 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
|
900 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
|
901 } |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
902 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
|
903 } |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
904 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
905 /* |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
906 * 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
|
907 * blob. |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
908 */ |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
909 int |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
910 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
|
911 { |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
912 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
|
913 && 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
|
914 && 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
|
915 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
916 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
|
917 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
|
918 } |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
919 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
|
920 } |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
921 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
922 /* |
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
|
923 * 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
|
924 * 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
|
925 */ |
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
926 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
|
927 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
|
928 { |
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
929 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
|
930 && 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
|
931 && 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
|
932 && 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
|
933 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
934 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
|
935 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
|
936 } |
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
937 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
|
938 } |
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
939 |
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
940 /* |
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
|
941 * 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
|
942 * 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
|
943 */ |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
944 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
|
945 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
|
946 { |
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
|
947 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
|
948 && 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
|
949 && 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
|
950 && 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
|
951 { |
26622
a28f91b893b2
patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
952 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
|
953 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
|
954 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
955 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
|
956 } |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
957 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25278
diff
changeset
|
958 /* |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 * 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
|
960 * 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
|
961 * 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
|
962 * 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
|
963 * 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
|
964 * Never returns NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 * 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
|
966 * NULL on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 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
|
970 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 static char_u mybuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 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
|
974 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 |
23786
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
976 /* |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
977 * 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
|
978 */ |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
979 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
|
980 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
|
981 { |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
982 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
|
983 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
|
984 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
|
985 |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
986 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
|
987 } |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
988 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 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
|
991 { |
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
|
992 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
|
993 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 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
|
995 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 * 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
|
999 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 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
|
1002 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 static char_u mybuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 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
|
1006 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 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
|
1010 { |
23786
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
1011 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
|
1012 } |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
1013 |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
1014 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
|
1015 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
|
1016 { |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 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
|
1020 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
|
1021 { |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
1022 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
|
1023 break; |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
1024 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 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
|
1026 (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
|
1027 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 case VAR_PARTIAL: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1030 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
|
1031 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 case VAR_LIST: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1033 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
|
1034 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 case VAR_DICT: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1036 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
|
1037 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 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
|
1039 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
|
1040 { |
26885
ed39730119bd
patch 8.2.3971: build fails
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1041 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
|
1042 break; |
b1093c1ac109
patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents:
24812
diff
changeset
|
1043 } |
b1093c1ac109
patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents:
24812
diff
changeset
|
1044 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
|
1045 return buf; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 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
|
1048 return varp->vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 return (char_u *)""; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 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
|
1053 return buf; |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
1054 case VAR_BLOB: |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1055 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
|
1056 break; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1057 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1058 emsg(_(e_using_class_as_string)); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1059 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1060 case VAR_OBJECT: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1061 emsg(_(e_using_object_as_string)); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1062 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 #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
|
1065 if (in_vim9script()) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 { |
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
|
1067 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
|
1068 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 } |
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
|
1070 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
|
1071 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 #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
|
1075 if (in_vim9script()) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 { |
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
|
1077 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
|
1078 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 } |
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
|
1080 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
|
1081 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 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
|
1083 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
|
1084 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
|
1085 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 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
|
1088 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
|
1089 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
|
1090 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
|
1091 break; |
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 return NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 * 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
|
1098 * string() on Dict, List, etc. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 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
|
1102 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 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
|
1104 || varp->v_type == VAR_DICT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 || varp->v_type == VAR_BLOB |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 || varp->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 || varp->v_type == VAR_PARTIAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 || varp->v_type == VAR_FLOAT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 typval_T tmp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 f_string(varp, &tmp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 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
|
1114 clear_tv(varp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 *varp = tmp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 return tmp.vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 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
|
1119 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 * 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
|
1123 * 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
|
1124 * TRUE. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 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
|
1128 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 int lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 switch (tv->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 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
|
1135 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
|
1136 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 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
|
1139 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
|
1140 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 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
|
1143 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
|
1144 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 default: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 } |
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
|
1148 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
|
1149 || (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
|
1150 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 * 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
|
1154 * 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
|
1155 * 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
|
1156 * 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
|
1157 * make a copy later. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 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
|
1161 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 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
|
1163 to->v_lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 switch (from->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 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
|
1170 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 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
|
1173 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 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
|
1177 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
|
1178 ++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
|
1179 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 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
|
1184 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
|
1185 ++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
|
1186 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 #endif |
24606
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
24424
diff
changeset
|
1188 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
|
1189 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
|
1190 break; |
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
24424
diff
changeset
|
1191 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1192 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1193 copy_class(from, to); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1194 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1195 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1196 case VAR_OBJECT: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1197 copy_object(from, to); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1198 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1199 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 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
|
1203 to->vval.v_string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 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
|
1207 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
|
1208 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
|
1209 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 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
|
1213 to->vval.v_partial = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 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
|
1217 ++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
|
1218 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 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
|
1222 to->vval.v_blob = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 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
|
1226 ++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
|
1227 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 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
|
1231 to->vval.v_list = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 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
|
1235 ++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
|
1236 } |
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 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 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
|
1240 to->vval.v_dict = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 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
|
1244 ++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
|
1245 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 break; |
24940
0c415a0f54f9
patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents:
24936
diff
changeset
|
1247 case VAR_VOID: |
0c415a0f54f9
patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents:
24936
diff
changeset
|
1248 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
|
1249 break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 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
|
1253 break; |
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 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 /* |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1258 * 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
|
1259 * 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
|
1260 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 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
|
1263 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
|
1264 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
|
1265 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
|
1266 int ic) // ignore case |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 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
|
1269 int res = 0; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 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
|
1271 |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1272 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
|
1273 { |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29525
diff
changeset
|
1274 // 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
|
1275 // it means TRUE. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 n1 = (type == EXPR_ISNOT); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 } |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1278 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
|
1279 || (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
|
1280 && 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
|
1281 && 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
|
1282 && (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
|
1283 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1284 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
|
1285 if (n1 == MAYBE) |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1286 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1287 clear_tv(tv1); |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1288 return FAIL; |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1289 } |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1290 if (type == EXPR_NEQUAL) |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1291 n1 = !n1; |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1292 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1293 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
|
1294 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1295 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
|
1296 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1297 clear_tv(tv1); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1300 n1 = res; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1302 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
|
1303 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1304 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
|
1305 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1306 clear_tv(tv1); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1309 n1 = res; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1311 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
|
1312 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1313 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
|
1314 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1315 clear_tv(tv1); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1318 n1 = res; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1320 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
|
1321 || 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
|
1322 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1323 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
|
1324 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1325 clear_tv(tv1); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1328 n1 = res; |
20587
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 // 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
|
1332 // 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
|
1333 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
|
1334 && 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
|
1335 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 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
|
1337 int error = FALSE; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 |
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
|
1339 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
|
1340 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
|
1341 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
|
1342 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
|
1343 { |
1cee572f2fd7
patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents:
26644
diff
changeset
|
1344 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
|
1345 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
|
1346 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 n1 = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 switch (type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 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
|
1352 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 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
|
1354 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
|
1355 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
|
1356 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
|
1357 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
|
1358 case EXPR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 } |
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 // 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
|
1365 // 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
|
1366 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
|
1367 && 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
|
1368 { |
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
|
1369 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
|
1370 |
1cee572f2fd7
patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents:
26644
diff
changeset
|
1371 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
|
1372 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
|
1373 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
|
1374 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
|
1375 { |
1cee572f2fd7
patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents:
26644
diff
changeset
|
1376 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
|
1377 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
|
1378 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 switch (type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 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
|
1383 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 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
|
1385 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
|
1386 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
|
1387 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
|
1388 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
|
1389 case EXPR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1394 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
|
1395 || 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
|
1396 || (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
|
1397 && 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
|
1398 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1399 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
|
1400 { |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
1401 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
|
1402 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
|
1403 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
|
1404 return FAIL; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
1405 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1406 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
|
1407 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
|
1408 switch (type) |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
1409 { |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
1410 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
|
1411 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
|
1412 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
|
1413 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
|
1414 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
|
1415 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
|
1416 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
|
1417 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
|
1418 return FAIL; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
1419 } |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
1420 } |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28103
diff
changeset
|
1421 #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
|
1422 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
|
1423 && (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
|
1424 && (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
|
1425 { |
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28103
diff
changeset
|
1426 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
|
1427 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
|
1428 else |
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28103
diff
changeset
|
1429 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
|
1430 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
|
1431 n1 = !n1; |
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28103
diff
changeset
|
1432 } |
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28103
diff
changeset
|
1433 #endif |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1436 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
|
1437 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1438 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
|
1439 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
|
1440 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1441 n1 = res; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 } |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1443 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
|
1444 if (in_vim9script()) |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1445 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1446 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
|
1447 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
|
1448 } |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1449 else |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1450 { |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1451 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
|
1452 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
|
1453 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 |
23788
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
1458 /* |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30761
diff
changeset
|
1459 * 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
|
1460 * 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
|
1461 * 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
|
1462 */ |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1463 int |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1464 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
|
1465 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
|
1466 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
|
1467 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
|
1468 int ic, |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1469 int *res) |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1470 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1471 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
|
1472 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1473 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
|
1474 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1475 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
|
1476 && 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
|
1477 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
|
1478 val = !val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1479 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1480 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
|
1481 || (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
|
1482 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1483 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
|
1484 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
|
1485 else |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1486 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
|
1487 return FAIL; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1488 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1489 else |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1490 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1491 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
|
1492 ic, FALSE); |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1493 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
|
1494 val = !val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1495 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1496 *res = val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1497 return OK; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1498 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1499 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1500 /* |
28011
d10d5cc8e657
patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents:
27928
diff
changeset
|
1501 * 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
|
1502 */ |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1503 int |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1504 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
|
1505 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1506 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
|
1507 || (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
|
1508 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1509 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
|
1510 |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1511 switch (tv->v_type) |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1512 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1513 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
|
1514 #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
|
1515 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
|
1516 #endif |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1517 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
|
1518 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
|
1519 #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
|
1520 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
|
1521 #endif |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1522 case VAR_LIST: return tv->vval.v_list == NULL; |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1523 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
|
1524 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
|
1525 |
ca7a207d83cd
patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents:
27926
diff
changeset
|
1526 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
|
1527 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
|
1528 break; |
ca7a207d83cd
patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents:
27926
diff
changeset
|
1529 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
|
1530 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
|
1531 break; |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1532 default: break; |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1533 } |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1534 } |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28103
diff
changeset
|
1535 // 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
|
1536 // 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
|
1537 return FALSE; |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1538 } |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1539 |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27034
diff
changeset
|
1540 /* |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30761
diff
changeset
|
1541 * 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
|
1542 * 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
|
1543 * 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
|
1544 */ |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1545 int |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1546 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
|
1547 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
|
1548 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
|
1549 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
|
1550 int *res) |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1551 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1552 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
|
1553 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1554 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
|
1555 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1556 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
|
1557 && 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
|
1558 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
|
1559 val = !val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1560 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1561 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
|
1562 || (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
|
1563 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1564 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
|
1565 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
|
1566 else |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26782
diff
changeset
|
1567 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
|
1568 return FAIL; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1569 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1570 else |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1571 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1572 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
|
1573 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
|
1574 val = !val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1575 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1576 *res = val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1577 return OK; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1578 } |
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 /* |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30761
diff
changeset
|
1581 * 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
|
1582 * 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
|
1583 * 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
|
1584 */ |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1585 int |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1586 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
|
1587 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
|
1588 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
|
1589 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
|
1590 int ic, |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1591 int *res) |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1592 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1593 int val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1594 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1595 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
|
1596 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1597 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
|
1598 && 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
|
1599 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
|
1600 val = !val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1601 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1602 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
|
1603 || (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
|
1604 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1605 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
|
1606 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
|
1607 else |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1608 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
|
1609 return FAIL; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1610 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1611 else |
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 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
|
1614 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
|
1615 val = !val; |
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 *res = val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1618 return OK; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1619 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1620 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1621 /* |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30761
diff
changeset
|
1622 * 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
|
1623 * 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
|
1624 * 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
|
1625 */ |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1626 int |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1627 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
|
1628 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
|
1629 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
|
1630 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
|
1631 int ic, |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1632 int *res) |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1633 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1634 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
|
1635 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1636 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
|
1637 && 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
|
1638 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1639 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
|
1640 return FAIL; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1641 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1642 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
|
1643 || (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
|
1644 // 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
|
1645 // 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
|
1646 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
|
1647 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
|
1648 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1649 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
|
1650 // 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
|
1651 // the same |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1652 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
|
1653 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
|
1654 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
|
1655 else |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1656 val = FALSE; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1657 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1658 else |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1659 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
|
1660 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
|
1661 val = !val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1662 *res = val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1663 return OK; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1664 } |
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 /* |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1667 * 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
|
1668 * 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
|
1669 * 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
|
1670 */ |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1671 int |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1672 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
|
1673 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
|
1674 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
|
1675 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
|
1676 int ic, |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1677 int *res) |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1678 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1679 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
|
1680 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
|
1681 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
|
1682 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
|
1683 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1684 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
|
1685 && ((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
|
1686 || (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
|
1687 { |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1688 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
|
1689 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
|
1690 return FAIL; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1691 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1692 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
|
1693 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
|
1694 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
|
1695 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
|
1696 switch (type) |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1697 { |
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
|
1698 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
|
1699 { |
53e2bf6032e5
patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents:
28011
diff
changeset
|
1700 // 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
|
1701 // 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
|
1702 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
|
1703 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
|
1704 } |
53e2bf6032e5
patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents:
28011
diff
changeset
|
1705 // FALLTHROUGH |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1706 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
|
1707 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
|
1708 { |
53e2bf6032e5
patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents:
28011
diff
changeset
|
1709 // 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
|
1710 // 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
|
1711 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
|
1712 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
|
1713 } |
53e2bf6032e5
patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents:
28011
diff
changeset
|
1714 // FALLTHROUGH |
26644
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1715 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
|
1716 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
|
1717 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
|
1718 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
|
1719 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
|
1720 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1721 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
|
1722 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
|
1723 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
|
1724 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
|
1725 val = !val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1726 break; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1727 |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1728 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
|
1729 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1730 *res = val; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1731 return OK; |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1732 } |
2fc1e528e0e1
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
1733 /* |
23788
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
1734 * 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
|
1735 * 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
|
1736 * 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
|
1737 */ |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 char_u * |
23788
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
1739 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
|
1740 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 char_u *tofree; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 char_u numbuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 char_u *ret = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1745 if (arg == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 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
|
1747 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
|
1748 { |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
1749 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
|
1750 : 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
|
1751 } |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
1752 else |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
1753 { |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
1754 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
|
1755 // 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
|
1756 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
|
1757 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
|
1758 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 return ret; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 * 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
|
1764 * 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
|
1765 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1767 tv_islocked(typval_T *tv) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 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
|
1770 || (tv->v_type == VAR_LIST |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 && tv->vval.v_list != NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 && (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
|
1773 || (tv->v_type == VAR_DICT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 && tv->vval.v_dict != NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 && (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
|
1776 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 static int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 func_equal( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 typval_T *tv1, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 typval_T *tv2, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 int ic) // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 dict_T *d1, *d2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 int a1, a2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 int i; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 // 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
|
1790 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
|
1791 : 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
|
1792 if (s1 != NULL && *s1 == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 s1 = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1794 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
|
1795 : 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
|
1796 if (s2 != NULL && *s2 == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1797 s2 = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1798 if (s1 == NULL || s2 == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1800 if (s1 != s2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1801 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1802 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 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
|
1804 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1806 // 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
|
1807 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
|
1808 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
|
1809 if (d1 == NULL || d2 == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 if (d1 != d2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1812 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 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
|
1815 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 // 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
|
1818 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
|
1819 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
|
1820 if (a1 != a2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 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
|
1823 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
|
1824 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
|
1825 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 return TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 * 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
|
1832 * 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
|
1833 * 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
|
1834 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 tv_equal( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 typval_T *tv1, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 typval_T *tv2, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1839 int ic, // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1840 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
|
1841 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 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
|
1843 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 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
|
1845 int r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1846 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
|
1847 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 // 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
|
1849 // 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
|
1850 // 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
|
1851 // 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
|
1852 // 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
|
1853 // recursiveness quickly. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 if (!recursive) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 tv_equal_recurse_limit = 1000; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 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
|
1857 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1858 --tv_equal_recurse_limit; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 return TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 // 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
|
1863 // arguments. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1864 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
|
1865 || (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
|
1866 && (tv2->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 || (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
|
1868 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1869 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1870 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
|
1871 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 |
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
|
1875 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
|
1876 && ((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
|
1877 || (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
|
1878 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 switch (tv1->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 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
|
1885 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 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
|
1891 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 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
|
1896 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 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
|
1901 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 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
|
1904 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
|
1905 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
|
1906 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 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
|
1909 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 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
|
1912 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 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
|
1916 #endif |
24606
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
24424
diff
changeset
|
1917 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
|
1918 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
|
1919 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1920 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1921 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
|
1922 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1923 case VAR_OBJECT: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1924 // TODO: compare values |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1925 return tv1->vval.v_object == tv2->vval.v_object; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31289
diff
changeset
|
1926 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 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
|
1929 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 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
|
1932 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 // 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
|
1940 // 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
|
1941 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1942 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 * Get an option value. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 * "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
|
1947 * "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
|
1948 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 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
|
1951 eval_option( |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1952 char_u **arg, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 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
|
1954 int evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1956 char_u *option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 long numval; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 char_u *stringval; |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1959 getoption_T opt_type; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1960 int c; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1961 int working = (**arg == '+'); // has("+option") |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 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
|
1963 int scope; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 // 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
|
1966 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
|
1967 if (option_end == NULL) |
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 if (rettv != NULL) |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
1970 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
|
1971 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 if (!evaluate) |
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 *arg = option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 c = *option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 *option_end = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 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
|
1983 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
|
1984 |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1985 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
|
1986 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 if (rettv != NULL) |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
1988 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
|
1989 ret = FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1990 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 else if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1992 { |
23519
cb66613dd9d5
patch 8.2.2302: Vim9: using an option value may use uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
1993 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
|
1994 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
|
1995 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 rettv->vval.v_string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 } |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1999 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
|
2000 { |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2001 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
|
2002 ? VAR_BOOL : VAR_NUMBER; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 rettv->vval.v_number = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 } |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2005 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
|
2006 { |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2007 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
|
2008 { |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2009 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
|
2010 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
|
2011 } |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2012 else |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2013 { |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2014 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
|
2015 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
|
2016 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2017 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2018 else // string option |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2020 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 rettv->vval.v_string = stringval; |
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 } |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
2024 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
|
2025 || 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
|
2026 || 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
|
2027 ret = FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2028 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 *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
|
2030 *arg = option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2031 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2032 return ret; |
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2035 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 * 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
|
2037 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2039 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
|
2040 eval_number( |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2041 char_u **arg, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2042 typval_T *rettv, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 int evaluate, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2044 int want_string UNUSED) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 int len; |
25622
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25585
diff
changeset
|
2047 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
|
2048 char_u *p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 int get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 // 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
|
2052 // "[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
|
2053 // 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
|
2054 // 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
|
2055 // omitted. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2056 // 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
|
2057 // ":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
|
2058 if (**arg == '.') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 p = *arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 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
|
2061 { |
763ea8f075db
patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents:
25443
diff
changeset
|
2062 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
|
2063 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
|
2064 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
|
2065 { |
763ea8f075db
patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents:
25443
diff
changeset
|
2066 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
|
2067 ++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
|
2068 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
|
2069 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
|
2070 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
|
2071 } |
763ea8f075db
patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents:
25443
diff
changeset
|
2072 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
|
2073 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
|
2074 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 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
|
2076 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2077 get_float = TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2078 p = skipdigits(p + 2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2079 if (*p == 'e' || *p == 'E') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 if (*p == '-' || *p == '+') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2083 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2084 if (!vim_isdigit(*p)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 p = skipdigits(p + 1); |
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 if (ASCII_ISALPHA(*p) || *p == '.') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 if (get_float) |
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 float_T f; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 |
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
|
2096 *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
|
2097 if (evaluate) |
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 rettv->v_type = VAR_FLOAT; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 rettv->vval.v_float = f; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2103 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2104 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
|
2105 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2106 char_u *bp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2107 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
|
2108 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 // Blob constant: 0z0123456789abcdef |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 blob = blob_alloc(); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 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
|
2113 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 if (!vim_isxdigit(bp[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2115 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2118 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
|
2119 ga_clear(&blob->bv_ga); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2120 VIM_CLEAR(blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2121 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2122 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2125 ga_append(&blob->bv_ga, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2126 (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
|
2127 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
|
2128 ++bp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2129 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2131 rettv_blob_set(rettv, blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 *arg = bp; |
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 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 varnumber_T n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 // 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
|
2139 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
|
2140 ? STR2NR_NO_OCT + STR2NR_QUOTE |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2141 : STR2NR_ALL, &n, NULL, 0, TRUE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 if (len == 0) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 { |
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
|
2144 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
|
2145 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
|
2146 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 *arg += len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2150 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2151 rettv->v_type = VAR_NUMBER; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2152 rettv->vval.v_number = n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2153 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2154 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2155 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2156 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2157 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2158 /* |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2159 * 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
|
2160 * "*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
|
2161 * 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
|
2162 * at a single "{". |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2163 * Return OK or FAIL. |
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 int |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2166 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
|
2167 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2168 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
|
2169 char_u *end; |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2170 int extra = interpolate ? 1 : 0; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2171 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
|
2172 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2173 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2174 // 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
|
2175 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
|
2176 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 if (*p == '\\' && p[1] != NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2178 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2179 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2180 // 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
|
2181 // 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
|
2182 // 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
|
2183 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
|
2184 { |
5063dfe96a59
patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents:
28821
diff
changeset
|
2185 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
|
2186 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
|
2187 |
28668
53c608c7ea9e
patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
2188 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
|
2189 |
5063dfe96a59
patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents:
28821
diff
changeset
|
2190 // 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
|
2191 // interpolation. |
5063dfe96a59
patch 9.0.0104: going beyond allocated memory when evaluating string constant
Bram Moolenaar <Bram@vim.org>
parents:
28821
diff
changeset
|
2192 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
|
2193 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
|
2194 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
|
2195 --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
|
2196 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2197 } |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2198 else if (interpolate && (*p == '{' || *p == '}')) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2199 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2200 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
|
2201 break; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2202 ++p; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2203 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
|
2204 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2205 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
|
2206 return FAIL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2207 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2208 --extra; // "{{" becomes "{", "}}" becomes "}" |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2209 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2210 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2211 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2212 if (*p != '"' && !(interpolate && *p == '{')) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 { |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
2214 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
|
2215 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2217 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2218 // 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
|
2219 if (!evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2220 { |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2221 *arg = p + off; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2222 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2223 } |
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 // 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
|
2226 // characters. |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2227 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
|
2228 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
|
2229 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
|
2230 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
|
2231 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
|
2232 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
|
2233 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2234 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
|
2235 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 if (*p == '\\') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 switch (*++p) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2240 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
|
2241 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
|
2242 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
|
2243 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
|
2244 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
|
2245 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
|
2246 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2247 case 'X': // hex: "\x1", "\x12" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 case 'x': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 case 'u': // Unicode: "\u0023" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2250 case 'U': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 if (vim_isxdigit(p[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 int n, nr; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 int c = toupper(*p); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2256 if (c == 'X') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 n = 2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 else if (*p == 'u') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 n = 4; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2261 n = 8; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 nr = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 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
|
2264 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 nr = (nr << 4) + hex2nr(*p); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2267 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 // 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
|
2270 // 'encoding'. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2271 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
|
2272 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
|
2273 else |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2274 *end++ = nr; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2275 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2277 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2278 // octal: "\1", "\12", "\123" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2279 case '0': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2280 case '1': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 case '2': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 case '3': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2283 case '4': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2284 case '5': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2285 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
|
2286 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
|
2287 if (*p >= '0' && *p <= '7') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2288 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2289 *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
|
2290 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
|
2291 *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
|
2292 } |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2293 ++end; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2294 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2295 |
20627
8bce783af0cb
patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents:
20603
diff
changeset
|
2296 // 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
|
2297 case '<': |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2298 { |
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
|
2299 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
|
2300 |
20627
8bce783af0cb
patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents:
20603
diff
changeset
|
2301 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
|
2302 flags |= FSK_SIMPLIFY; |
28668
53c608c7ea9e
patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
2303 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
|
2304 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
|
2305 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2306 end += extra; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2307 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
|
2308 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
|
2309 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
|
2310 } |
20587
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 // FALLTHROUGH |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2313 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2314 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
|
2315 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2316 } |
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 else |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2319 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2320 if (interpolate && (*p == '{' || *p == '}')) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2321 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2322 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
|
2323 break; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2324 ++p; // reduce "{{" to "{" and "}}" to "}" |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2325 } |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2326 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
|
2327 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 } |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
2329 *end = NUL; |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2330 if (*p == '"' && !interpolate) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 *arg = p; |
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 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2335 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2336 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2337 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2338 * 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
|
2339 * 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
|
2340 * 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
|
2341 * 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
|
2342 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2343 int |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2344 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
|
2345 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2346 char_u *p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2347 char_u *str; |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2348 int reduce = interpolate ? -1 : 0; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2349 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
|
2350 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2351 // 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
|
2352 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
|
2353 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2354 if (*p == '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2355 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2356 if (p[1] != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2357 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2358 ++reduce; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2359 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2360 } |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2361 else if (interpolate) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2362 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2363 if (*p == '{') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2364 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2365 if (p[1] != '{') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2366 break; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2367 ++p; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2368 ++reduce; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2369 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2370 else if (*p == '}') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2371 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2372 ++p; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2373 if (*p != '}') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2374 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2375 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
|
2376 return FAIL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2377 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2378 ++reduce; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2379 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2380 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2381 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2382 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2383 if (*p != '\'' && !(interpolate && *p == '{')) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2384 { |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
2385 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
|
2386 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2387 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2388 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2389 // 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
|
2390 if (!evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2391 { |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2392 *arg = p + off; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2393 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2394 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2395 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2396 // 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
|
2397 // any expressions. |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2398 str = alloc((p - *arg) - reduce); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2399 if (str == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2400 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2401 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2402 rettv->vval.v_string = str; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2403 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2404 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
|
2405 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2406 if (*p == '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2407 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2408 if (p[1] != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2409 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2410 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2411 } |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2412 else if (interpolate && (*p == '{' || *p == '}')) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2413 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2414 if (*p == '{' && p[1] != '{') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2415 break; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2416 ++p; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2417 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2418 MB_COPY_CHAR(p, str); |
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 *str = NUL; |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2421 *arg = p + off; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2422 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2423 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2424 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2425 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2426 /* |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2427 * 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
|
2428 * "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
|
2429 * Returns OK or FAIL. |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2430 */ |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2431 int |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2432 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
|
2433 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2434 typval_T tv; |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2435 int ret = OK; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2436 int quote; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2437 garray_T ga; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2438 char_u *p; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2439 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2440 ga_init2(&ga, 1, 80); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2441 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2442 // *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
|
2443 ++*arg; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2444 quote = **arg; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2445 ++*arg; |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2446 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2447 for (;;) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2448 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2449 // 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
|
2450 // "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
|
2451 if (quote == '"') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2452 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
|
2453 else |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2454 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
|
2455 if (ret == FAIL) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2456 break; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2457 if (evaluate) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2458 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2459 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
|
2460 clear_tv(&tv); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2461 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2462 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2463 if (**arg != '{') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2464 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2465 // found terminating quote |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2466 ++*arg; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2467 break; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2468 } |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
2469 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
|
2470 if (p == NULL) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2471 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2472 ret = FAIL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2473 break; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2474 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2475 *arg = p; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2476 } |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2477 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2478 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
|
2479 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
|
2480 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2481 ga_clear(&ga); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2482 rettv->vval.v_string = NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2483 return ret; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2484 } |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2485 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2486 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
|
2487 return OK; |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2488 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
2489 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2490 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2491 * 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
|
2492 * 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
|
2493 * "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
|
2494 * 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
|
2495 * May return NULL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2496 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2497 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2498 tv2string( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2499 typval_T *tv, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2500 char_u **tofree, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2501 char_u *numbuf, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2502 int copyID) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2503 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2504 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
|
2505 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2506 |
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 * 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
|
2509 * "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
|
2510 * 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
|
2511 * 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
|
2512 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2513 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
|
2514 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
|
2515 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2516 char_u *string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2517 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2518 int cc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2519 char_u *name; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2520 int mustfree = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2521 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2522 ++*arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2523 name = *arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2524 len = get_env_len(arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2525 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2526 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2527 if (len == 0) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2528 return FAIL; // invalid empty name |
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 cc = name[len]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2531 name[len] = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2532 // 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
|
2533 string = vim_getenv(name, &mustfree); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2534 if (string != NULL && *string != NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2535 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2536 if (!mustfree) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2537 string = vim_strsave(string); |
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 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2540 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2541 if (mustfree) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2542 vim_free(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2543 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2544 // 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
|
2545 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
|
2546 if (string != NULL && *string == '$') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2547 VIM_CLEAR(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2548 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2549 name[len] = cc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2550 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2551 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2552 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
|
2553 rettv->v_lock = 0; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2554 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2555 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2556 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2557 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2558 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2559 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2560 * 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
|
2561 * 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
|
2562 * Returns -1 on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2563 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2564 linenr_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2565 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
|
2566 { |
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
|
2567 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
|
2568 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
|
2569 |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
2570 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
|
2571 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
|
2572 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
|
2573 && 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
|
2574 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2575 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
|
2576 pos_T *fp; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2577 |
24260
ad065f64eb20
patch 8.2.2671: error for line number in legacy script
Bram Moolenaar <Bram@vim.org>
parents:
24258
diff
changeset
|
2578 // 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
|
2579 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
|
2580 if (fp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2581 lnum = fp->lnum; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2582 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2583 return lnum; |
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2586 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2587 * 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
|
2588 * 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
|
2589 * Returns 0 on error. |
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 linenr_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2592 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
|
2593 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2594 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
|
2595 && 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
|
2596 && 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
|
2597 && 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
|
2598 && buf != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2599 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
|
2600 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
|
2601 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2602 |
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 * 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
|
2605 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2606 buf_T * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2607 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
|
2608 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2609 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
|
2610 buf_T *buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2611 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2612 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
|
2613 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
|
2614 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
|
2615 return NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2616 if (name == NULL || *name == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2617 return curbuf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2618 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
|
2619 return lastbuf; |
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 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
|
2622 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2623 // 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
|
2624 if (buf == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2625 buf = find_buffer(tv); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2626 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2627 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2628 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2629 |
22025
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
2630 /* |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
2631 * 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
|
2632 */ |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
2633 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
|
2634 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
|
2635 { |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
2636 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
|
2637 |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
2638 ++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
|
2639 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
|
2640 --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
|
2641 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
|
2642 && 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
|
2643 && 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
|
2644 // 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
|
2645 (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
|
2646 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
|
2647 } |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
2648 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2649 #endif // FEAT_EVAL |