annotate src/vim9type.c @ 25425:effe5f2b4d01 v8.2.3249

patch 8.2.3249: Vim9: error for re-imported function with default argument Commit: https://github.com/vim/vim/commit/60dc8274e9f8c6a20d54efebc7a8752fe062eead Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 29 22:48:54 2021 +0200 patch 8.2.3249: Vim9: error for re-imported function with default argument Problem: Vim9: error for re-imported function with default argument. Solution: Do not check argument type if it is still unknown. (closes https://github.com/vim/vim/issues/8653)
author Bram Moolenaar <Bram@vim.org>
date Thu, 29 Jul 2021 23:00:04 +0200
parents cfbf40f749b0
children b8a6a0007dc3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * vim9type.c: handling of types
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #define USING_FLOAT_STUFF
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 #ifdef VMS
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 # include <float.h>
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 #endif
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * Allocate memory for a type_T and add the pointer to type_gap, so that it can
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
25 * be easily freed later.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 */
22184
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
27 type_T *
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
28 get_type_ptr(garray_T *type_gap)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 if (ga_grow(type_gap, 1) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 return NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 type = ALLOC_CLEAR_ONE(type_T);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 if (type != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 ((type_T **)type_gap->ga_data)[type_gap->ga_len] = type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 ++type_gap->ga_len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 clear_type_list(garray_T *gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 while (gap->ga_len > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 vim_free(((type_T **)gap->ga_data)[--gap->ga_len]);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 ga_clear(gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
51 /*
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
52 * Take a type that is using entries in a growarray and turn it into a type
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
53 * with allocated entries.
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
54 */
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
55 type_T *
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
56 alloc_type(type_T *type)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
57 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
58 type_T *ret;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
59
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
60 if (type == NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
61 return NULL;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
62
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
63 // A fixed type never contains allocated types, return as-is.
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
64 if (type->tt_flags & TTFLAG_STATIC)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
65 return type;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
66
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
67 ret = ALLOC_ONE(type_T);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
68 *ret = *type;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
69
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
70 if (ret->tt_member != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
71 ret->tt_member = alloc_type(ret->tt_member);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
72 if (type->tt_args != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
73 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
74 int i;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
75
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
76 ret->tt_args = ALLOC_MULT(type_T *, type->tt_argcount);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
77 if (ret->tt_args != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
78 for (i = 0; i < type->tt_argcount; ++i)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
79 ret->tt_args[i] = alloc_type(type->tt_args[i]);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
80 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
81
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
82 return ret;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
83 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
84
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
85 /*
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
86 * Free a type that was created with alloc_type().
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
87 */
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
88 void
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
89 free_type(type_T *type)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
90 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
91 int i;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
92
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
93 if (type == NULL || (type->tt_flags & TTFLAG_STATIC))
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
94 return;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
95 if (type->tt_args != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
96 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
97 for (i = 0; i < type->tt_argcount; ++i)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
98 free_type(type->tt_args[i]);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
99 vim_free(type->tt_args);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
100 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
101 free_type(type->tt_member);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
102 vim_free(type);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
103 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
104
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 get_list_type(type_T *member_type, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 // recognize commonly used types
22804
af26fadf333d patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
111 if (member_type == NULL || member_type->tt_type == VAR_ANY)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 return &t_list_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 if (member_type->tt_type == VAR_VOID
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 || member_type->tt_type == VAR_UNKNOWN)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 return &t_list_empty;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 if (member_type->tt_type == VAR_BOOL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 return &t_list_bool;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if (member_type->tt_type == VAR_NUMBER)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 return &t_list_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 if (member_type->tt_type == VAR_STRING)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 return &t_list_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 // Not a common type, create a new entry.
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
124 type = get_type_ptr(type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 if (type == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 type->tt_type = VAR_LIST;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 type->tt_member = member_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 type->tt_argcount = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 type->tt_args = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 get_dict_type(type_T *member_type, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 // recognize commonly used types
22804
af26fadf333d patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
140 if (member_type == NULL || member_type->tt_type == VAR_ANY)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 return &t_dict_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 if (member_type->tt_type == VAR_VOID
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 || member_type->tt_type == VAR_UNKNOWN)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 return &t_dict_empty;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 if (member_type->tt_type == VAR_BOOL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 return &t_dict_bool;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 if (member_type->tt_type == VAR_NUMBER)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 return &t_dict_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 if (member_type->tt_type == VAR_STRING)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 return &t_dict_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 // Not a common type, create a new entry.
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
153 type = get_type_ptr(type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 if (type == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 type->tt_type = VAR_DICT;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 type->tt_member = member_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 type->tt_argcount = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 type->tt_args = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 * Allocate a new type for a function.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 alloc_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 {
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
169 type_T *type = get_type_ptr(type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 if (type == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 type->tt_type = VAR_FUNC;
24996
0136c6ee1961 patch 8.2.3035: Vim9: crash when calling :def function with partial
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
174 type->tt_member = ret_type == NULL ? &t_unknown : ret_type;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 type->tt_argcount = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 type->tt_args = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 * Get a function type, based on the return type "ret_type".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 * If "argcount" is -1 or 0 a predefined type can be used.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 * If "argcount" > 0 always create a new type, so that arguments can be added.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 get_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 // recognize commonly used types
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 if (argcount <= 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 {
24996
0136c6ee1961 patch 8.2.3035: Vim9: crash when calling :def function with partial
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
191 if (ret_type == &t_unknown || ret_type == NULL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 // (argcount == 0) is not possible
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 return &t_func_unknown;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 if (ret_type == &t_void)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 return &t_func_0_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 return &t_func_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 if (ret_type == &t_any)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 return &t_func_0_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 return &t_func_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 if (ret_type == &t_number)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 return &t_func_0_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 return &t_func_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 if (ret_type == &t_string)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 return &t_func_0_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 return &t_func_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 return alloc_func_type(ret_type, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 * For a function type, reserve space for "argcount" argument types (including
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 * vararg).
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 int
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 func_type_add_arg_types(
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 type_T *functype,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 int argcount,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 // To make it easy to free the space needed for the argument types, add the
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 // pointer to type_gap.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 if (ga_grow(type_gap, 1) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 return FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 functype->tt_args = ALLOC_CLEAR_MULT(type_T *, argcount);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 if (functype->tt_args == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 return FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 ((type_T **)type_gap->ga_data)[type_gap->ga_len] =
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 (void *)functype->tt_args;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 ++type_gap->ga_len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 return OK;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 * Get a type_T for a typval_T.
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
254 * "type_gap" is used to temporarily create types in.
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
255 * When "do_member" is TRUE also get the member type, otherwise use "any".
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 */
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
257 static type_T *
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
258 typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 {
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
260 type_T *type;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
261 type_T *member_type = &t_any;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
262 int argcount = 0;
25126
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
263 int min_argcount = 0;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 if (tv->v_type == VAR_NUMBER)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 return &t_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 if (tv->v_type == VAR_BOOL)
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
268 return &t_bool;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 if (tv->v_type == VAR_STRING)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 return &t_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 if (tv->v_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 {
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
274 list_T *l = tv->vval.v_list;
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
275 listitem_T *li;
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
276
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
277 if (l == NULL || l->lv_first == NULL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 return &t_list_empty;
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
279 if (!do_member)
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
280 return &t_list_any;
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
281 if (l->lv_first == &range_list_item)
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
282 return &t_list_number;
24160
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
283 if (l->lv_copyID == copyID)
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
284 // avoid recursion
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
285 return &t_list_any;
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
286 l->lv_copyID = copyID;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
288 // Use the common type of all members.
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
289 member_type = typval2type(&l->lv_first->li_tv, copyID, type_gap, TRUE);
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
290 for (li = l->lv_first->li_next; li != NULL; li = li->li_next)
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
291 common_type(typval2type(&li->li_tv, copyID, type_gap, TRUE),
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
292 member_type, &member_type, type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 return get_list_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 if (tv->v_type == VAR_DICT)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 dict_iterator_T iter;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 typval_T *value;
24160
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
300 dict_T *d = tv->vval.v_dict;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301
24160
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
302 if (d == NULL || d->dv_hashtab.ht_used == 0)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 return &t_dict_empty;
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
304 if (!do_member)
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
305 return &t_dict_any;
24160
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
306 if (d->dv_copyID == copyID)
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
307 // avoid recursion
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
308 return &t_dict_any;
e695db9a5465 patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
309 d->dv_copyID = copyID;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
311 // Use the common type of all values.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 dict_iterate_start(tv, &iter);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 dict_iterate_next(&iter, &value);
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
314 member_type = typval2type(value, copyID, type_gap, TRUE);
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
315 while (dict_iterate_next(&iter, &value) != NULL)
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
316 common_type(typval2type(value, copyID, type_gap, TRUE),
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
317 member_type, &member_type, type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 return get_dict_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 if (tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 char_u *name = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 ufunc_T *ufunc = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 if (tv->v_type == VAR_PARTIAL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 if (tv->vval.v_partial->pt_func != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 ufunc = tv->vval.v_partial->pt_func;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 name = tv->vval.v_partial->pt_name;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 name = tv->vval.v_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 if (name != NULL)
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
336 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
337 int idx = find_internal_func(name);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
338
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
339 if (idx >= 0)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
340 {
25126
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
341 internal_func_get_argcount(idx, &argcount, &min_argcount);
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
342 member_type = internal_func_ret_type(idx, 0, NULL);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
343 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
344 else
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
345 ufunc = find_func(name, FALSE, NULL);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
346 }
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 if (ufunc != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 // May need to get the argument types from default values by
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 // compiling the function.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 if (ufunc->uf_def_status == UF_TO_BE_COMPILED
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
352 && compile_def_function(ufunc, TRUE, CT_NONE, NULL)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
353 == FAIL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 return NULL;
23338
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
355 if (ufunc->uf_func_type == NULL)
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
356 set_function_type(ufunc);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 if (ufunc->uf_func_type != NULL)
25137
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
358 {
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
359 if (tv->v_type == VAR_PARTIAL
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
360 && tv->vval.v_partial->pt_argc > 0)
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
361 {
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
362 type = get_type_ptr(type_gap);
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
363 if (type == NULL)
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
364 return NULL;
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
365 *type = *ufunc->uf_func_type;
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
366 type->tt_argcount -= tv->vval.v_partial->pt_argc;
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
367 type->tt_min_argcount -= tv->vval.v_partial->pt_argc;
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
368 return type;
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
369 }
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 return ufunc->uf_func_type;
25137
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
371 }
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
375 type = get_type_ptr(type_gap);
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
376 if (type == NULL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 return NULL;
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
378 type->tt_type = tv->v_type;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
379 type->tt_argcount = argcount;
25126
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
380 type->tt_min_argcount = min_argcount;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
381 type->tt_member = member_type;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
383 return type;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 /*
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
387 * Return TRUE if "tv" is not a bool but should be converted to bool.
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
388 */
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
389 int
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
390 need_convert_to_bool(type_T *type, typval_T *tv)
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
391 {
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
392 return type != NULL && type == &t_bool && tv->v_type != VAR_BOOL
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
393 && (tv->v_type == VAR_NUMBER
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
394 && (tv->vval.v_number == 0 || tv->vval.v_number == 1));
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
395 }
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
396
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
397 /*
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
398 * Get a type_T for a typval_T.
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
399 * "type_list" is used to temporarily create types in.
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
400 * When "do_member" is TRUE also get the member type, otherwise use "any".
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
401 */
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
402 type_T *
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
403 typval2type(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
404 {
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
405 type_T *type = typval2type_int(tv, copyID, type_gap, do_member);
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
406
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
407 if (type != NULL && type != &t_bool
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
408 && (tv->v_type == VAR_NUMBER
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
409 && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
23334
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
410 // Number 0 and 1 and expression with "&&" or "||" can also be used for
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
411 // bool.
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
412 type = &t_number_bool;
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
413 return type;
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
414 }
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
415
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
416 /*
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 * Get a type_T for a typval_T, used for v: variables.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 * "type_list" is used to temporarily create types in.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 typval2type_vimvar(typval_T *tv, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 if (tv->v_type == VAR_LIST) // e.g. for v:oldfiles
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 return &t_list_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 if (tv->v_type == VAR_DICT) // e.g. for v:completed_item
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 return &t_dict_any;
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
427 return typval2type(tv, get_copyID(), type_gap, TRUE);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
430 int
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
431 check_typval_arg_type(
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
432 type_T *expected,
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
433 typval_T *actual_tv,
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
434 char *func_name,
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
435 int arg_idx)
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
436 {
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
437 where_T where = WHERE_INIT;
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
438
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
439 where.wt_index = arg_idx;
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
440 where.wt_func_name = func_name;
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
441 return check_typval_type(expected, actual_tv, where);
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
442 }
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 * Return FAIL if "expected" and "actual" don't match.
22804
af26fadf333d patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
446 * When "argidx" > 0 it is included in the error message.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 int
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
449 check_typval_type(type_T *expected, typval_T *actual_tv, where_T where)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 garray_T type_list;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 type_T *actual_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 int res = FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 ga_init2(&type_list, sizeof(type_T *), 10);
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
456 actual_type = typval2type(actual_tv, get_copyID(), &type_list, TRUE);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 if (actual_type != NULL)
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
458 res = check_type(expected, actual_type, TRUE, where);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 clear_type_list(&type_list);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 return res;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 type_mismatch(type_T *expected, type_T *actual)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 {
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
466 arg_type_mismatch(expected, actual, 0);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 void
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
470 arg_type_mismatch(type_T *expected, type_T *actual, int arg_idx)
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
471 {
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
472 where_T where = WHERE_INIT;
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
473
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
474 where.wt_index = arg_idx;
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
475 type_mismatch_where(expected, actual, where);
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
476 }
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
477
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
478 void
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
479 type_mismatch_where(type_T *expected, type_T *actual, where_T where)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 char *tofree1, *tofree2;
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
482 char *typename1 = type_name(expected, &tofree1);
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
483 char *typename2 = type_name(actual, &tofree2);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
485 if (where.wt_index > 0)
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
486 {
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
487 if (where.wt_func_name == NULL)
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
488 semsg(_(where.wt_variable
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
489 ? e_variable_nr_type_mismatch_expected_str_but_got_str
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
490 : e_argument_nr_type_mismatch_expected_str_but_got_str),
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
491 where.wt_index, typename1, typename2);
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
492 else
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
493 semsg(_(where.wt_variable
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
494 ? e_variable_nr_type_mismatch_expected_str_but_got_str_in_str
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
495 : e_argument_nr_type_mismatch_expected_str_but_got_str_in_str),
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
496 where.wt_index, typename1, typename2, where.wt_func_name);
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
497 }
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
498 else if (where.wt_func_name == NULL)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
499 semsg(_(e_type_mismatch_expected_str_but_got_str),
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
500 typename1, typename2);
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
501 else
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
502 semsg(_(e_type_mismatch_expected_str_but_got_str_in_str),
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
503 typename1, typename2, where.wt_func_name);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 vim_free(tofree1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 vim_free(tofree2);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 * Check if the expected and actual types match.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 * Does not allow for assigning "any" to a specific type.
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
511 * When "argidx" > 0 it is included in the error message.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 int
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
514 check_type(type_T *expected, type_T *actual, int give_msg, where_T where)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 int ret = OK;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 // When expected is "unknown" we accept any actual type.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 // When expected is "any" we accept any actual type except "void".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 if (expected->tt_type != VAR_UNKNOWN
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 && !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 {
22347
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
524 // tt_type should match, except that a "partial" can be assigned to a
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
525 // variable with type "func".
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
526 if (!(expected->tt_type == actual->tt_type
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
527 || (expected->tt_type == VAR_FUNC
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
528 && actual->tt_type == VAR_PARTIAL)))
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 {
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
530 if (expected->tt_type == VAR_BOOL
22184
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
531 && (actual->tt_flags & TTFLAG_BOOL_OK))
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
532 // Using number 0 or 1 for bool is OK.
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
533 return OK;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 if (give_msg)
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
535 type_mismatch_where(expected, actual, where);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 return FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 // "unknown" is used for an empty list or dict
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 if (actual->tt_member != &t_unknown)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
542 ret = check_type(expected->tt_member, actual->tt_member,
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
543 FALSE, where);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 else if (expected->tt_type == VAR_FUNC)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 {
23418
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
547 // If the return type is unknown it can be anything, including
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
548 // nothing, thus there is no point in checking.
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
549 if (expected->tt_member != &t_unknown
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
550 && actual->tt_member != &t_unknown)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
551 ret = check_type(expected->tt_member, actual->tt_member,
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
552 FALSE, where);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 if (ret == OK && expected->tt_argcount != -1
25135
5731bcaaabcb patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents: 25126
diff changeset
554 && actual->tt_min_argcount != -1
25126
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
555 && (actual->tt_argcount == -1
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
556 || (actual->tt_argcount < expected->tt_min_argcount
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
557 || actual->tt_argcount > expected->tt_argcount)))
23481
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
558 ret = FAIL;
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
559 if (ret == OK && expected->tt_args != NULL
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
560 && actual->tt_args != NULL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 for (i = 0; i < expected->tt_argcount; ++i)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 // Allow for using "any" argument type, lambda's have them.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 if (actual->tt_args[i] != &t_any && check_type(
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
567 expected->tt_args[i], actual->tt_args[i], FALSE,
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
568 where) == FAIL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 ret = FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 if (ret == FAIL && give_msg)
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
576 type_mismatch_where(expected, actual, where);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 return ret;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 /*
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
582 * Check that the arguments of "type" match "argvars[argcount]".
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
583 * Return OK/FAIL.
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
584 */
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
585 int
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
586 check_argument_types(
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
587 type_T *type,
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
588 typval_T *argvars,
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
589 int argcount,
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
590 char_u *name)
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
591 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
592 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
593 int i;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
594
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
595 if (type->tt_type != VAR_FUNC && type->tt_type != VAR_PARTIAL)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
596 return OK; // just in case
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
597 if (argcount < type->tt_min_argcount - varargs)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
598 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
599 semsg(_(e_toofewarg), name);
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
600 return FAIL;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
601 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
602 if (!varargs && type->tt_argcount >= 0 && argcount > type->tt_argcount)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
603 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
604 semsg(_(e_toomanyarg), name);
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
605 return FAIL;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
606 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
607 if (type->tt_args == NULL)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
608 return OK; // cannot check
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
609
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
610
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
611 for (i = 0; i < argcount; ++i)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
612 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
613 type_T *expected;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
614
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
615 if (varargs && i >= type->tt_argcount - 1)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
616 expected = type->tt_args[type->tt_argcount - 1]->tt_member;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
617 else
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
618 expected = type->tt_args[i];
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 25196
diff changeset
619 if (check_typval_arg_type(expected, &argvars[i], NULL, i + 1) == FAIL)
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
620 return FAIL;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
621 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
622 return OK;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
623 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
624
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
625 /*
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 * Skip over a type definition and return a pointer to just after it.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 * When "optional" is TRUE then a leading "?" is accepted.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 char_u *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 skip_type(char_u *start, int optional)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 char_u *p = start;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 if (optional && *p == '?')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 while (ASCII_ISALNUM(*p) || *p == '_')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 // Skip over "<type>"; this is permissive about white space.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 if (*skipwhite(p) == '<')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 p = skip_type(skipwhite(p + 1), FALSE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 if (*p == '>')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 else if ((*p == '(' || (*p == ':' && VIM_ISWHITE(p[1])))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 && STRNCMP("func", start, 4) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 if (*p == '(')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 // handle func(args): type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 while (*p != ')' && *p != NUL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 char_u *sp = p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 if (STRNCMP(p, "...", 3) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 p += 3;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 p = skip_type(p, TRUE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 if (p == sp)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 return p; // syntax error
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 if (*p == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 p = skipwhite(p + 1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 if (*p == ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 if (p[1] == ':')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 p = skip_type(skipwhite(p + 2), FALSE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 // handle func: return_type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 p = skip_type(skipwhite(p + 1), FALSE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 return p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 * Parse the member type: "<type>" and return "type" with the member set.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 * Use "type_gap" if a new type needs to be added.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 * Returns NULL in case of failure.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 static type_T *
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
691 parse_type_member(
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
692 char_u **arg,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
693 type_T *type,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
694 garray_T *type_gap,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
695 int give_error)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 type_T *member_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 int prev_called_emsg = called_emsg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 if (**arg != '<')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
702 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
703 {
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
704 if (*skipwhite(*arg) == '<')
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
705 semsg(_(e_no_white_space_allowed_before_str_str), "<", *arg);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
706 else
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
707 emsg(_(e_missing_type));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
708 }
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
709 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 *arg = skipwhite(*arg + 1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
713 member_type = parse_type(arg, type_gap, give_error);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
714 if (member_type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
715 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 *arg = skipwhite(*arg);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 if (**arg != '>' && called_emsg == prev_called_emsg)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
720 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
721 emsg(_(e_missing_gt_after_type));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
722 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 ++*arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 if (type->tt_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 return get_list_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 return get_dict_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 * Parse a type at "arg" and advance over it.
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
733 * When "give_error" is TRUE give error messages, otherwise be quiet.
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
734 * Return NULL for failure.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 type_T *
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
737 parse_type(char_u **arg, garray_T *type_gap, int give_error)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 char_u *p = *arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 size_t len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 // skip over the first word
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 while (ASCII_ISALNUM(*p) || *p == '_')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 len = p - *arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 switch (**arg)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 case 'a':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 if (len == 3 && STRNCMP(*arg, "any", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 case 'b':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 if (len == 4 && STRNCMP(*arg, "bool", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 return &t_bool;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 if (len == 4 && STRNCMP(*arg, "blob", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 return &t_blob;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 case 'c':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 if (len == 7 && STRNCMP(*arg, "channel", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 return &t_channel;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 case 'd':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 if (len == 4 && STRNCMP(*arg, "dict", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 *arg += len;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
779 return parse_type_member(arg, &t_dict_any,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
780 type_gap, give_error);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 case 'f':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 if (len == 5 && STRNCMP(*arg, "float", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 #ifdef FEAT_FLOAT
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 return &t_float;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 #else
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
790 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
791 emsg(_(e_this_vim_is_not_compiled_with_float_support));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
792 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 #endif
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 if (len == 4 && STRNCMP(*arg, "func", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 type_T *ret_type = &t_unknown;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 int argcount = -1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 int flags = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 int first_optional = -1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 type_T *arg_type[MAX_FUNC_ARGS + 1];
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 // func({type}, ...{type}): {type}
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 if (**arg == '(')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 // "func" may or may not return a value, "func()" does
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 // not return a value.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 ret_type = &t_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 p = ++*arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 argcount = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 while (*p != NUL && *p != ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 if (*p == '?')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 if (first_optional == -1)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 first_optional = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 else if (STRNCMP(p, "...", 3) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 flags |= TTFLAG_VARARGS;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 p += 3;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 else if (first_optional != -1)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
829 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
830 emsg(_(e_mandatory_argument_after_optional_argument));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
831 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
834 type = parse_type(&p, type_gap, give_error);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
835 if (type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
836 return NULL;
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
837 arg_type[argcount++] = type;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 // Nothing comes after "...{type}".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 if (flags & TTFLAG_VARARGS)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 if (*p != ',' && *skipwhite(p) == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
845 if (give_error)
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
846 semsg(_(e_no_white_space_allowed_before_str_str),
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
847 ",", p);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
848 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 if (*p == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 if (!VIM_ISWHITE(*p))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
855 if (give_error)
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
856 semsg(_(e_white_space_required_after_str_str),
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
857 ",", p - 1);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
858 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 if (argcount == MAX_FUNC_ARGS)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
864 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
865 emsg(_(e_too_many_argument_types));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
866 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 if (*p != ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
873 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
874 emsg(_(e_missing_close));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
875 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 *arg = p + 1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 if (**arg == ':')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 // parse return type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 ++*arg;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
883 if (!VIM_ISWHITE(**arg) && give_error)
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
884 semsg(_(e_white_space_required_after_str_str),
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
885 ":", *arg - 1);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 *arg = skipwhite(*arg);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
887 ret_type = parse_type(arg, type_gap, give_error);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
888 if (ret_type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
889 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 if (flags == 0 && first_optional == -1 && argcount <= 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 type = get_func_type(ret_type, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 type = alloc_func_type(ret_type, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 type->tt_flags = flags;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 if (argcount > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 type->tt_argcount = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 type->tt_min_argcount = first_optional == -1
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 ? argcount : first_optional;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 if (func_type_add_arg_types(type, argcount,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 type_gap) == FAIL)
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
904 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 mch_memmove(type->tt_args, arg_type,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 sizeof(type_T *) * argcount);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 case 'j':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 if (len == 3 && STRNCMP(*arg, "job", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 return &t_job;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 case 'l':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 if (len == 4 && STRNCMP(*arg, "list", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 *arg += len;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
923 return parse_type_member(arg, &t_list_any,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
924 type_gap, give_error);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 case 'n':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 if (len == 6 && STRNCMP(*arg, "number", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 return &t_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 case 's':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 if (len == 6 && STRNCMP(*arg, "string", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 return &t_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 case 'v':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 if (len == 4 && STRNCMP(*arg, "void", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 return &t_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
950 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
951 semsg(_(e_type_not_recognized_str), *arg);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
952 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 * Check if "type1" and "type2" are exactly the same.
25425
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
957 * "flags" can have ETYPE_ARG_UNKNOWN, which means that an unknown argument
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
958 * type in "type1" is accepted.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 */
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
960 int
25425
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
961 equal_type(type_T *type1, type_T *type2, int flags)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964
24118
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
965 if (type1 == NULL || type2 == NULL)
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
966 return FALSE;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 if (type1->tt_type != type2->tt_type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 switch (type1->tt_type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 case VAR_UNKNOWN:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 case VAR_ANY:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 case VAR_VOID:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 case VAR_SPECIAL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 case VAR_BOOL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 case VAR_NUMBER:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 case VAR_FLOAT:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 case VAR_STRING:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 case VAR_BLOB:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 case VAR_JOB:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 case VAR_CHANNEL:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24438
diff changeset
982 case VAR_INSTR:
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 break; // not composite is always OK
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 case VAR_LIST:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 case VAR_DICT:
25425
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
986 return equal_type(type1->tt_member, type2->tt_member, flags);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 case VAR_FUNC:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 case VAR_PARTIAL:
25425
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
989 if (!equal_type(type1->tt_member, type2->tt_member, flags)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 || type1->tt_argcount != type2->tt_argcount)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 if (type1->tt_argcount < 0
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 || type1->tt_args == NULL || type2->tt_args == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 for (i = 0; i < type1->tt_argcount; ++i)
25425
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
996 if ((flags & ETYPE_ARG_UNKNOWN) == 0
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
997 && !equal_type(type1->tt_args[i], type2->tt_args[i],
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
998 flags))
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 * Find the common type of "type1" and "type2" and put it in "dest".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 * "type2" and "dest" may be the same.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 {
25425
effe5f2b4d01 patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
1012 if (equal_type(type1, type2, 0))
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 *dest = type1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017
22322
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1018 // If either is VAR_UNKNOWN use the other type. An empty list/dict has no
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1019 // specific type.
24118
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
1020 if (type1 == NULL || type1->tt_type == VAR_UNKNOWN)
22322
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1021 {
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1022 *dest = type2;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1023 return;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1024 }
24118
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
1025 if (type2 == NULL || type2->tt_type == VAR_UNKNOWN)
22322
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1026 {
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1027 *dest = type1;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1028 return;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1029 }
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1030
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 if (type1->tt_type == type2->tt_type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 type_T *common;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 common_type(type1->tt_member, type2->tt_member, &common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 if (type1->tt_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 *dest = get_list_type(common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 *dest = get_dict_type(common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 if (type1->tt_type == VAR_FUNC)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 type_T *common;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 common_type(type1->tt_member, type2->tt_member, &common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 if (type1->tt_argcount == type2->tt_argcount
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 && type1->tt_argcount >= 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 int argcount = type1->tt_argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 *dest = alloc_func_type(common, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 if (type1->tt_args != NULL && type2->tt_args != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 if (func_type_add_arg_types(*dest, argcount,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 type_gap) == OK)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 for (i = 0; i < argcount; ++i)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 common_type(type1->tt_args[i], type2->tt_args[i],
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 &(*dest)->tt_args[i], type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 else
25126
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
1066 // Use -1 for "tt_argcount" to indicate an unknown number of
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
1067 // arguments.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 *dest = alloc_func_type(common, -1, type_gap);
25126
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 24996
diff changeset
1069
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
1070 // Use the minimum of min_argcount.
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
1071 (*dest)->tt_min_argcount =
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
1072 type1->tt_min_argcount < type2->tt_min_argcount
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
1073 ? type1->tt_min_argcount : type2->tt_min_argcount;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 *dest = &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080
21715
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1081 /*
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1082 * Get the member type of a dict or list from the items on the stack.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1083 * "stack_top" points just after the last type on the type stack.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1084 * For a list "skip" is 1, for a dict "skip" is 2, keys are skipped.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1085 * Returns &t_void for an empty list or dict.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1086 * Otherwise finds the common type of all items.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1087 */
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1088 type_T *
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1089 get_member_type_from_stack(
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1090 type_T **stack_top,
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1091 int count,
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1092 int skip,
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1093 garray_T *type_gap)
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1094 {
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1095 int i;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1096 type_T *result;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1097 type_T *type;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1098
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1099 // Use "any" for an empty list or dict.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1100 if (count == 0)
22322
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1101 return &t_unknown;
21715
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1102
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1103 // Use the first value type for the list member type, then find the common
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1104 // type from following items.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1105 result = *(stack_top -(count * skip) + skip - 1);
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1106 for (i = 1; i < count; ++i)
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1107 {
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1108 if (result == &t_any)
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1109 break; // won't get more common
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1110 type = *(stack_top -((count - i) * skip) + skip - 1);
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1111 common_type(type, result, &result, type_gap);
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1112 }
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1113
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1114 return result;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1115 }
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1116
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 char *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 vartype_name(vartype_T type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 switch (type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 case VAR_UNKNOWN: break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 case VAR_ANY: return "any";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 case VAR_VOID: return "void";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 case VAR_SPECIAL: return "special";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 case VAR_BOOL: return "bool";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 case VAR_NUMBER: return "number";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 case VAR_FLOAT: return "float";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 case VAR_STRING: return "string";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 case VAR_BLOB: return "blob";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 case VAR_JOB: return "job";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 case VAR_CHANNEL: return "channel";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 case VAR_LIST: return "list";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 case VAR_DICT: return "dict";
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24438
diff changeset
1135 case VAR_INSTR: return "instr";
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 case VAR_FUNC:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 case VAR_PARTIAL: return "func";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 return "unknown";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 * Return the name of a type.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 * The result may be in allocated memory, in which case "tofree" is set.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 char *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 type_name(type_T *type, char **tofree)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1150 char *name;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 *tofree = NULL;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1153 if (type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1154 return "[unknown]";
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1155 name = vartype_name(type->tt_type);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 if (type->tt_type == VAR_LIST || type->tt_type == VAR_DICT)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 char *member_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 char *member_name = type_name(type->tt_member, &member_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 size_t len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 len = STRLEN(name) + STRLEN(member_name) + 3;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 *tofree = alloc(len);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 if (*tofree != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 vim_snprintf(*tofree, len, "%s<%s>", name, member_name);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 vim_free(member_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 return *tofree;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 if (type->tt_type == VAR_FUNC)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 garray_T ga;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 ga_init2(&ga, 1, 100);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 if (ga_grow(&ga, 20) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 STRCPY(ga.ga_data, "func(");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 ga.ga_len += 5;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 for (i = 0; i < type->tt_argcount; ++i)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 {
25196
694f114a7673 patch 8.2.3134: crash when using typename() on a function reference
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
1185 char *arg_free = NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 char *arg_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 int len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 if (type->tt_args == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 arg_type = "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 arg_type = type_name(type->tt_args[i], &arg_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 if (i > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 STRCPY((char *)ga.ga_data + ga.ga_len, ", ");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 ga.ga_len += 2;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 len = (int)STRLEN(arg_type);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 if (ga_grow(&ga, len + 8) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 vim_free(arg_free);
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1202 ga_clear(&ga);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 if (varargs && i == type->tt_argcount - 1)
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1206 ga_concat(&ga, (char_u *)"...");
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 else if (i >= type->tt_min_argcount)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 *((char *)ga.ga_data + ga.ga_len++) = '?';
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1209 ga_concat(&ga, (char_u *)arg_type);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 vim_free(arg_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 }
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1212 if (type->tt_argcount < 0)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1213 // any number of arguments
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1214 ga_concat(&ga, (char_u *)"...");
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 if (type->tt_member == &t_void)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 STRCPY((char *)ga.ga_data + ga.ga_len, ")");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 char *ret_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 char *ret_name = type_name(type->tt_member, &ret_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 int len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 len = (int)STRLEN(ret_name) + 4;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 if (ga_grow(&ga, len) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 vim_free(ret_free);
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1228 ga_clear(&ga);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 STRCPY((char *)ga.ga_data + ga.ga_len, "): ");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 STRCPY((char *)ga.ga_data + ga.ga_len + 3, ret_name);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 vim_free(ret_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 }
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1235 *tofree = ga.ga_data;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 return ga.ga_data;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 return name;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241
23594
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1242 /*
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1243 * "typename(expr)" function
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1244 */
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1245 void
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1246 f_typename(typval_T *argvars, typval_T *rettv)
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1247 {
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1248 garray_T type_list;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1249 type_T *type;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1250 char *tofree;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1251 char *name;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1252
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1253 rettv->v_type = VAR_STRING;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1254 ga_init2(&type_list, sizeof(type_T *), 10);
24438
5c6ccab68d1e patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents: 24160
diff changeset
1255 type = typval2type(argvars, get_copyID(), &type_list, TRUE);
23594
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1256 name = type_name(type, &tofree);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1257 if (tofree != NULL)
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1258 rettv->vval.v_string = (char_u *)tofree;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1259 else
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1260 {
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1261 rettv->vval.v_string = vim_strsave((char_u *)name);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1262 vim_free(tofree);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1263 }
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1264 clear_type_list(&type_list);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1265 }
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1266
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 #endif // FEAT_EVAL