annotate src/vim9class.c @ 31833:3516e35f409f v9.0.1249

patch 9.0.1249: cannot export an abstract class Commit: https://github.com/vim/vim/commit/657aea7fc47fb919ce76fad64ba0ec55a1af80f1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 27 13:16:19 2023 +0000 patch 9.0.1249: cannot export an abstract class Problem: Cannot export an abstract class. (Ernie Rael) Solution: Add the EX_EXPORT flag to :abstract. (closes https://github.com/vim/vim/issues/11884)
author Bram Moolenaar <Bram@vim.org>
date Fri, 27 Jan 2023 14:30:04 +0100
parents 64f03e860c91
children ffa11e2757e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * vim9class.c: Vim9 script class support
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #define USING_FLOAT_STUFF
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 // When not generating protos this is included in proto.h
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 #ifdef PROTO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 # include "vim9.h"
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 #endif
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 /*
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
25 * Parse a member declaration, both object and class member.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
26 * Returns OK or FAIL. When OK then "varname_end" is set to just after the
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
27 * variable name and "type_ret" is set to the decleared or detected type.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
28 * "init_expr" is set to the initialisation expression (allocated), if there is
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
29 * one. For an interface "init_expr" is NULL.
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
30 */
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
31 static int
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
32 parse_member(
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
33 exarg_T *eap,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
34 char_u *line,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
35 char_u *varname,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
36 int has_public, // TRUE if "public" seen before "varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
37 char_u **varname_end,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
38 garray_T *type_list,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
39 type_T **type_ret,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
40 char_u **init_expr)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
41 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
42 *varname_end = to_name_end(varname, FALSE);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
43 if (*varname == '_' && has_public)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
44 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
45 semsg(_(e_public_member_name_cannot_start_with_underscore_str), line);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
46 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
47 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
48
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
49 char_u *colon = skipwhite(*varname_end);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
50 char_u *type_arg = colon;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
51 type_T *type = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
52 if (*colon == ':')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
53 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
54 if (VIM_ISWHITE(**varname_end))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
55 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
56 semsg(_(e_no_white_space_allowed_before_colon_str), varname);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
57 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
58 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
59 if (!VIM_ISWHITE(colon[1]))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
60 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
61 semsg(_(e_white_space_required_after_str_str), ":", varname);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
62 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
63 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
64 type_arg = skipwhite(colon + 1);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
65 type = parse_type(&type_arg, type_list, TRUE);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
66 if (type == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
67 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
68 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
69
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
70 char_u *expr_start = skipwhite(type_arg);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
71 char_u *expr_end = expr_start;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
72 if (type == NULL && *expr_start != '=')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
73 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
74 emsg(_(e_type_or_initialization_required));
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
75 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
76 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
77
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
78 if (*expr_start == '=')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
79 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
80 if (!VIM_ISWHITE(expr_start[-1]) || !VIM_ISWHITE(expr_start[1]))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
81 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
82 semsg(_(e_white_space_required_before_and_after_str_at_str),
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
83 "=", type_arg);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
84 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
85 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
86 expr_start = skipwhite(expr_start + 1);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
87
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
88 expr_end = expr_start;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
89 evalarg_T evalarg;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
90 fill_evalarg_from_eap(&evalarg, eap, FALSE);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
91 skip_expr(&expr_end, NULL);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
92
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
93 if (type == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
94 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
95 // No type specified, use the type of the initializer.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
96 typval_T tv;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
97 tv.v_type = VAR_UNKNOWN;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
98 char_u *expr = expr_start;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
99 int res = eval0(expr, &tv, eap, &evalarg);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
100
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
101 if (res == OK)
31608
8e965e5a46c9 patch 9.0.1136: memory leak when getting class member type from expr
Bram Moolenaar <Bram@vim.org>
parents: 31592
diff changeset
102 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
103 type = typval2type(&tv, get_copyID(), type_list,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
104 TVTT_DO_MEMBER);
31608
8e965e5a46c9 patch 9.0.1136: memory leak when getting class member type from expr
Bram Moolenaar <Bram@vim.org>
parents: 31592
diff changeset
105 clear_tv(&tv);
8e965e5a46c9 patch 9.0.1136: memory leak when getting class member type from expr
Bram Moolenaar <Bram@vim.org>
parents: 31592
diff changeset
106 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
107 if (type == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
108 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
109 semsg(_(e_cannot_get_object_member_type_from_initializer_str),
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
110 expr_start);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
111 clear_evalarg(&evalarg, NULL);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
112 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
113 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
114 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
115 clear_evalarg(&evalarg, NULL);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
116 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
117 if (!valid_declaration_type(type))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
118 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
119
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
120 *type_ret = type;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
121 if (expr_end > expr_start)
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
122 {
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
123 if (init_expr == NULL)
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
124 {
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
125 emsg(_(e_cannot_initialize_member_in_interface));
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
126 return FAIL;
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
127 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
128 *init_expr = vim_strnsave(expr_start, expr_end - expr_start);
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
129 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
130 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
131 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
132
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
133 /*
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
134 * Add a member to an object or a class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
135 * Returns OK when successful, "init_expr" will be consumed then.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
136 * Returns FAIL otherwise, caller might need to free "init_expr".
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
137 */
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
138 static int
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
139 add_member(
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
140 garray_T *gap,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
141 char_u *varname,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
142 char_u *varname_end,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
143 int has_public,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
144 type_T *type,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
145 char_u *init_expr)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
146 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
147 if (ga_grow(gap, 1) == FAIL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
148 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
149 ocmember_T *m = ((ocmember_T *)gap->ga_data) + gap->ga_len;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
150 m->ocm_name = vim_strnsave(varname, varname_end - varname);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
151 m->ocm_access = has_public ? ACCESS_ALL
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
152 : *varname == '_' ? ACCESS_PRIVATE : ACCESS_READ;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
153 m->ocm_type = type;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
154 if (init_expr != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
155 m->ocm_init = init_expr;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
156 ++gap->ga_len;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
157 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
158 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
159
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
160 /*
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
161 * Move the class or object members found while parsing a class into the class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
162 * "gap" contains the found members.
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
163 * "parent_members" points to the members in the parent class (if any)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
164 * "parent_count" is the number of members in the parent class
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
165 * "members" will be set to the newly allocated array of members and
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
166 * "member_count" set to the number of members.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
167 * Returns OK or FAIL.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
168 */
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
169 static int
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
170 add_members_to_class(
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
171 garray_T *gap,
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
172 ocmember_T *parent_members,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
173 int parent_count,
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
174 ocmember_T **members,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
175 int *member_count)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
176 {
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
177 *member_count = parent_count + gap->ga_len;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
178 *members = *member_count == 0 ? NULL
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
179 : ALLOC_MULT(ocmember_T, *member_count);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
180 if (*member_count > 0 && *members == NULL)
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
181 return FAIL;
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
182 for (int i = 0; i < parent_count; ++i)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
183 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
184 // parent members need to be copied
31746
d3d3ed2c09f6 patch 9.0.1205: crash when handling class that extends another class
Bram Moolenaar <Bram@vim.org>
parents: 31732
diff changeset
185 ocmember_T *m = *members + i;
d3d3ed2c09f6 patch 9.0.1205: crash when handling class that extends another class
Bram Moolenaar <Bram@vim.org>
parents: 31732
diff changeset
186 *m = parent_members[i];
d3d3ed2c09f6 patch 9.0.1205: crash when handling class that extends another class
Bram Moolenaar <Bram@vim.org>
parents: 31732
diff changeset
187 m->ocm_name = vim_strsave(m->ocm_name);
d3d3ed2c09f6 patch 9.0.1205: crash when handling class that extends another class
Bram Moolenaar <Bram@vim.org>
parents: 31732
diff changeset
188 if (m->ocm_init != NULL)
d3d3ed2c09f6 patch 9.0.1205: crash when handling class that extends another class
Bram Moolenaar <Bram@vim.org>
parents: 31732
diff changeset
189 m->ocm_init = vim_strsave(m->ocm_init);
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
190 }
31487
df58407c97f3 patch 9.0.1076: ASAN complains about NULL argument
Bram Moolenaar <Bram@vim.org>
parents: 31483
diff changeset
191 if (gap->ga_len > 0)
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
192 // new members are moved
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
193 mch_memmove(*members + parent_count,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
194 gap->ga_data, sizeof(ocmember_T) * gap->ga_len);
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
195 VIM_CLEAR(gap->ga_data);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
196 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
197 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
198
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
199 /*
31754
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
200 * Convert a member index "idx" of interface "itf" to the member index of class
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
201 * "cl" implementing that interface.
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
202 */
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
203 int
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
204 object_index_from_itf_index(class_T *itf, int idx, class_T *cl)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
205 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
206 if (idx > itf->class_obj_member_count)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
207 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
208 siemsg("index %d out of range for interface %s", idx, itf->class_name);
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
209 return 0;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
210 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
211 itf2class_T *i2c;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
212 for (i2c = itf->class_itf2class; i2c != NULL; i2c = i2c->i2c_next)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
213 if (i2c->i2c_class == cl)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
214 break;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
215 if (i2c == NULL)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
216 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
217 siemsg("class %s not found on interface %s",
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
218 cl->class_name, itf->class_name);
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
219 return 0;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
220 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
221 int *table = (int *)(i2c + 1);
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
222 return table[idx];
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
223 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
224
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
225 /*
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 * Handle ":class" and ":abstract class" up to ":endclass".
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
227 * Handle ":interface" up to ":endinterface".
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 ex_class(exarg_T *eap)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 {
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
232 int is_class = eap->cmdidx == CMD_class; // FALSE for :interface
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
233
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 char_u *arg = eap->arg;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
235 int is_abstract = eap->cmdidx == CMD_abstract;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 if (is_abstract)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 if (STRNCMP(arg, "class", 5) != 0 || !VIM_ISWHITE(arg[5]))
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 semsg(_(e_invalid_argument_str), arg);
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 return;
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 arg = skipwhite(arg + 5);
31732
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
244 is_class = TRUE;
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
245 }
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
246
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
247 if (!current_script_is_vim9()
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
248 || (cmdmod.cmod_flags & CMOD_LEGACY)
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
249 || !getline_equal(eap->getline, eap->cookie, getsourceline))
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
250 {
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
251 if (is_class)
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
252 emsg(_(e_class_can_only_be_defined_in_vim9_script));
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
253 else
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
254 emsg(_(e_interface_can_only_be_defined_in_vim9_script));
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
255 return;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 if (!ASCII_ISUPPER(*arg))
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 {
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
260 if (is_class)
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
261 semsg(_(e_class_name_must_start_with_uppercase_letter_str), arg);
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
262 else
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
263 semsg(_(e_interface_name_must_start_with_uppercase_letter_str),
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
264 arg);
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 return;
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
267 char_u *name_end = find_name_end(arg, NULL, NULL, FNE_CHECK_START);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
268 if (!IS_WHITE_OR_NUL(*name_end))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
269 {
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
270 semsg(_(e_white_space_required_after_name_str), arg);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
271 return;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
272 }
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
273 char_u *name_start = arg;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274
31706
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
275 // "export class" gets used when creating the class, don't use "is_export"
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
276 // for the items inside the class.
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
277 int class_export = is_export;
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
278 is_export = FALSE;
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
279
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 // TODO:
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
281 // generics: <Tkey, Tentry>
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
282
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
283 // Name for "extends BaseClass"
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
284 char_u *extends = NULL;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
285
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
286 // Names for "implements SomeInterface"
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
287 garray_T ga_impl;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
288 ga_init2(&ga_impl, sizeof(char_u *), 5);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
289
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
290 arg = skipwhite(name_end);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
291 while (*arg != NUL && *arg != '#' && *arg != '\n')
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
292 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
293 // TODO:
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
294 // specifies SomeInterface
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
295 if (STRNCMP(arg, "extends", 7) == 0 && IS_WHITE_OR_NUL(arg[7]))
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
296 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
297 if (extends != NULL)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
298 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
299 emsg(_(e_duplicate_extends));
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
300 goto early_ret;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
301 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
302 arg = skipwhite(arg + 7);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
303 char_u *end = find_name_end(arg, NULL, NULL, FNE_CHECK_START);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
304 if (!IS_WHITE_OR_NUL(*end))
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
305 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
306 semsg(_(e_white_space_required_after_name_str), arg);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
307 goto early_ret;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
308 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
309 extends = vim_strnsave(arg, end - arg);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
310 if (extends == NULL)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
311 goto early_ret;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
312
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
313 arg = skipwhite(end + 1);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
314 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
315 else if (STRNCMP(arg, "implements", 10) == 0
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
316 && IS_WHITE_OR_NUL(arg[10]))
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
317 {
31649
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
318 if (ga_impl.ga_len > 0)
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
319 {
31649
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
320 emsg(_(e_duplicate_implements));
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
321 goto early_ret;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
322 }
31649
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
323 arg = skipwhite(arg + 10);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
324
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
325 for (;;)
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
326 {
31649
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
327 char_u *impl_end = find_name_end(arg, NULL, NULL,
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
328 FNE_CHECK_START);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
329 if (!IS_WHITE_OR_NUL(*impl_end) && *impl_end != ',')
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
330 {
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
331 semsg(_(e_white_space_required_after_name_str), arg);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
332 goto early_ret;
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
333 }
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
334 char_u *iname = vim_strnsave(arg, impl_end - arg);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
335 if (iname == NULL)
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
336 goto early_ret;
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
337 for (int i = 0; i < ga_impl.ga_len; ++i)
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
338 if (STRCMP(((char_u **)ga_impl.ga_data)[i], iname) == 0)
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
339 {
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
340 semsg(_(e_duplicate_interface_after_implements_str),
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
341 iname);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
342 vim_free(iname);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
343 goto early_ret;
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
344 }
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
345 if (ga_add_string(&ga_impl, iname) == FAIL)
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
346 {
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
347 vim_free(iname);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
348 goto early_ret;
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
349 }
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
350 if (*impl_end != ',')
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
351 {
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
352 arg = skipwhite(impl_end);
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
353 break;
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
354 }
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31643
diff changeset
355 arg = skipwhite(impl_end + 1);
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
356 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
357 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
358 else
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
359 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
360 semsg(_(e_trailing_characters_str), arg);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
361 early_ret:
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
362 vim_free(extends);
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
363 ga_clear_strings(&ga_impl);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
364 return;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
365 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
366 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
367
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
368 garray_T type_list; // list of pointers to allocated types
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
369 ga_init2(&type_list, sizeof(type_T *), 10);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
370
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
371 // Growarray with class members declared in the class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
372 garray_T classmembers;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
373 ga_init2(&classmembers, sizeof(ocmember_T), 10);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
374
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
375 // Growarray with functions declared in the class.
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
376 garray_T classfunctions;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
377 ga_init2(&classfunctions, sizeof(ufunc_T *), 10);
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
378
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
379 // Growarray with object members declared in the class.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
380 garray_T objmembers;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
381 ga_init2(&objmembers, sizeof(ocmember_T), 10);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
382
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
383 // Growarray with object methods declared in the class.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
384 garray_T objmethods;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
385 ga_init2(&objmethods, sizeof(ufunc_T *), 10);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
386
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
387 /*
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
388 * Go over the body of the class/interface until "endclass" or
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
389 * "endinterface" is found.
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
390 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
391 char_u *theline = NULL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
392 int success = FALSE;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
393 for (;;)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
394 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
395 vim_free(theline);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
396 theline = eap->getline(':', eap->cookie, 0, GETLINE_CONCAT_ALL);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
397 if (theline == NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
398 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
399 char_u *line = skipwhite(theline);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
400
31501
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
401 // Skip empty and comment lines.
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
402 if (*line == NUL)
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
403 continue;
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
404 if (*line == '#')
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
405 {
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
406 if (vim9_bad_comment(line))
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
407 break;
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
408 continue;
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
409 }
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
410
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
411 char_u *p = line;
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
412 char *end_name = is_class ? "endclass" : "endinterface";
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
413 if (checkforcmd(&p, end_name, is_class ? 4 : 5))
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
414 {
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
415 if (STRNCMP(line, end_name, is_class ? 8 : 12) != 0)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
416 semsg(_(e_command_cannot_be_shortened_str), line);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
417 else if (*p == '|' || !ends_excmd2(line, p))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
418 semsg(_(e_trailing_characters_str), p);
31408
c82cb53474ee patch 9.0.1037: lalloc(0) error for a class without members
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
419 else
c82cb53474ee patch 9.0.1037: lalloc(0) error for a class without members
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
420 success = TRUE;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
421 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
422 }
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
423 char *wrong_name = is_class ? "endinterface" : "endclass";
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
424 if (checkforcmd(&p, wrong_name, is_class ? 5 : 4))
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
425 {
31833
3516e35f409f patch 9.0.1249: cannot export an abstract class
Bram Moolenaar <Bram@vim.org>
parents: 31815
diff changeset
426 semsg(_(e_invalid_command_str_expected_str), line, end_name);
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
427 break;
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
428 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
429
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
430 int has_public = FALSE;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
431 if (checkforcmd(&p, "public", 3))
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
432 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
433 if (STRNCMP(line, "public", 6) != 0)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
434 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
435 semsg(_(e_command_cannot_be_shortened_str), line);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
436 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
437 }
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
438 has_public = TRUE;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
439 p = skipwhite(line + 6);
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
440
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
441 if (STRNCMP(p, "this", 4) != 0 && STRNCMP(p, "static", 6) != 0)
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
442 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
443 emsg(_(e_public_must_be_followed_by_this_or_static));
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
444 break;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
445 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
446 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
447
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
448 int has_static = FALSE;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
449 char_u *ps = p;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
450 if (checkforcmd(&p, "static", 4))
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
451 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
452 if (STRNCMP(ps, "static", 6) != 0)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
453 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
454 semsg(_(e_command_cannot_be_shortened_str), ps);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
455 break;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
456 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
457 has_static = TRUE;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
458 p = skipwhite(ps + 6);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
459 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
460
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
461 // object members (public, read access, private):
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
462 // "this._varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
463 // "this.varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
464 // "public this.varname"
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
465 if (STRNCMP(p, "this", 4) == 0)
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
466 {
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
467 if (p[4] != '.' || !eval_isnamec1(p[5]))
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
468 {
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
469 semsg(_(e_invalid_object_member_declaration_str), p);
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
470 break;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
471 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
472 char_u *varname = p + 5;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
473 char_u *varname_end = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
474 type_T *type = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
475 char_u *init_expr = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
476 if (parse_member(eap, line, varname, has_public,
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
477 &varname_end, &type_list, &type,
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
478 is_class ? &init_expr: NULL) == FAIL)
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
479 break;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
480 if (add_member(&objmembers, varname, varname_end,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
481 has_public, type, init_expr) == FAIL)
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
482 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
483 vim_free(init_expr);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
484 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
485 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
486 }
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
487
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
488 // constructors:
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
489 // def new()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
490 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
491 // def newOther()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
492 // enddef
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
493 // object methods and class functions:
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
494 // def SomeMethod()
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
495 // enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
496 // static def ClassFunction()
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
497 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
498 // TODO:
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
499 // def <Tval> someMethod()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
500 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
501 else if (checkforcmd(&p, "def", 3))
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
502 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
503 exarg_T ea;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
504 garray_T lines_to_free;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
505
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
506 // TODO: error for "public static def Func()"?
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
507
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
508 CLEAR_FIELD(ea);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
509 ea.cmd = line;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
510 ea.arg = p;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
511 ea.cmdidx = CMD_def;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
512 ea.getline = eap->getline;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
513 ea.cookie = eap->cookie;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
514
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
515 ga_init2(&lines_to_free, sizeof(char_u *), 50);
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
516 ufunc_T *uf = define_function(&ea, NULL, &lines_to_free,
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
517 is_class ? CF_CLASS : CF_INTERFACE);
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
518 ga_clear_strings(&lines_to_free);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
519
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
520 if (uf != NULL)
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
521 {
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
522 char_u *name = uf->uf_name;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
523 int is_new = STRNCMP(name, "new", 3) == 0;
31732
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
524 if (is_new && is_abstract)
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
525 {
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
526 emsg(_(e_cannot_define_new_function_in_abstract_class));
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
527 success = FALSE;
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
528 break;
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
529 }
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
530 garray_T *fgap = has_static || is_new
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
531 ? &classfunctions : &objmethods;
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
532 // Check the name isn't used already.
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
533 for (int i = 0; i < fgap->ga_len; ++i)
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
534 {
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
535 char_u *n = ((ufunc_T **)fgap->ga_data)[i]->uf_name;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
536 if (STRCMP(name, n) == 0)
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
537 {
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
538 semsg(_(e_duplicate_function_str), name);
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
539 break;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
540 }
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
541 }
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
542
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
543 if (ga_grow(fgap, 1) == OK)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
544 {
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
545 if (is_new)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
546 uf->uf_flags |= FC_NEW;
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
547
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
548 ((ufunc_T **)fgap->ga_data)[fgap->ga_len] = uf;
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
549 ++fgap->ga_len;
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
550 }
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
551 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
552 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
553
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
554 // class members
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
555 else if (has_static)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
556 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
557 // class members (public, read access, private):
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
558 // "static _varname"
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
559 // "static varname"
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
560 // "public static varname"
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
561 char_u *varname = p;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
562 char_u *varname_end = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
563 type_T *type = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
564 char_u *init_expr = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
565 if (parse_member(eap, line, varname, has_public,
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
566 &varname_end, &type_list, &type,
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
567 is_class ? &init_expr : NULL) == FAIL)
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
568 break;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
569 if (add_member(&classmembers, varname, varname_end,
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
570 has_public, type, init_expr) == FAIL)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
571 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
572 vim_free(init_expr);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
573 break;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
574 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
575 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
576
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
577 else
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
578 {
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
579 if (is_class)
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
580 semsg(_(e_not_valid_command_in_class_str), line);
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
581 else
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
582 semsg(_(e_not_valid_command_in_interface_str), line);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
583 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
584 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
585 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
586 vim_free(theline);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
587
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
588 class_T *extends_cl = NULL; // class from "extends" argument
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
589
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
590 /*
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
591 * Check a few things before defining the class.
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
592 */
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
593
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
594 // Check the "extends" class is valid.
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
595 if (success && extends != NULL)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
596 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
597 typval_T tv;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
598 tv.v_type = VAR_UNKNOWN;
31706
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
599 if (eval_variable_import(extends, &tv) == FAIL)
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
600 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
601 semsg(_(e_class_name_not_found_str), extends);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
602 success = FALSE;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
603 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
604 else
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
605 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
606 if (tv.v_type != VAR_CLASS
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
607 || tv.vval.v_class == NULL
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
608 || (tv.vval.v_class->class_flags & CLASS_INTERFACE) != 0)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
609 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
610 semsg(_(e_cannot_extend_str), extends);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
611 success = FALSE;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
612 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
613 else
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
614 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
615 extends_cl = tv.vval.v_class;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
616 ++extends_cl->class_refcount;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
617 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
618 clear_tv(&tv);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
619 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
620 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
621 VIM_CLEAR(extends);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
622
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
623 class_T **intf_classes = NULL;
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
624
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
625 // Check all "implements" entries are valid.
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
626 if (success && ga_impl.ga_len > 0)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
627 {
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
628 intf_classes = ALLOC_CLEAR_MULT(class_T *, ga_impl.ga_len);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
629
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
630 for (int i = 0; i < ga_impl.ga_len && success; ++i)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
631 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
632 char_u *impl = ((char_u **)ga_impl.ga_data)[i];
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
633 typval_T tv;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
634 tv.v_type = VAR_UNKNOWN;
31706
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
635 if (eval_variable_import(impl, &tv) == FAIL)
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
636 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
637 semsg(_(e_interface_name_not_found_str), impl);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
638 success = FALSE;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
639 break;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
640 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
641
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
642 if (tv.v_type != VAR_CLASS
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
643 || tv.vval.v_class == NULL
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
644 || (tv.vval.v_class->class_flags & CLASS_INTERFACE) == 0)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
645 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
646 semsg(_(e_not_valid_interface_str), impl);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
647 success = FALSE;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
648 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
649
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
650 class_T *ifcl = tv.vval.v_class;
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
651 intf_classes[i] = ifcl;
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
652 ++ifcl->class_refcount;
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
653
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
654 // check the members of the interface match the members of the class
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
655 for (int loop = 1; loop <= 2 && success; ++loop)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
656 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
657 // loop == 1: check class members
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
658 // loop == 2: check object members
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
659 int if_count = loop == 1 ? ifcl->class_class_member_count
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
660 : ifcl->class_obj_member_count;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
661 if (if_count == 0)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
662 continue;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
663 ocmember_T *if_ms = loop == 1 ? ifcl->class_class_members
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
664 : ifcl->class_obj_members;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
665 ocmember_T *cl_ms = (ocmember_T *)(loop == 1
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
666 ? classmembers.ga_data
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
667 : objmembers.ga_data);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
668 int cl_count = loop == 1 ? classmembers.ga_len
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
669 : objmembers.ga_len;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
670 for (int if_i = 0; if_i < if_count; ++if_i)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
671 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
672 int cl_i;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
673 for (cl_i = 0; cl_i < cl_count; ++cl_i)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
674 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
675 ocmember_T *m = &cl_ms[cl_i];
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
676 if (STRCMP(if_ms[if_i].ocm_name, m->ocm_name) == 0)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
677 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
678 // TODO: check type
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
679 break;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
680 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
681 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
682 if (cl_i == cl_count)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
683 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
684 semsg(_(e_member_str_of_interface_str_not_implemented),
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
685 if_ms[if_i].ocm_name, impl);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
686 success = FALSE;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
687 break;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
688 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
689 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
690 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
691
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
692 // check the functions/methods of the interface match the
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
693 // functions/methods of the class
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
694 for (int loop = 1; loop <= 2 && success; ++loop)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
695 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
696 // loop == 1: check class functions
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
697 // loop == 2: check object methods
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
698 int if_count = loop == 1 ? ifcl->class_class_function_count
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
699 : ifcl->class_obj_method_count;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
700 if (if_count == 0)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
701 continue;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
702 ufunc_T **if_fp = loop == 1 ? ifcl->class_class_functions
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
703 : ifcl->class_obj_methods;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
704 ufunc_T **cl_fp = (ufunc_T **)(loop == 1
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
705 ? classfunctions.ga_data
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
706 : objmethods.ga_data);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
707 int cl_count = loop == 1 ? classfunctions.ga_len
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
708 : objmethods.ga_len;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
709 for (int if_i = 0; if_i < if_count; ++if_i)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
710 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
711 char_u *if_name = if_fp[if_i]->uf_name;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
712 int cl_i;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
713 for (cl_i = 0; cl_i < cl_count; ++cl_i)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
714 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
715 char_u *cl_name = cl_fp[cl_i]->uf_name;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
716 if (STRCMP(if_name, cl_name) == 0)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
717 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
718 // TODO: check return and argument types
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
719 break;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
720 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
721 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
722 if (cl_i == cl_count)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
723 {
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
724 semsg(_(e_function_str_of_interface_str_not_implemented),
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
725 if_name, impl);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
726 success = FALSE;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
727 break;
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
728 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
729 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
730 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
731
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
732 clear_tv(&tv);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
733 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
734 }
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
735
31720
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
736 if (success)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
737 {
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
738 // Check no function argument name is used as an object/class member.
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
739 for (int loop = 1; loop <= 2 && success; ++loop)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
740 {
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
741 garray_T *gap = loop == 1 ? &classfunctions : &objmethods;
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
742
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
743 for (int fi = 0; fi < gap->ga_len && success; ++fi)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
744 {
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
745 ufunc_T *uf = ((ufunc_T **)gap->ga_data)[fi];
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
746
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
747 for (int i = 0; i < uf->uf_args.ga_len && success; ++i)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
748 {
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
749 char_u *aname = ((char_u **)uf->uf_args.ga_data)[i];
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
750 for (int il = 1; il <= 2 && success; ++il)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
751 {
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
752 // For a "new()" function "this.member" arguments are
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
753 // OK. TODO: check for the "this." prefix.
31724
2b523bbb3a6f patch 9.0.1194: compiler warning for comparing pointer with int
Bram Moolenaar <Bram@vim.org>
parents: 31720
diff changeset
754 if (STRNCMP(uf->uf_name, "new", 3) == 0 && il == 2)
31720
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
755 continue;
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
756 garray_T *mgap = il == 1 ? &classmembers : &objmembers;
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
757 for (int mi = 0; mi < mgap->ga_len; ++mi)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
758 {
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
759 char_u *mname = ((ocmember_T *)mgap->ga_data
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
760 + mi)->ocm_name;
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
761 if (STRCMP(aname, mname) == 0)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
762 {
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
763 success = FALSE;
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
764 semsg(_(e_argument_already_declared_in_class_str),
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
765 aname);
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
766 break;
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
767 }
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
768 }
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
769 }
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
770 }
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
771 }
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
772 }
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
773 }
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
774
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
775
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
776 class_T *cl = NULL;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
777 if (success)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
778 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
779 // "endclass" encountered without failures: Create the class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
780
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
781 cl = ALLOC_CLEAR_ONE(class_T);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
782 if (cl == NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
783 goto cleanup;
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
784 if (!is_class)
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
785 cl->class_flags = CLASS_INTERFACE;
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
786
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
787 cl->class_refcount = 1;
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
788 cl->class_name = vim_strnsave(name_start, name_end - name_start);
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
789 if (cl->class_name == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
790 goto cleanup;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
792 cl->class_extends = extends_cl;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
793
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
794 // Add class and object members to "cl".
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
795 if (add_members_to_class(&classmembers,
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
796 extends_cl == NULL ? NULL
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
797 : extends_cl->class_class_members,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
798 extends_cl == NULL ? 0
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
799 : extends_cl->class_class_member_count,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
800 &cl->class_class_members,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
801 &cl->class_class_member_count) == FAIL
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
802 || add_members_to_class(&objmembers,
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
803 extends_cl == NULL ? NULL
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
804 : extends_cl->class_obj_members,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
805 extends_cl == NULL ? 0
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
806 : extends_cl->class_obj_member_count,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
807 &cl->class_obj_members,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
808 &cl->class_obj_member_count) == FAIL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
809 goto cleanup;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
810
31754
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
811 if (ga_impl.ga_len > 0)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
812 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
813 // Move the "implements" names into the class.
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
814 cl->class_interface_count = ga_impl.ga_len;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
815 cl->class_interfaces = ALLOC_MULT(char_u *, ga_impl.ga_len);
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
816 if (cl->class_interfaces == NULL)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
817 goto cleanup;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
818 for (int i = 0; i < ga_impl.ga_len; ++i)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
819 cl->class_interfaces[i] = ((char_u **)ga_impl.ga_data)[i];
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
820 VIM_CLEAR(ga_impl.ga_data);
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
821 ga_impl.ga_len = 0;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
822
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
823 // For each interface add a lookuptable for the member index on the
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
824 // interface to the member index in this class.
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
825 for (int i = 0; i < cl->class_interface_count; ++i)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
826 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
827 class_T *ifcl = intf_classes[i];
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
828 itf2class_T *if2cl = alloc_clear(sizeof(itf2class_T)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
829 + ifcl->class_obj_member_count * sizeof(int));
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
830 if (if2cl == NULL)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
831 goto cleanup;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
832 if2cl->i2c_next = ifcl->class_itf2class;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
833 ifcl->class_itf2class = if2cl;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
834 if2cl->i2c_class = cl;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
835
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
836 for (int if_i = 0; if_i < ifcl->class_obj_member_count; ++if_i)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
837 for (int cl_i = 0; cl_i < cl->class_obj_member_count; ++cl_i)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
838 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
839 if (STRCMP(ifcl->class_obj_members[if_i].ocm_name,
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
840 cl->class_obj_members[cl_i].ocm_name) == 0)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
841 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
842 int *table = (int *)(if2cl + 1);
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
843 table[if_i] = cl_i;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
844 break;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
845 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
846 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
847 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
848
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
849 cl->class_interfaces_cl = intf_classes;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
850 intf_classes = NULL;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
851 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
852
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31608
diff changeset
853 if (is_class && cl->class_class_member_count > 0)
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
854 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
855 // Allocate a typval for each class member and initialize it.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
856 cl->class_members_tv = ALLOC_CLEAR_MULT(typval_T,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
857 cl->class_class_member_count);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
858 if (cl->class_members_tv != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
859 for (int i = 0; i < cl->class_class_member_count; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
860 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
861 ocmember_T *m = &cl->class_class_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
862 typval_T *tv = &cl->class_members_tv[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
863 if (m->ocm_init != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
864 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
865 typval_T *etv = eval_expr(m->ocm_init, eap);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
866 if (etv != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
867 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
868 *tv = *etv;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
869 vim_free(etv);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
870 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
871 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
872 else
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
873 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
874 // TODO: proper default value
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
875 tv->v_type = m->ocm_type->tt_type;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
876 tv->vval.v_string = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
877 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
878 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
879 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
880
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
881 int have_new = FALSE;
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
882 for (int i = 0; i < classfunctions.ga_len; ++i)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
883 if (STRCMP(((ufunc_T **)classfunctions.ga_data)[i]->uf_name,
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
884 "new") == 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
885 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
886 have_new = TRUE;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
887 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
888 }
31732
ef7a9a7eb197 patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31724
diff changeset
889 if (is_class && !is_abstract && !have_new)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
890 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
891 // No new() method was defined, add the default constructor.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
892 garray_T fga;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
893 ga_init2(&fga, 1, 1000);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
894 ga_concat(&fga, (char_u *)"new(");
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
895 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
896 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
897 if (i > 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
898 ga_concat(&fga, (char_u *)", ");
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
899 ga_concat(&fga, (char_u *)"this.");
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
900 ocmember_T *m = cl->class_obj_members + i;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
901 ga_concat(&fga, (char_u *)m->ocm_name);
31441
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31424
diff changeset
902 ga_concat(&fga, (char_u *)" = v:none");
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
903 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
904 ga_concat(&fga, (char_u *)")\nenddef\n");
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
905 ga_append(&fga, NUL);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
906
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
907 exarg_T fea;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
908 CLEAR_FIELD(fea);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
909 fea.cmdidx = CMD_def;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
910 fea.cmd = fea.arg = fga.ga_data;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
911
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
912 garray_T lines_to_free;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
913 ga_init2(&lines_to_free, sizeof(char_u *), 50);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
914
31643
68a9375d4ca3 patch 9.0.1154: Coverity warns for dead code
Bram Moolenaar <Bram@vim.org>
parents: 31641
diff changeset
915 ufunc_T *nf = define_function(&fea, NULL, &lines_to_free, CF_CLASS);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
916
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
917 ga_clear_strings(&lines_to_free);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
918 vim_free(fga.ga_data);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
919
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
920 if (nf != NULL && ga_grow(&classfunctions, 1) == OK)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
921 {
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
922 ((ufunc_T **)classfunctions.ga_data)[classfunctions.ga_len]
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
923 = nf;
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
924 ++classfunctions.ga_len;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
925
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
926 nf->uf_flags |= FC_NEW;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
927 nf->uf_ret_type = get_type_ptr(&type_list);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
928 if (nf->uf_ret_type != NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
929 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
930 nf->uf_ret_type->tt_type = VAR_OBJECT;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
931 nf->uf_ret_type->tt_member = (type_T *)cl;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
932 nf->uf_ret_type->tt_argcount = 0;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
933 nf->uf_ret_type->tt_args = NULL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
934 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
935 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
936 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
937
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
938 // Move all the functions into the created class.
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
939 // loop 1: class functions, loop 2: object methods
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
940 for (int loop = 1; loop <= 2; ++loop)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
941 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
942 garray_T *gap = loop == 1 ? &classfunctions : &objmethods;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
943 int *fcount = loop == 1 ? &cl->class_class_function_count
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
944 : &cl->class_obj_method_count;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
945 ufunc_T ***fup = loop == 1 ? &cl->class_class_functions
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
946 : &cl->class_obj_methods;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
947
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
948 int parent_count = 0;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
949 if (extends_cl != NULL)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
950 // Include functions from the parent.
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
951 parent_count = loop == 1
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
952 ? extends_cl->class_class_function_count
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
953 : extends_cl->class_obj_method_count;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
954
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
955 *fcount = parent_count + gap->ga_len;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
956 if (*fcount == 0)
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
957 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
958 *fup = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
959 continue;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
960 }
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
961 *fup = ALLOC_MULT(ufunc_T *, *fcount);
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
962 if (*fup == NULL)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
963 goto cleanup;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
964
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
965 mch_memmove(*fup, gap->ga_data, sizeof(ufunc_T *) * gap->ga_len);
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
966 vim_free(gap->ga_data);
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
967 if (loop == 1)
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
968 cl->class_class_function_count_child = gap->ga_len;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
969 else
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
970 cl->class_obj_method_count_child = gap->ga_len;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
971
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
972 int skipped = 0;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
973 for (int i = 0; i < parent_count; ++i)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
974 {
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
975 // Copy functions from the parent. Can't use the same
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
976 // function, because "uf_class" is different and compilation
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
977 // will have a different result.
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
978 // Put them after the functions in the current class, object
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
979 // methods may be overruled, then "super.Method()" is used to
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
980 // find a method from the parent.
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
981 // Skip "new" functions. TODO: not all of them.
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
982 if (loop == 1 && STRNCMP(
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
983 extends_cl->class_class_functions[i]->uf_name,
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
984 "new", 3) == 0)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
985 ++skipped;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
986 else
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
987 {
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
988 ufunc_T *pf = (loop == 1
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
989 ? extends_cl->class_class_functions
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
990 : extends_cl->class_obj_methods)[i];
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
991 (*fup)[gap->ga_len + i - skipped] = copy_function(pf);
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
992
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
993 // If the child class overrides a function from the parent
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
994 // the signature must be equal.
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
995 char_u *pname = pf->uf_name;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
996 for (int ci = 0; ci < gap->ga_len; ++ci)
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
997 {
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
998 ufunc_T *cf = (*fup)[ci];
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
999 char_u *cname = cf->uf_name;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1000 if (STRCMP(pname, cname) == 0)
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1001 {
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1002 where_T where = WHERE_INIT;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1003 where.wt_func_name = (char *)pname;
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1004 (void)check_type(pf->uf_func_type, cf->uf_func_type,
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1005 TRUE, where);
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1006 }
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1007 }
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
1008 }
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1009 }
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1010
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1011 *fcount -= skipped;
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1012
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1013 // Set the class pointer on all the functions and object methods.
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1014 for (int i = 0; i < *fcount; ++i)
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1015 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1016 ufunc_T *fp = (*fup)[i];
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1017 fp->uf_class = cl;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1018 if (loop == 2)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1019 fp->uf_flags |= FC_OBJECT;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1020 }
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1021 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1022
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1023 cl->class_type.tt_type = VAR_CLASS;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1024 cl->class_type.tt_member = (type_T *)cl;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1025 cl->class_object_type.tt_type = VAR_OBJECT;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1026 cl->class_object_type.tt_member = (type_T *)cl;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1027 cl->class_type_list = type_list;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1028
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1029 // TODO:
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1030 // - Fill hashtab with object members and methods ?
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1031
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1032 // Add the class to the script-local variables.
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
1033 // TODO: handle other context, e.g. in a function
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1034 typval_T tv;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1035 tv.v_type = VAR_CLASS;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1036 tv.vval.v_class = cl;
31706
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1037 is_export = class_export;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1038 set_var_const(cl->class_name, current_sctx.sc_sid,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1039 NULL, &tv, FALSE, ASSIGN_DECL, 0);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1040 return;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1041 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1042
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1043 cleanup:
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1044 if (cl != NULL)
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1045 {
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1046 vim_free(cl->class_name);
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1047 vim_free(cl->class_class_functions);
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1048 if (cl->class_interfaces != NULL)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1049 {
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1050 for (int i = 0; i < cl->class_interface_count; ++i)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1051 vim_free(cl->class_interfaces[i]);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1052 vim_free(cl->class_interfaces);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1053 }
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1054 if (cl->class_interfaces_cl != NULL)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1055 {
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1056 for (int i = 0; i < cl->class_interface_count; ++i)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1057 class_unref(cl->class_interfaces_cl[i]);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1058 vim_free(cl->class_interfaces_cl);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1059 }
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1060 vim_free(cl->class_obj_members);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1061 vim_free(cl->class_obj_methods);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1062 vim_free(cl);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1063 }
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1064
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1065 vim_free(extends);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1066 class_unref(extends_cl);
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1067
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1068 if (intf_classes != NULL)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1069 {
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1070 for (int i = 0; i < ga_impl.ga_len; ++i)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1071 class_unref(intf_classes[i]);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1072 vim_free(intf_classes);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1073 }
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
1074 ga_clear_strings(&ga_impl);
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
1075
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1076 for (int round = 1; round <= 2; ++round)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1077 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1078 garray_T *gap = round == 1 ? &classmembers : &objmembers;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1079 if (gap->ga_len == 0 || gap->ga_data == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1080 continue;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1081
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1082 for (int i = 0; i < gap->ga_len; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1083 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1084 ocmember_T *m = ((ocmember_T *)gap->ga_data) + i;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1085 vim_free(m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1086 vim_free(m->ocm_init);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1087 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1088 ga_clear(gap);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1089 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1090
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1091 for (int i = 0; i < objmethods.ga_len; ++i)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1092 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1093 ufunc_T *uf = ((ufunc_T **)objmethods.ga_data)[i];
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1094 func_clear_free(uf, FALSE);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1095 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1096 ga_clear(&objmethods);
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1097
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1098 for (int i = 0; i < classfunctions.ga_len; ++i)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1099 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1100 ufunc_T *uf = ((ufunc_T **)classfunctions.ga_data)[i];
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1101 func_clear_free(uf, FALSE);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1102 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1103 ga_clear(&classfunctions);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1104
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1105 clear_type_list(&type_list);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1106 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1107
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1108 /*
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
1109 * Find member "name" in class "cl", set "member_idx" to the member index and
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
1110 * return its type.
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
1111 * When not found "member_idx" is set to -1 and t_any is returned.
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1112 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1113 type_T *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1114 class_member_type(
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1115 class_T *cl,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1116 char_u *name,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1117 char_u *name_end,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1118 int *member_idx)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1119 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1120 *member_idx = -1; // not found (yet)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1121 size_t len = name_end - name;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1122
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1123 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1124 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1125 ocmember_T *m = cl->class_obj_members + i;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1126 if (STRNCMP(m->ocm_name, name, len) == 0 && m->ocm_name[len] == NUL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1127 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1128 *member_idx = i;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1129 return m->ocm_type;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1130 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1131 }
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
1132
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
1133 semsg(_(e_unknown_variable_str), name);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1134 return &t_any;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 * Handle ":enum" up to ":endenum".
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 ex_enum(exarg_T *eap UNUSED)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 * Handle ":type".
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 ex_type(exarg_T *eap UNUSED)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1155 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1156 * Evaluate what comes after a class:
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1157 * - class member: SomeClass.varname
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1158 * - class function: SomeClass.SomeMethod()
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1159 * - class constructor: SomeClass.new()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1160 * - object member: someObject.varname
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1161 * - object method: someObject.SomeMethod()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1162 *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1163 * "*arg" points to the '.'.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1164 * "*arg" is advanced to after the member name or method call.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1165 *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1166 * Returns FAIL or OK.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1167 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1168 int
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1169 class_object_index(
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1170 char_u **arg,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1171 typval_T *rettv,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1172 evalarg_T *evalarg,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1173 int verbose UNUSED) // give error messages
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1174 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1175 // int evaluate = evalarg != NULL
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1176 // && (evalarg->eval_flags & EVAL_EVALUATE);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1177
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1178 if (VIM_ISWHITE((*arg)[1]))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1179 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1180 semsg(_(e_no_white_space_allowed_after_str_str), ".", *arg);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1181 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1182 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1183
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1184 ++*arg;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1185 char_u *name = *arg;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1186 char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1187 if (name_end == name)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1188 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1189 size_t len = name_end - name;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1190
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1191 class_T *cl = rettv->v_type == VAR_CLASS ? rettv->vval.v_class
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1192 : rettv->vval.v_object->obj_class;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1193 if (*name_end == '(')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1194 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1195 int on_class = rettv->v_type == VAR_CLASS;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1196 int count = on_class ? cl->class_class_function_count
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1197 : cl->class_obj_method_count;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1198 for (int i = 0; i < count; ++i)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1199 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1200 ufunc_T *fp = on_class ? cl->class_class_functions[i]
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1201 : cl->class_obj_methods[i];
31418
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
1202 // Use a separate pointer to avoid that ASAN complains about
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
1203 // uf_name[] only being 4 characters.
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
1204 char_u *ufname = (char_u *)fp->uf_name;
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
1205 if (STRNCMP(name, ufname, len) == 0 && ufname[len] == NUL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1206 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1207 typval_T argvars[MAX_FUNC_ARGS + 1];
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1208 int argcount = 0;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1209
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1210 char_u *argp = name_end;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1211 int ret = get_func_arguments(&argp, evalarg, 0,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1212 argvars, &argcount);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1213 if (ret == FAIL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1214 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1215
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1216 funcexe_T funcexe;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1217 CLEAR_FIELD(funcexe);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1218 funcexe.fe_evaluate = TRUE;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1219 if (rettv->v_type == VAR_OBJECT)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1220 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1221 funcexe.fe_object = rettv->vval.v_object;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1222 ++funcexe.fe_object->obj_refcount;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1223 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1224
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1225 // Clear the class or object after calling the function, in
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1226 // case the refcount is one.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1227 typval_T tv_tofree = *rettv;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1228 rettv->v_type = VAR_UNKNOWN;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1229
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1230 // Call the user function. Result goes into rettv;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1231 int error = call_user_func_check(fp, argcount, argvars,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1232 rettv, &funcexe, NULL);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1233
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1234 // Clear the previous rettv and the arguments.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1235 clear_tv(&tv_tofree);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1236 for (int idx = 0; idx < argcount; ++idx)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1237 clear_tv(&argvars[idx]);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1238
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1239 if (error != FCERR_NONE)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1240 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1241 user_func_error(error, printable_func_name(fp),
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1242 funcexe.fe_found_var);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1243 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1244 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1245 *arg = argp;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1246 return OK;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1247 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1248 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1249
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1250 semsg(_(e_method_not_found_on_class_str_str), cl->class_name, name);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1251 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1252
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1253 else if (rettv->v_type == VAR_OBJECT)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1254 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1255 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1256 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1257 ocmember_T *m = &cl->class_obj_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1258 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1259 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
1260 if (*name == '_')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
1261 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1262 semsg(_(e_cannot_access_private_member_str), m->ocm_name);
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
1263 return FAIL;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
1264 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
1265
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1266 // The object only contains a pointer to the class, the member
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1267 // values array follows right after that.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1268 object_T *obj = rettv->vval.v_object;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1269 typval_T *tv = (typval_T *)(obj + 1) + i;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1270 copy_tv(tv, rettv);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1271 object_unref(obj);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1272
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1273 *arg = name_end;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1274 return OK;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1275 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1276 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1277
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1278 semsg(_(e_member_not_found_on_object_str_str), cl->class_name, name);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1279 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1280
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1281 else if (rettv->v_type == VAR_CLASS)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1282 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1283 // class member
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1284 for (int i = 0; i < cl->class_class_member_count; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1285 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1286 ocmember_T *m = &cl->class_class_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1287 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1288 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1289 if (*name == '_')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1290 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1291 semsg(_(e_cannot_access_private_member_str), m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1292 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1293 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1294
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1295 typval_T *tv = &cl->class_members_tv[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1296 copy_tv(tv, rettv);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1297 class_unref(cl);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1298
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1299 *arg = name_end;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1300 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1301 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1302 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1303
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1304 semsg(_(e_member_not_found_on_class_str_str), cl->class_name, name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1305 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1306
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1307 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1308 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1309
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1310 /*
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1311 * If "arg" points to a class or object method, return it.
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1312 * Otherwise return NULL.
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1313 */
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1314 ufunc_T *
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1315 find_class_func(char_u **arg)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1316 {
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1317 char_u *name = *arg;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1318 char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START);
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1319 if (name_end == name || *name_end != '.')
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1320 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1321
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1322 size_t len = name_end - name;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1323 typval_T tv;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1324 tv.v_type = VAR_UNKNOWN;
31592
65a2bae18b27 patch 9.0.1128: build failure
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
1325 if (eval_variable(name, (int)len,
65a2bae18b27 patch 9.0.1128: build failure
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
1326 0, &tv, NULL, EVAL_VAR_NOAUTOLOAD) == FAIL)
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1327 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1328 if (tv.v_type != VAR_CLASS && tv.v_type != VAR_OBJECT)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1329 goto fail_after_eval;
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1330
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1331 class_T *cl = tv.v_type == VAR_CLASS ? tv.vval.v_class
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1332 : tv.vval.v_object->obj_class;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1333 if (cl == NULL)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1334 goto fail_after_eval;
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1335 char_u *fname = name_end + 1;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1336 char_u *fname_end = find_name_end(fname, NULL, NULL, FNE_CHECK_START);
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1337 if (fname_end == fname)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1338 goto fail_after_eval;
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1339 len = fname_end - fname;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1340
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1341 int count = tv.v_type == VAR_CLASS ? cl->class_class_function_count
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1342 : cl->class_obj_method_count;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1343 ufunc_T **funcs = tv.v_type == VAR_CLASS ? cl->class_class_functions
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1344 : cl->class_obj_methods;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1345 for (int i = 0; i < count; ++i)
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1346 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1347 ufunc_T *fp = funcs[i];
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1348 // Use a separate pointer to avoid that ASAN complains about
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1349 // uf_name[] only being 4 characters.
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1350 char_u *ufname = (char_u *)fp->uf_name;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1351 if (STRNCMP(fname, ufname, len) == 0 && ufname[len] == NUL)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1352 {
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1353 clear_tv(&tv);
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1354 return fp;
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1355 }
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1356 }
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1357
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1358 fail_after_eval:
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
1359 clear_tv(&tv);
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1360 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1361 }
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1362
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
1363 /*
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1364 * If "name[len]" is a class member in cctx->ctx_ufunc->uf_class return the
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1365 * index in class.class_class_members[].
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1366 * If "cl_ret" is not NULL set it to the class.
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1367 * Otherwise return -1;
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1368 */
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1369 int
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1370 class_member_index(char_u *name, size_t len, class_T **cl_ret, cctx_T *cctx)
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1371 {
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1372 if (cctx == NULL || cctx->ctx_ufunc == NULL
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1373 || cctx->ctx_ufunc->uf_class == NULL)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1374 return -1;
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1375 class_T *cl = cctx->ctx_ufunc->uf_class;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1376
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1377 for (int i = 0; i < cl->class_class_member_count; ++i)
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1378 {
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1379 ocmember_T *m = &cl->class_class_members[i];
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1380 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1381 {
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1382 if (cl_ret != NULL)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1383 *cl_ret = cl;
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1384 return i;
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1385 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1386 }
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31586
diff changeset
1387 return -1;
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1388 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1389
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
1390 /*
31815
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1391 * Return TRUE if current context "cctx_arg" is inside class "cl".
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1392 * Return FALSE if not.
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1393 */
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1394 int
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1395 inside_class(cctx_T *cctx_arg, class_T *cl)
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1396 {
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1397 for (cctx_T *cctx = cctx_arg; cctx != NULL; cctx = cctx->ctx_outer)
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1398 if (cctx->ctx_ufunc != NULL && cctx->ctx_ufunc->uf_class == cl)
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1399 return TRUE;
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1400 return FALSE;
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1401 }
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1402
64f03e860c91 patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents: 31754
diff changeset
1403 /*
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1404 * Make a copy of an object.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1405 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1406 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1407 copy_object(typval_T *from, typval_T *to)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1408 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1409 *to = *from;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1410 if (to->vval.v_object != NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1411 ++to->vval.v_object->obj_refcount;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1412 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1413
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1414 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1415 * Free an object.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1416 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1417 static void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1418 object_clear(object_T *obj)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1419 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1420 class_T *cl = obj->obj_class;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1421
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1422 // the member values are just after the object structure
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1423 typval_T *tv = (typval_T *)(obj + 1);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1424 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1425 clear_tv(tv + i);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1426
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1427 // Remove from the list headed by "first_object".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1428 object_cleared(obj);
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1429
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1430 vim_free(obj);
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1431 class_unref(cl);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1432 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1433
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1434 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1435 * Unreference an object.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1436 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1437 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1438 object_unref(object_T *obj)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1439 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1440 if (obj != NULL && --obj->obj_refcount <= 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1441 object_clear(obj);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1442 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1443
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1444 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1445 * Make a copy of a class.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1446 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1447 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1448 copy_class(typval_T *from, typval_T *to)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1449 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1450 *to = *from;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1451 if (to->vval.v_class != NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1452 ++to->vval.v_class->class_refcount;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1453 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1454
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1455 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1456 * Unreference a class. Free it when the reference count goes down to zero.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1457 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1458 void
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1459 class_unref(class_T *cl)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1460 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1461 if (cl != NULL && --cl->class_refcount <= 0 && cl->class_name != NULL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1462 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1463 // Freeing what the class contains may recursively come back here.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1464 // Clear "class_name" first, if it is NULL the class does not need to
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1465 // be freed.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1466 VIM_CLEAR(cl->class_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1467
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1468 class_unref(cl->class_extends);
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
1469
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
1470 for (int i = 0; i < cl->class_interface_count; ++i)
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1471 {
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
1472 vim_free(((char_u **)cl->class_interfaces)[i]);
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1473 if (cl->class_interfaces_cl[i] != NULL)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1474 class_unref(cl->class_interfaces_cl[i]);
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1475 }
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
1476 vim_free(cl->class_interfaces);
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
1477 vim_free(cl->class_interfaces_cl);
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
1478
31754
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
1479 itf2class_T *next;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
1480 for (itf2class_T *i2c = cl->class_itf2class; i2c != NULL; i2c = next)
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
1481 {
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
1482 next = i2c->i2c_next;
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
1483 vim_free(i2c);
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
1484 }
48431422f766 patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents: 31746
diff changeset
1485
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1486 for (int i = 0; i < cl->class_class_member_count; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1487 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1488 ocmember_T *m = &cl->class_class_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1489 vim_free(m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1490 vim_free(m->ocm_init);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1491 if (cl->class_members_tv != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1492 clear_tv(&cl->class_members_tv[i]);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1493 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1494 vim_free(cl->class_class_members);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1495 vim_free(cl->class_members_tv);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1496
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1497 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1498 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1499 ocmember_T *m = &cl->class_obj_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1500 vim_free(m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
1501 vim_free(m->ocm_init);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1502 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1503 vim_free(cl->class_obj_members);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1504
31586
f36f920bad1a patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
1505 for (int i = 0; i < cl->class_class_function_count; ++i)
f36f920bad1a patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
1506 {
f36f920bad1a patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
1507 ufunc_T *uf = cl->class_class_functions[i];
f36f920bad1a patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
1508 func_clear_free(uf, FALSE);
f36f920bad1a patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
1509 }
f36f920bad1a patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
1510 vim_free(cl->class_class_functions);
f36f920bad1a patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
1511
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1512 for (int i = 0; i < cl->class_obj_method_count; ++i)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1513 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1514 ufunc_T *uf = cl->class_obj_methods[i];
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1515 func_clear_free(uf, FALSE);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
1516 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1517 vim_free(cl->class_obj_methods);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1518
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1519 clear_type_list(&cl->class_type_list);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1520
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1521 vim_free(cl);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1522 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1523 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
1524
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1525 static object_T *first_object = NULL;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1526
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1527 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1528 * Call this function when an object has been created. It will be added to the
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1529 * list headed by "first_object".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1530 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1531 void
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1532 object_created(object_T *obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1533 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1534 if (first_object != NULL)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1535 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1536 obj->obj_next_used = first_object;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1537 first_object->obj_prev_used = obj;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1538 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1539 first_object = obj;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1540 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1541
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1542 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1543 * Call this function when an object has been cleared and is about to be freed.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1544 * It is removed from the list headed by "first_object".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1545 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1546 void
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1547 object_cleared(object_T *obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1548 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1549 if (obj->obj_next_used != NULL)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1550 obj->obj_next_used->obj_prev_used = obj->obj_prev_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1551 if (obj->obj_prev_used != NULL)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1552 obj->obj_prev_used->obj_next_used = obj->obj_next_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1553 else if (first_object == obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1554 first_object = obj->obj_next_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1555 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1556
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1557 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1558 * Go through the list of all objects and free items without "copyID".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1559 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1560 int
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1561 object_free_nonref(int copyID)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1562 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1563 int did_free = FALSE;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1564 object_T *next_obj;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1565
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1566 for (object_T *obj = first_object; obj != NULL; obj = next_obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1567 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1568 next_obj = obj->obj_next_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1569 if ((obj->obj_copyID & COPYID_MASK) != (copyID & COPYID_MASK))
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1570 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1571 // Free the object and items it contains.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1572 object_clear(obj);
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1573 did_free = TRUE;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1574 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1575 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1576
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1577 return did_free;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1578 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1579
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 #endif // FEAT_EVAL