Mercurial > vim
annotate src/vim9class.c @ 32303:71c5920fb43e v9.0.1483
patch 9.0.1483: += operator does not work on class member
Commit: https://github.com/vim/vim/commit/22363c69945e48a7496f0ae00bc06235084ddd7a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 24 17:15:25 2023 +0100
patch 9.0.1483: += operator does not work on class member
Problem: += operator does not work on class member.
Solution: Do not skip as if "this." was used. (Christian Brabandt,
closes #12263)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 24 Apr 2023 18:30:04 +0200 |
parents | d542423ef5c9 |
children | feb9a581eb00 |
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); |
32100
fcc497515cce
patch 9.0.1381: ACCESS_ names have a conflict with on some systems
Bram Moolenaar <Bram@vim.org>
parents:
32047
diff
changeset
|
151 m->ocm_access = has_public ? VIM_ACCESS_ALL |
fcc497515cce
patch 9.0.1381: ACCESS_ names have a conflict with on some systems
Bram Moolenaar <Bram@vim.org>
parents:
32047
diff
changeset
|
152 : *varname == '_' ? VIM_ACCESS_PRIVATE : VIM_ACCESS_READ; |
31483
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 |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
204 object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl) |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
205 { |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
206 if (idx > (is_method ? itf->class_obj_method_count |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
207 : itf->class_obj_member_count)) |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
208 { |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
209 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
|
210 return 0; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
211 } |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
212 itf2class_T *i2c; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
213 for (i2c = itf->class_itf2class; i2c != NULL; i2c = i2c->i2c_next) |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
214 if (i2c->i2c_class == cl && i2c->i2c_is_method == is_method) |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
215 break; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
216 if (i2c == NULL) |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
217 { |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
218 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
|
219 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
|
220 return 0; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
221 } |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
222 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
|
223 return table[idx]; |
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 |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
226 /* |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 * 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
|
228 * 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
|
229 */ |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 void |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 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
|
232 { |
32047
b49db96c1e55
patch 9.0.1355: no error when declaring a class twice
Bram Moolenaar <Bram@vim.org>
parents:
32005
diff
changeset
|
233 int is_class = eap->cmdidx == CMD_class; // FALSE for :interface |
b49db96c1e55
patch 9.0.1355: no error when declaring a class twice
Bram Moolenaar <Bram@vim.org>
parents:
32005
diff
changeset
|
234 long start_lnum = SOURCING_LNUM; |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
235 |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 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
|
237 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
|
238 if (is_abstract) |
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 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
|
241 { |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 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
|
243 return; |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 } |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 arg = skipwhite(arg + 5); |
31732
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
246 is_class = TRUE; |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
247 } |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
248 |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
249 if (!current_script_is_vim9() |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
250 || (cmdmod.cmod_flags & CMOD_LEGACY) |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
251 || !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
|
252 { |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
253 if (is_class) |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
254 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
|
255 else |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
256 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
|
257 return; |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 } |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 if (!ASCII_ISUPPER(*arg)) |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 { |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
262 if (is_class) |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
263 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
|
264 else |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
265 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
|
266 arg); |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 return; |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
269 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
|
270 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
|
271 { |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
272 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
|
273 return; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
274 } |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
275 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
|
276 |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
277 // "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
|
278 // 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
|
279 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
|
280 is_export = FALSE; |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
281 |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 // TODO: |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
283 // generics: <Tkey, Tentry> |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
284 |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
285 // 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
|
286 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
|
287 |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
288 // Names for "implements SomeInterface" |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
289 garray_T ga_impl; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
290 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
|
291 |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
292 arg = skipwhite(name_end); |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
293 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
|
294 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
295 // TODO: |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
296 // specifies SomeInterface |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
297 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
|
298 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
299 if (extends != NULL) |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
300 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
301 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
|
302 goto early_ret; |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
303 } |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
308 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
|
309 goto early_ret; |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
310 } |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
311 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
|
312 if (extends == NULL) |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
313 goto early_ret; |
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 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
|
316 } |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
317 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
|
318 && 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
|
319 { |
31649
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
320 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
|
321 { |
31649
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
322 emsg(_(e_duplicate_implements)); |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
323 goto early_ret; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
324 } |
31649
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
325 arg = skipwhite(arg + 10); |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
326 |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
327 for (;;) |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
328 { |
31649
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
329 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
|
330 FNE_CHECK_START); |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
331 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
|
332 { |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
333 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
|
334 goto early_ret; |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
335 } |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
336 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
|
337 if (iname == NULL) |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
338 goto early_ret; |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
339 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
|
340 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
|
341 { |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
342 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
|
343 iname); |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
344 vim_free(iname); |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
345 goto early_ret; |
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 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
|
348 { |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
349 vim_free(iname); |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
350 goto early_ret; |
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 if (*impl_end != ',') |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
353 { |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
354 arg = skipwhite(impl_end); |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
355 break; |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
356 } |
520857d1fda7
patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents:
31643
diff
changeset
|
357 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
|
358 } |
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 else |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
361 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
362 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
|
363 early_ret: |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
364 vim_free(extends); |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
365 ga_clear_strings(&ga_impl); |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
366 return; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
367 } |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
368 } |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
369 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
370 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
|
371 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
|
372 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
373 // 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
|
374 garray_T classmembers; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
375 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
|
376 |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
377 // 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
|
378 garray_T classfunctions; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
379 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
|
380 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
381 // 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
|
382 garray_T objmembers; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
383 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
|
384 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
385 // 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
|
386 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
|
387 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
|
388 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
389 /* |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
390 * 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
|
391 * "endinterface" is found. |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
392 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
393 char_u *theline = NULL; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
394 int success = FALSE; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
395 for (;;) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
396 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
397 vim_free(theline); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
398 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
|
399 if (theline == NULL) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
400 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
401 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
|
402 |
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
|
403 // 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
|
404 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
|
405 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
|
406 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
|
407 { |
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 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
|
409 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
|
410 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
|
411 } |
560ba934725f
patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents:
31487
diff
changeset
|
412 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
413 char_u *p = line; |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
414 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
|
415 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
|
416 { |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 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
|
421 else |
c82cb53474ee
patch 9.0.1037: lalloc(0) error for a class without members
Bram Moolenaar <Bram@vim.org>
parents:
31404
diff
changeset
|
422 success = TRUE; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
423 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
424 } |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
425 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
|
426 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
|
427 { |
31833
3516e35f409f
patch 9.0.1249: cannot export an abstract class
Bram Moolenaar <Bram@vim.org>
parents:
31815
diff
changeset
|
428 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
|
429 break; |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
430 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
431 |
31455
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
432 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
|
433 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
|
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 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
|
436 { |
31455
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
437 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
|
438 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
439 } |
31455
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
440 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
|
441 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
|
442 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
443 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
|
444 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
445 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
|
446 break; |
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
447 } |
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
448 } |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
449 |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
450 int has_static = FALSE; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
451 char_u *ps = p; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
452 if (checkforcmd(&p, "static", 4)) |
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 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
|
455 { |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
456 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
|
457 break; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
458 } |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
459 has_static = TRUE; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
460 p = skipwhite(ps + 6); |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
461 } |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
462 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
463 // 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
|
464 // "this._varname" |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
465 // "this.varname" |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
466 // "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
|
467 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
|
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 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
|
470 { |
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
471 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
|
472 break; |
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
473 } |
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
474 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
|
475 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
|
476 type_T *type = NULL; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
477 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
|
478 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
|
479 &varname_end, &type_list, &type, |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
480 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
|
481 break; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
482 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
|
483 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
|
484 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
485 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
|
486 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
487 } |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
488 } |
31443
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31441
diff
changeset
|
489 |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
490 // constructors: |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
491 // def new() |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
492 // enddef |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
493 // def newOther() |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
494 // enddef |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
495 // object methods and class functions: |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
496 // def SomeMethod() |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
497 // enddef |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
498 // 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
|
499 // enddef |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
500 // TODO: |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
501 // def <Tval> someMethod() |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
502 // enddef |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
503 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
|
504 { |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
505 exarg_T ea; |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
506 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
|
507 |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
508 // 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
|
509 |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
510 CLEAR_FIELD(ea); |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
511 ea.cmd = line; |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
512 ea.arg = p; |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
513 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
|
514 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
|
515 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
|
516 |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
517 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
|
518 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
|
519 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
|
520 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
|
521 |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
522 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
|
523 { |
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
|
524 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
|
525 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
|
526 if (is_new && is_abstract) |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
527 { |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
528 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
|
529 success = FALSE; |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
530 break; |
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
531 } |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
532 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
|
533 ? &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
|
534 // 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
|
535 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
|
536 { |
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 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
|
538 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
|
539 { |
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 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
|
541 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
|
542 } |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
543 } |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
544 |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
545 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
|
546 { |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
547 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
|
548 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
|
549 |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
550 ((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
|
551 ++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
|
552 } |
31582
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 } |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
555 |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
556 // class members |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
557 else if (has_static) |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
558 { |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
559 // 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
|
560 // "static _varname" |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
561 // "static varname" |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
562 // "public static varname" |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
563 char_u *varname = p; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
564 char_u *varname_end = NULL; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
565 type_T *type = NULL; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
566 char_u *init_expr = NULL; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
567 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
|
568 &varname_end, &type_list, &type, |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
569 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
|
570 break; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
571 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
|
572 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
|
573 { |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
574 vim_free(init_expr); |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
575 break; |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
576 } |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
577 } |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
578 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
579 else |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
580 { |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
581 if (is_class) |
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_class_str), line); |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
583 else |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
584 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
|
585 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
586 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
587 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
588 vim_free(theline); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
589 |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
590 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
|
591 |
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 * 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
|
594 */ |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
595 |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
596 // 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
|
597 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
|
598 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
599 typval_T tv; |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
600 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
|
601 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
|
602 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
603 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
|
604 success = FALSE; |
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 else |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
607 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
608 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
|
609 || 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
|
610 || (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
|
611 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
612 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
|
613 success = FALSE; |
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 else |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
616 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
617 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
|
618 ++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
|
619 } |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
620 clear_tv(&tv); |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
621 } |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
622 } |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
623 VIM_CLEAR(extends); |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
624 |
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
|
625 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
|
626 |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
627 // 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
|
628 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
|
629 { |
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
|
630 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
|
631 |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
632 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
|
633 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
634 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
|
635 typval_T tv; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
636 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
|
637 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
|
638 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
639 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
|
640 success = FALSE; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
641 break; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
642 } |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
643 |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
644 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
|
645 || tv.vval.v_class == NULL |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
646 || (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
|
647 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
648 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
|
649 success = FALSE; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
650 } |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
651 |
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
|
652 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
|
653 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
|
654 ++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
|
655 |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
656 // 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
|
657 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
|
658 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
659 // loop == 1: check class members |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
660 // loop == 2: check object members |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
661 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
|
662 : ifcl->class_obj_member_count; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
663 if (if_count == 0) |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
664 continue; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
665 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
|
666 : ifcl->class_obj_members; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
667 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
|
668 ? classmembers.ga_data |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
669 : objmembers.ga_data); |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
670 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
|
671 : objmembers.ga_len; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
672 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
|
673 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
674 int cl_i; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
675 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
|
676 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
677 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
|
678 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
|
679 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
680 // TODO: check type |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
681 break; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
682 } |
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 if (cl_i == cl_count) |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
685 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
686 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
|
687 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
|
688 success = FALSE; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
689 break; |
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 } |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
693 |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
694 // 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
|
695 // functions/methods of the class |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
696 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
|
697 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
698 // loop == 1: check class functions |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
699 // loop == 2: check object methods |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
700 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
|
701 : ifcl->class_obj_method_count; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
702 if (if_count == 0) |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
703 continue; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
704 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
|
705 : ifcl->class_obj_methods; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
706 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
|
707 ? classfunctions.ga_data |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
708 : objmethods.ga_data); |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
709 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
|
710 : objmethods.ga_len; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
711 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
|
712 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
713 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
|
714 int cl_i; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
715 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
|
716 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
717 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
|
718 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
|
719 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
720 // 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
|
721 break; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
722 } |
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 if (cl_i == cl_count) |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
725 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
726 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
|
727 if_name, impl); |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
728 success = FALSE; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
729 break; |
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 } |
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 clear_tv(&tv); |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
735 } |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
736 } |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
737 |
31720
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
738 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
|
739 { |
32270
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
740 // Check no function argument name is used as a class member. |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
741 // (Object members are always accessed with "this." prefix, so no need |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
742 // to check them.) |
31720
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 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
|
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 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
|
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 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
|
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 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
|
750 |
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
751 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
|
752 { |
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
753 char_u *aname = ((char_u **)uf->uf_args.ga_data)[i]; |
32270
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
754 garray_T *mgap = &classmembers; |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
755 |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
756 for (int mi = 0; mi < mgap->ga_len; ++mi) |
31720
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
757 { |
32270
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
758 char_u *mname = ((ocmember_T *)mgap->ga_data + mi) |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
759 ->ocm_name; |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
760 if (STRCMP(aname, mname) == 0) |
31720
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
761 { |
32270
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
762 success = FALSE; |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
763 |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
764 if (uf->uf_script_ctx.sc_sid > 0) |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
765 SOURCING_LNUM = uf->uf_script_ctx.sc_lnum; |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
766 |
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
767 semsg(_(e_argument_already_declared_in_class_str), |
31720
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
768 aname); |
32270
d542423ef5c9
patch 9.0.1466: cannot use an object member name as a method argument
Bram Moolenaar <Bram@vim.org>
parents:
32142
diff
changeset
|
769 break; |
31720
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 } |
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
776 |
1949c2613b3e
patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
777 |
31447
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
778 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
|
779 if (success) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
780 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
781 // "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
|
782 |
31447
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
783 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
|
784 if (cl == NULL) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
785 goto cleanup; |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
786 if (!is_class) |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
787 cl->class_flags = CLASS_INTERFACE; |
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
788 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
789 cl->class_refcount = 1; |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
790 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
|
791 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
|
792 goto cleanup; |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
794 if (extends_cl != NULL) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
795 { |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
796 cl->class_extends = extends_cl; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
797 extends_cl->class_flags |= CLASS_EXTENDED; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
798 } |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
799 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
800 // 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
|
801 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
|
802 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
|
803 : 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
|
804 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
|
805 : 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
|
806 &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
|
807 &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
|
808 || 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
|
809 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
|
810 : 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
|
811 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
|
812 : 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
|
813 &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
|
814 &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
|
815 goto cleanup; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
816 |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
817 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
|
818 { |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
819 // 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
|
820 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
|
821 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
|
822 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
|
823 goto cleanup; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
824 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
|
825 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
|
826 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
|
827 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
|
828 |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
829 cl->class_interfaces_cl = intf_classes; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
830 intf_classes = NULL; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
831 } |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
832 |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
833 if (cl->class_interface_count > 0 || extends_cl != NULL) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
834 { |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
835 // 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
|
836 // interface to the member index in this class. |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
837 // And a lookuptable for the object method index on the interface |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
838 // to the object method index in this class. |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
839 // Also do this for the extended class, if any. |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
840 for (int i = 0; i <= cl->class_interface_count; ++i) |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
841 { |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
842 class_T *ifcl = i < cl->class_interface_count |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
843 ? cl->class_interfaces_cl[i] |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
844 : extends_cl; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
845 if (ifcl == NULL) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
846 continue; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
847 |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
848 // Table for members. |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
849 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
|
850 + 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
|
851 if (if2cl == NULL) |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
852 goto cleanup; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
853 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
|
854 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
|
855 if2cl->i2c_class = cl; |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
856 if2cl->i2c_is_method = FALSE; |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
857 |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
858 for (int if_i = 0; if_i < ifcl->class_obj_member_count; ++if_i) |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
859 for (int cl_i = 0; cl_i < cl->class_obj_member_count; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
860 ++cl_i) |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
861 { |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
862 if (STRCMP(ifcl->class_obj_members[if_i].ocm_name, |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
863 cl->class_obj_members[cl_i].ocm_name) == 0) |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
864 { |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
865 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
|
866 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
|
867 break; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
868 } |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
869 } |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
870 |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
871 // Table for methods. |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
872 if2cl = alloc_clear(sizeof(itf2class_T) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
873 + ifcl->class_obj_method_count * sizeof(int)); |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
874 if (if2cl == NULL) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
875 goto cleanup; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
876 if2cl->i2c_next = ifcl->class_itf2class; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
877 ifcl->class_itf2class = if2cl; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
878 if2cl->i2c_class = cl; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
879 if2cl->i2c_is_method = TRUE; |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
880 |
31843
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
881 for (int if_i = 0; if_i < ifcl->class_obj_method_count; ++if_i) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
882 { |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
883 int done = FALSE; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
884 for (int cl_i = 0; cl_i < objmethods.ga_len; ++cl_i) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
885 { |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
886 if (STRCMP(ifcl->class_obj_methods[if_i]->uf_name, |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
887 ((ufunc_T **)objmethods.ga_data)[cl_i]->uf_name) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
888 == 0) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
889 { |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
890 int *table = (int *)(if2cl + 1); |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
891 table[if_i] = cl_i; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
892 done = TRUE; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
893 break; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
894 } |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
895 } |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
896 |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
897 if (!done && extends_cl != NULL) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
898 { |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
899 for (int cl_i = 0; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
900 cl_i < extends_cl->class_obj_member_count; ++cl_i) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
901 { |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
902 if (STRCMP(ifcl->class_obj_methods[if_i]->uf_name, |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
903 extends_cl->class_obj_methods[cl_i]->uf_name) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
904 == 0) |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
905 { |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
906 int *table = (int *)(if2cl + 1); |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
907 table[if_i] = cl_i; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
908 break; |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
909 } |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
910 } |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
911 } |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
912 } |
ffa11e2757e7
patch 9.0.1254: calling a method on an interface does not work
Bram Moolenaar <Bram@vim.org>
parents:
31833
diff
changeset
|
913 } |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
914 } |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
915 |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31608
diff
changeset
|
916 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
|
917 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
918 // 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
|
919 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
|
920 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
|
921 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
|
922 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
|
923 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
924 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
|
925 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
|
926 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
|
927 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
928 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
|
929 if (etv != NULL) |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
930 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
931 *tv = *etv; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
932 vim_free(etv); |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
933 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
934 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
935 else |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
936 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
937 // TODO: proper default value |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
938 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
|
939 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
|
940 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
941 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
942 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
943 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
944 int have_new = FALSE; |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
945 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
|
946 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
|
947 "new") == 0) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
948 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
949 have_new = TRUE; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
950 break; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
951 } |
31732
ef7a9a7eb197
patch 9.0.1198: abstract class not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31724
diff
changeset
|
952 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
|
953 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
954 // 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
|
955 garray_T fga; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
960 if (i > 0) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
967 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
|
968 ga_append(&fga, NUL); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
969 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
970 exarg_T fea; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
971 CLEAR_FIELD(fea); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
972 fea.cmdidx = CMD_def; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
973 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
|
974 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
975 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
|
976 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
|
977 |
31643
68a9375d4ca3
patch 9.0.1154: Coverity warns for dead code
Bram Moolenaar <Bram@vim.org>
parents:
31641
diff
changeset
|
978 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
|
979 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
980 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
|
981 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
|
982 |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
983 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
|
984 { |
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
|
985 ((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
|
986 = nf; |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
987 ++classfunctions.ga_len; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
988 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
989 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
|
990 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
|
991 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
|
992 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
993 nf->uf_ret_type->tt_type = VAR_OBJECT; |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31970
diff
changeset
|
994 nf->uf_ret_type->tt_class = cl; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
995 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
|
996 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
|
997 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
998 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
999 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1000 |
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
|
1001 // 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
|
1002 // 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
|
1003 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
|
1004 { |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1005 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
|
1006 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
|
1007 : &cl->class_obj_method_count; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1008 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
|
1009 : &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
|
1010 |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1011 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
|
1012 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
|
1013 // 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
|
1014 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
|
1015 ? 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
|
1016 : 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
|
1017 |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1018 *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
|
1019 if (*fcount == 0) |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1020 { |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1021 *fup = NULL; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1022 continue; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1023 } |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1024 *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
|
1025 if (*fup == NULL) |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1026 goto cleanup; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1027 |
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
|
1028 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
|
1029 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
|
1030 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
|
1031 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
|
1032 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
|
1033 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
|
1034 |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1035 int skipped = 0; |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1036 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
|
1037 { |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1038 // 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
|
1039 // 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
|
1040 // 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
|
1041 // 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
|
1042 // 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
|
1043 // 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
|
1044 // 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
|
1045 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
|
1046 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
|
1047 "new", 3) == 0) |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1048 ++skipped; |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1049 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
|
1050 { |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
1051 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
|
1052 ? 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
|
1053 : 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
|
1054 (*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
|
1055 |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
1056 // 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
|
1057 // 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
|
1058 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
|
1059 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
|
1060 { |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
1061 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
|
1062 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
|
1063 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
|
1064 { |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
1065 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
|
1066 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
|
1067 (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
|
1068 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
|
1069 } |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
1070 } |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31653
diff
changeset
|
1071 } |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1072 } |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1073 |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1074 *fcount -= skipped; |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1075 |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1076 // 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
|
1077 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
|
1078 { |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1079 ufunc_T *fp = (*fup)[i]; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1080 fp->uf_class = cl; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1081 if (loop == 2) |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1082 fp->uf_flags |= FC_OBJECT; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1083 } |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1084 } |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1085 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1086 cl->class_type.tt_type = VAR_CLASS; |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31970
diff
changeset
|
1087 cl->class_type.tt_class = cl; |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1088 cl->class_object_type.tt_type = VAR_OBJECT; |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31970
diff
changeset
|
1089 cl->class_object_type.tt_class = cl; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1090 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
|
1091 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1092 // TODO: |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1093 // - 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
|
1094 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1095 // 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
|
1096 // 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
|
1097 typval_T tv; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1098 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
|
1099 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
|
1100 is_export = class_export; |
32047
b49db96c1e55
patch 9.0.1355: no error when declaring a class twice
Bram Moolenaar <Bram@vim.org>
parents:
32005
diff
changeset
|
1101 SOURCING_LNUM = start_lnum; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1102 set_var_const(cl->class_name, current_sctx.sc_sid, |
32047
b49db96c1e55
patch 9.0.1355: no error when declaring a class twice
Bram Moolenaar <Bram@vim.org>
parents:
32005
diff
changeset
|
1103 NULL, &tv, FALSE, 0, 0); |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1104 return; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1105 } |
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 cleanup: |
31447
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1108 if (cl != NULL) |
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1109 { |
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1110 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
|
1111 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
|
1112 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
|
1113 { |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
1114 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
|
1115 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
|
1116 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
|
1117 } |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
1118 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
|
1119 { |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
1120 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
|
1121 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
|
1122 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
|
1123 } |
31447
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1124 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
|
1125 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
|
1126 vim_free(cl); |
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1127 } |
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1128 |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1129 vim_free(extends); |
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1130 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
|
1131 |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
1132 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
|
1133 { |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
1134 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
|
1135 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
|
1136 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
|
1137 } |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
1138 ga_clear_strings(&ga_impl); |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
1139 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1140 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
|
1141 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1142 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
|
1143 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
|
1144 continue; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1145 |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1146 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
|
1147 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1148 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
|
1149 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
|
1150 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
|
1151 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1152 ga_clear(gap); |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1153 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1154 |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1155 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
|
1156 { |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1157 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
|
1158 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
|
1159 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1160 ga_clear(&objmethods); |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1161 |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1162 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
|
1163 { |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1164 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
|
1165 func_clear_free(uf, FALSE); |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1166 } |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1167 ga_clear(&classfunctions); |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1168 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1169 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
|
1170 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1171 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1172 /* |
31517
cd5247f4da06
patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
31501
diff
changeset
|
1173 * 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
|
1174 * 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
|
1175 * 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
|
1176 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1177 type_T * |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1178 class_member_type( |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1179 class_T *cl, |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1180 char_u *name, |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1181 char_u *name_end, |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1182 int *member_idx) |
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 *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
|
1185 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
|
1186 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1187 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
|
1188 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1189 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
|
1190 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
|
1191 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1192 *member_idx = i; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1193 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
|
1194 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1195 } |
31517
cd5247f4da06
patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
31501
diff
changeset
|
1196 |
cd5247f4da06
patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
31501
diff
changeset
|
1197 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
|
1198 return &t_any; |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 } |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 /* |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 * 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
|
1203 */ |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 void |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 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
|
1206 { |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 // TODO |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 } |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 /* |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 * Handle ":type". |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 */ |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 void |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 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
|
1215 { |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 // TODO |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 } |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1219 /* |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1220 * 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
|
1221 * - class member: SomeClass.varname |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1222 * - 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
|
1223 * - class constructor: SomeClass.new() |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1224 * - object member: someObject.varname |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1225 * - object method: someObject.SomeMethod() |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1226 * |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1227 * "*arg" points to the '.'. |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1228 * "*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
|
1229 * |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1230 * Returns FAIL or OK. |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1231 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1232 int |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1233 class_object_index( |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1234 char_u **arg, |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1235 typval_T *rettv, |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1236 evalarg_T *evalarg, |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1237 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
|
1238 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1239 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
|
1240 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1241 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
|
1242 return FAIL; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1243 } |
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; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1246 char_u *name = *arg; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1247 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
|
1248 if (name_end == name) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1249 return FAIL; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1250 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
|
1251 |
31970
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1252 class_T *cl; |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1253 if (rettv->v_type == VAR_CLASS) |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1254 cl = rettv->vval.v_class; |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1255 else // VAR_OBJECT |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1256 { |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1257 if (rettv->vval.v_object == NULL) |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1258 { |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1259 emsg(_(e_using_null_object)); |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1260 return FAIL; |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1261 } |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1262 cl = rettv->vval.v_object->obj_class; |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1263 } |
fe66019e7a23
patch 9.0.1317: crash when using an unset object variable
Bram Moolenaar <Bram@vim.org>
parents:
31843
diff
changeset
|
1264 |
32142
64e8cd965e79
patch 9.0.1402: crash when using null_class
Bram Moolenaar <Bram@vim.org>
parents:
32100
diff
changeset
|
1265 if (cl == NULL) |
64e8cd965e79
patch 9.0.1402: crash when using null_class
Bram Moolenaar <Bram@vim.org>
parents:
32100
diff
changeset
|
1266 { |
64e8cd965e79
patch 9.0.1402: crash when using null_class
Bram Moolenaar <Bram@vim.org>
parents:
32100
diff
changeset
|
1267 emsg(_(e_incomplete_type)); |
64e8cd965e79
patch 9.0.1402: crash when using null_class
Bram Moolenaar <Bram@vim.org>
parents:
32100
diff
changeset
|
1268 return FAIL; |
64e8cd965e79
patch 9.0.1402: crash when using null_class
Bram Moolenaar <Bram@vim.org>
parents:
32100
diff
changeset
|
1269 } |
64e8cd965e79
patch 9.0.1402: crash when using null_class
Bram Moolenaar <Bram@vim.org>
parents:
32100
diff
changeset
|
1270 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1271 if (*name_end == '(') |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1272 { |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1273 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
|
1274 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
|
1275 : cl->class_obj_method_count; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1276 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
|
1277 { |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1278 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
|
1279 : 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
|
1280 // 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
|
1281 // 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
|
1282 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
|
1283 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
|
1284 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1285 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
|
1286 int argcount = 0; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1287 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1288 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
|
1289 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
|
1290 argvars, &argcount); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1291 if (ret == FAIL) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1292 return FAIL; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1293 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1294 funcexe_T funcexe; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1295 CLEAR_FIELD(funcexe); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1296 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
|
1297 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
|
1298 { |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1299 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
|
1300 ++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
|
1301 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1302 |
31404
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1303 // 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
|
1304 // 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
|
1305 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
|
1306 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
|
1307 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1308 // 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
|
1309 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
|
1310 rettv, &funcexe, NULL); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1311 |
31404
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1312 // 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
|
1313 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
|
1314 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
|
1315 clear_tv(&argvars[idx]); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1316 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1317 if (error != FCERR_NONE) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1318 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1319 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
|
1320 funcexe.fe_found_var); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1321 return FAIL; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1322 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1323 *arg = argp; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1324 return OK; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1325 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1326 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1327 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1328 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
|
1329 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1330 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1331 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
|
1332 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1333 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
|
1334 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1335 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
|
1336 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
|
1337 { |
31455
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
1338 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
|
1339 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1340 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
|
1341 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
|
1342 } |
5ef28f5ff357
patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31447
diff
changeset
|
1343 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1344 // 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
|
1345 // 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
|
1346 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
|
1347 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
|
1348 copy_tv(tv, rettv); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1349 object_unref(obj); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1350 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1351 *arg = name_end; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1352 return OK; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1353 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1354 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1355 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1356 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
|
1357 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1358 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1359 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
|
1360 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1361 // class member |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1362 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
|
1363 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1364 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
|
1365 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
|
1366 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1367 if (*name == '_') |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1368 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1369 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
|
1370 return FAIL; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1371 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1372 |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1373 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
|
1374 copy_tv(tv, rettv); |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1375 class_unref(cl); |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1376 |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1377 *arg = name_end; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1378 return OK; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1379 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1380 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1381 |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1382 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
|
1383 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1384 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1385 return FAIL; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1386 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1387 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1388 /* |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1389 * 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
|
1390 * 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
|
1391 */ |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1392 ufunc_T * |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1393 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
|
1394 { |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1395 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
|
1396 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
|
1397 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
|
1398 return NULL; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1399 |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1400 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
|
1401 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
|
1402 tv.v_type = VAR_UNKNOWN; |
31592
65a2bae18b27
patch 9.0.1128: build failure
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1403 if (eval_variable(name, (int)len, |
65a2bae18b27
patch 9.0.1128: build failure
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1404 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
|
1405 return NULL; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1406 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
|
1407 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
|
1408 |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1409 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
|
1410 : 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
|
1411 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
|
1412 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
|
1413 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
|
1414 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
|
1415 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
|
1416 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
|
1417 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
|
1418 |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1419 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
|
1420 : cl->class_obj_method_count; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1421 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
|
1422 : cl->class_obj_methods; |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1423 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
|
1424 { |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1425 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
|
1426 // 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
|
1427 // 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
|
1428 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
|
1429 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
|
1430 { |
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1431 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
|
1432 return fp; |
31447
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1433 } |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1434 } |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1435 |
31447
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1436 fail_after_eval: |
8cb31f7ac9e2
patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents:
31443
diff
changeset
|
1437 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
|
1438 return NULL; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1439 } |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1440 |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31418
diff
changeset
|
1441 /* |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
1442 * 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
|
1443 * 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
|
1444 * 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
|
1445 * Otherwise return -1; |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1446 */ |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1447 int |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
1448 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
|
1449 { |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
1450 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
|
1451 || 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
|
1452 return -1; |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1453 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
|
1454 |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
1455 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
|
1456 { |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
1457 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
|
1458 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
|
1459 { |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
1460 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
|
1461 *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
|
1462 return i; |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1463 } |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1464 } |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31586
diff
changeset
|
1465 return -1; |
31582
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1466 } |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1467 |
8bbc932fbd09
patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
1468 /* |
31815
64f03e860c91
patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
1469 * 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
|
1470 * 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
|
1471 */ |
64f03e860c91
patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
1472 int |
64f03e860c91
patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
1473 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
|
1474 { |
64f03e860c91
patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
1475 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
|
1476 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
|
1477 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
|
1478 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
|
1479 } |
64f03e860c91
patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
1480 |
64f03e860c91
patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
1481 /* |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1482 * 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
|
1483 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1484 void |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1485 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
|
1486 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1487 *to = *from; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1488 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
|
1489 ++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
|
1490 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1491 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1492 /* |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1493 * Free an object. |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1494 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1495 static void |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1496 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
|
1497 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1498 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
|
1499 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1500 // 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
|
1501 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
|
1502 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
|
1503 clear_tv(tv + i); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1504 |
31404
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1505 // 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
|
1506 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
|
1507 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1508 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
|
1509 class_unref(cl); |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1510 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1511 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1512 /* |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1513 * Unreference an object. |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1514 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1515 void |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1516 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
|
1517 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1518 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
|
1519 object_clear(obj); |
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 |
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 * 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
|
1524 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1525 void |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1526 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
|
1527 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1528 *to = *from; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1529 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
|
1530 ++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
|
1531 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1532 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1533 /* |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1534 * 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
|
1535 */ |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1536 void |
31404
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1537 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
|
1538 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1539 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
|
1540 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1541 // 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
|
1542 // 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
|
1543 // be freed. |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1544 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
|
1545 |
31653
ec76f9d2319e
patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31649
diff
changeset
|
1546 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
|
1547 |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
1548 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
|
1549 { |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
1550 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
|
1551 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
|
1552 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
|
1553 } |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
1554 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
|
1555 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
|
1556 |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
1557 itf2class_T *next; |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
1558 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
|
1559 { |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
1560 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
|
1561 vim_free(i2c); |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
1562 } |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31746
diff
changeset
|
1563 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1564 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
|
1565 { |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1566 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
|
1567 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
|
1568 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
|
1569 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
|
1570 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
|
1571 } |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1572 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
|
1573 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
|
1574 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1575 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
|
1576 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31455
diff
changeset
|
1577 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
|
1578 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
|
1579 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
|
1580 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1581 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
|
1582 |
31586
f36f920bad1a
patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents:
31582
diff
changeset
|
1583 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
|
1584 { |
f36f920bad1a
patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents:
31582
diff
changeset
|
1585 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
|
1586 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
|
1587 } |
f36f920bad1a
patch 9.0.1125: memory leak when using class functions
Bram Moolenaar <Bram@vim.org>
parents:
31582
diff
changeset
|
1588 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
|
1589 |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1590 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
|
1591 { |
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31408
diff
changeset
|
1592 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
|
1593 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
|
1594 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1595 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
|
1596 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1597 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
|
1598 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1599 vim_free(cl); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1600 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1601 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
1602 |
31404
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1603 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
|
1604 |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1605 /* |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1606 * 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
|
1607 * 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
|
1608 */ |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1609 void |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1610 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
|
1611 { |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1612 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
|
1613 { |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1614 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
|
1615 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
|
1616 } |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1617 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
|
1618 } |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1619 |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1620 /* |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1621 * 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
|
1622 * 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
|
1623 */ |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1624 void |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1625 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
|
1626 { |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1627 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
|
1628 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
|
1629 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
|
1630 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
|
1631 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
|
1632 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
|
1633 } |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1634 |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1635 /* |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1636 * 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
|
1637 */ |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1638 int |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1639 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
|
1640 { |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1641 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
|
1642 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
|
1643 |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1644 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
|
1645 { |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1646 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
|
1647 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
|
1648 { |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1649 // 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
|
1650 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
|
1651 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
|
1652 } |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1653 } |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1654 |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1655 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
|
1656 } |
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1657 |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 #endif // FEAT_EVAL |