Mercurial > vim
annotate src/vim9class.c @ 33130:3e4c08a8d637 v9.0.1847
patch 9.0.1847: [security] potential oob write in do_addsub()
Commit: https://github.com/vim/vim/commit/889f6af37164775192e33b233a90e86fd3df0f57
Author: Christian Brabandt <cb@256bit.org>
Date: Sat Sep 2 19:43:33 2023 +0200
patch 9.0.1847: [security] potential oob write in do_addsub()
Problem: potential oob write in do_addsub()
Solution: don't overflow buf2, check size in for loop()
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 02 Sep 2023 20:00:02 +0200 |
parents | bede81965821 |
children | 4ecf54d709b3 |
rev | line source |
---|---|
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
8 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
9 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
10 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
11 * vim9class.c: Vim9 script class support |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
12 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
13 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
14 #define USING_FLOAT_STUFF |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
15 #include "vim.h" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
16 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
17 #if defined(FEAT_EVAL) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
18 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
19 // When not generating protos this is included in proto.h |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
20 #ifdef PROTO |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
21 # include "vim9.h" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
22 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
23 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
24 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
25 * Parse a member declaration, both object and class member. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
26 * Returns OK or FAIL. When OK then "varname_end" is set to just after the |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
27 * variable name and "type_ret" is set to the declared or detected type. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
28 * "init_expr" is set to the initialisation expression (allocated), if there is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
29 * one. For an interface "init_expr" is NULL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
30 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
31 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
32 parse_member( |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
33 exarg_T *eap, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
34 char_u *line, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
35 char_u *varname, |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
36 int has_public, // TRUE if "public" seen before "varname" |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
37 char_u **varname_end, |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
38 garray_T *type_list, |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
39 type_T **type_ret, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
40 char_u **init_expr) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
41 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
42 *varname_end = to_name_end(varname, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
43 if (*varname == '_' && has_public) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
44 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
45 semsg(_(e_public_member_name_cannot_start_with_underscore_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
46 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
47 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
48 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
49 char_u *colon = skipwhite(*varname_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
50 char_u *type_arg = colon; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
51 type_T *type = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
52 if (*colon == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
53 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
54 if (VIM_ISWHITE(**varname_end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
55 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
56 semsg(_(e_no_white_space_allowed_before_colon_str), varname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
57 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
58 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
59 if (!VIM_ISWHITE(colon[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
60 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
61 semsg(_(e_white_space_required_after_str_str), ":", varname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
62 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
63 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
64 type_arg = skipwhite(colon + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
65 type = parse_type(&type_arg, type_list, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
66 if (type == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
67 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
68 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
69 |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
70 char_u *init_arg = skipwhite(type_arg); |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
71 if (type == NULL && *init_arg != '=') |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
72 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
73 emsg(_(e_type_or_initialization_required)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
74 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
75 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
76 |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
77 if (init_expr == NULL && *init_arg == '=') |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
78 { |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
79 emsg(_(e_cannot_initialize_member_in_interface)); |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
80 return FAIL; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
81 } |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
82 |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
83 if (*init_arg == '=') |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
84 { |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
85 evalarg_T evalarg; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
86 char_u *expr_start, *expr_end; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
87 |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
88 if (!VIM_ISWHITE(init_arg[-1]) || !VIM_ISWHITE(init_arg[1])) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
89 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
90 semsg(_(e_white_space_required_before_and_after_str_at_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
91 "=", type_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
92 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
93 } |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
94 init_arg = skipwhite(init_arg + 1); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
95 |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
96 fill_evalarg_from_eap(&evalarg, eap, FALSE); |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
97 (void)skip_expr_concatenate(&init_arg, &expr_start, &expr_end, &evalarg); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
98 |
33006
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32984
diff
changeset
|
99 // No type specified for the member. Set it to "any" and the correct |
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32984
diff
changeset
|
100 // type will be set when the object is instantiated. |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
101 if (type == NULL) |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
102 type = &t_any; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
103 |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
104 *init_expr = vim_strnsave(expr_start, expr_end - expr_start); |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
105 // Free the memory pointed by expr_start. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
106 clear_evalarg(&evalarg, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
107 } |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
108 else if (!valid_declaration_type(type)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
109 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
110 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
111 *type_ret = type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
112 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
113 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
114 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
115 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
116 * Add a member to an object or a class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
117 * Returns OK when successful, "init_expr" will be consumed then. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
118 * Returns FAIL otherwise, caller might need to free "init_expr". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
119 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
120 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
121 add_member( |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
122 garray_T *gap, |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
123 char_u *varname, |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
124 char_u *varname_end, |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
125 int has_public, |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
126 type_T *type, |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
127 char_u *init_expr) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
128 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
129 if (ga_grow(gap, 1) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
130 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
131 ocmember_T *m = ((ocmember_T *)gap->ga_data) + gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
132 m->ocm_name = vim_strnsave(varname, varname_end - varname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
133 m->ocm_access = has_public ? VIM_ACCESS_ALL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
134 : *varname == '_' ? VIM_ACCESS_PRIVATE : VIM_ACCESS_READ; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
135 m->ocm_type = type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
136 if (init_expr != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
137 m->ocm_init = init_expr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
138 ++gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
139 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
140 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
141 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
142 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
143 * Move the class or object members found while parsing a class into the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
144 * "gap" contains the found members. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
145 * "parent_members" points to the members in the parent class (if any) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
146 * "parent_count" is the number of members in the parent class |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
147 * "members" will be set to the newly allocated array of members and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
148 * "member_count" set to the number of members. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
149 * Returns OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
150 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
151 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
152 add_members_to_class( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
153 garray_T *gap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
154 ocmember_T *parent_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
155 int parent_count, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
156 ocmember_T **members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
157 int *member_count) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
158 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
159 *member_count = parent_count + gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
160 *members = *member_count == 0 ? NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
161 : ALLOC_MULT(ocmember_T, *member_count); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
162 if (*member_count > 0 && *members == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
163 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
164 for (int i = 0; i < parent_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
165 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
166 // parent members need to be copied |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
167 ocmember_T *m = *members + i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
168 *m = parent_members[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
169 m->ocm_name = vim_strsave(m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
170 if (m->ocm_init != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
171 m->ocm_init = vim_strsave(m->ocm_init); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
172 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
173 if (gap->ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
174 // new members are moved |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
175 mch_memmove(*members + parent_count, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
176 gap->ga_data, sizeof(ocmember_T) * gap->ga_len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
177 VIM_CLEAR(gap->ga_data); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
178 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
179 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
180 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
181 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
182 * Convert a member index "idx" of interface "itf" to the member index of class |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
183 * "cl" implementing that interface. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
184 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
185 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
186 object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
187 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
188 if (idx > (is_method ? itf->class_obj_method_count |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
189 : itf->class_obj_member_count)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
190 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
191 siemsg("index %d out of range for interface %s", idx, itf->class_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
192 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
193 } |
32772
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
194 |
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
195 // If "cl" is the interface or the class that is extended, then the method |
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
196 // index can be used directly and there is no need to search for the method |
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
197 // index in one of the child classes. |
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
198 if (cl == itf) |
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
199 return idx; |
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
200 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
201 itf2class_T *i2c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
202 for (i2c = itf->class_itf2class; i2c != NULL; i2c = i2c->i2c_next) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
203 if (i2c->i2c_class == cl && i2c->i2c_is_method == is_method) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
204 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
205 if (i2c == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
206 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
207 siemsg("class %s not found on interface %s", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
208 cl->class_name, itf->class_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
209 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
210 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
211 int *table = (int *)(i2c + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
212 return table[idx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
213 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
214 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
215 /* |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
216 * Check whether a class named "extends_name" is present. If the class is |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
217 * valid, then "extends_clp" is set with the class pointer. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
218 * Returns TRUE if the class name "extends_names" is a valid class. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
219 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
220 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
221 validate_extends_class(char_u *extends_name, class_T **extends_clp) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
222 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
223 typval_T tv; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
224 int success = FALSE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
225 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
226 tv.v_type = VAR_UNKNOWN; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
227 if (eval_variable_import(extends_name, &tv) == FAIL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
228 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
229 semsg(_(e_class_name_not_found_str), extends_name); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
230 return success; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
231 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
232 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
233 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
234 if (tv.v_type != VAR_CLASS |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
235 || tv.vval.v_class == NULL |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
236 || (tv.vval.v_class->class_flags & CLASS_INTERFACE) != 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
237 semsg(_(e_cannot_extend_str), extends_name); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
238 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
239 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
240 class_T *extends_cl = tv.vval.v_class; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
241 ++extends_cl->class_refcount; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
242 *extends_clp = extends_cl; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
243 success = TRUE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
244 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
245 clear_tv(&tv); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
246 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
247 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
248 return success; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
249 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
250 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
251 /* |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
252 * Check whether a class/object member variable in "classmembers_gap" / |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
253 * "objmembers_gap" is a duplicate of a member in any of the extended parent |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
254 * class lineage. Returns TRUE if there are no duplicates. |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
255 */ |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
256 static int |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
257 validate_extends_members( |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
258 garray_T *classmembers_gap, |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
259 garray_T *objmembers_gap, |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
260 class_T *extends_cl) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
261 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
262 for (int loop = 1; loop <= 2; ++loop) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
263 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
264 // loop == 1: check class members |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
265 // loop == 2: check object members |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
266 int member_count = loop == 1 ? classmembers_gap->ga_len |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
267 : objmembers_gap->ga_len; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
268 if (member_count == 0) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
269 continue; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
270 ocmember_T *members = (ocmember_T *)(loop == 1 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
271 ? classmembers_gap->ga_data |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
272 : objmembers_gap->ga_data); |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
273 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
274 // Validate each member variable |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
275 for (int c_i = 0; c_i < member_count; c_i++) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
276 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
277 class_T *p_cl = extends_cl; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
278 ocmember_T *c_m = members + c_i; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
279 char_u *pstr = (*c_m->ocm_name == '_') |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
280 ? c_m->ocm_name + 1 : c_m->ocm_name; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
281 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
282 // Check in all the parent classes in the lineage |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
283 while (p_cl != NULL) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
284 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
285 int p_member_count = loop == 1 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
286 ? p_cl->class_class_member_count |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
287 : p_cl->class_obj_member_count; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
288 if (p_member_count == 0) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
289 continue; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
290 ocmember_T *p_members = (loop == 1 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
291 ? p_cl->class_class_members |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
292 : p_cl->class_obj_members); |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
293 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
294 // Compare against all the members in the parent class |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
295 for (int p_i = 0; p_i < p_member_count; p_i++) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
296 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
297 ocmember_T *p_m = p_members + p_i; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
298 char_u *qstr = (*p_m->ocm_name == '_') |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
299 ? p_m->ocm_name + 1 : p_m->ocm_name; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
300 if (STRCMP(pstr, qstr) == 0) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
301 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
302 semsg(_(e_duplicate_member_str), c_m->ocm_name); |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
303 return FALSE; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
304 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
305 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
306 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
307 p_cl = p_cl->class_extends; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
308 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
309 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
310 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
311 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
312 return TRUE; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
313 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
314 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
315 /* |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
316 * Check the members of the interface class "ifcl" match the class members |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
317 * ("classmembers_gap") and object members ("objmembers_gap") of a class. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
318 * Returns TRUE if the class and object member names are valid. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
319 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
320 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
321 validate_interface_members( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
322 char_u *intf_class_name, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
323 class_T *ifcl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
324 garray_T *classmembers_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
325 garray_T *objmembers_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
326 { |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
327 for (int loop = 1; loop <= 2; ++loop) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
328 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
329 // loop == 1: check class members |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
330 // loop == 2: check object members |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
331 int if_count = loop == 1 ? ifcl->class_class_member_count |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
332 : ifcl->class_obj_member_count; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
333 if (if_count == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
334 continue; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
335 ocmember_T *if_ms = loop == 1 ? ifcl->class_class_members |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
336 : ifcl->class_obj_members; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
337 ocmember_T *cl_ms = (ocmember_T *)(loop == 1 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
338 ? classmembers_gap->ga_data |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
339 : objmembers_gap->ga_data); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
340 int cl_count = loop == 1 ? classmembers_gap->ga_len |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
341 : objmembers_gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
342 for (int if_i = 0; if_i < if_count; ++if_i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
343 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
344 int cl_i; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
345 for (cl_i = 0; cl_i < cl_count; ++cl_i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
346 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
347 ocmember_T *m = &cl_ms[cl_i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
348 where_T where = WHERE_INIT; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
349 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
350 if (STRCMP(if_ms[if_i].ocm_name, m->ocm_name) != 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
351 continue; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
352 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
353 // Ensure the type is matching. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
354 where.wt_func_name = (char *)m->ocm_name; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
355 where.wt_kind = WT_MEMBER; |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
356 if (check_type(if_ms[if_i].ocm_type, m->ocm_type, TRUE, |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
357 where) == FAIL) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
358 return FALSE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
359 |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
360 if (if_ms[if_i].ocm_access != m->ocm_access) |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
361 { |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
362 semsg(_(e_member_str_of_interface_str_has_different_access), |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
363 if_ms[if_i].ocm_name, intf_class_name); |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
364 return FALSE; |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
365 } |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
366 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
367 break; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
368 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
369 if (cl_i == cl_count) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
370 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
371 semsg(_(e_member_str_of_interface_str_not_implemented), |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
372 if_ms[if_i].ocm_name, intf_class_name); |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
373 return FALSE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
374 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
375 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
376 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
377 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
378 return TRUE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
379 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
380 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
381 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
382 * Check the functions/methods of the interface class "ifcl" match the class |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
383 * methods ("classfunctions_gap") and object functions ("objmemthods_gap") of a |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
384 * class. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
385 * Returns TRUE if the class and object member names are valid. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
386 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
387 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
388 validate_interface_methods( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
389 char_u *intf_class_name, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
390 class_T *ifcl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
391 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
392 garray_T *objmethods_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
393 { |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
394 for (int loop = 1; loop <= 2; ++loop) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
395 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
396 // loop == 1: check class functions |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
397 // loop == 2: check object methods |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
398 int if_count = loop == 1 ? ifcl->class_class_function_count |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
399 : ifcl->class_obj_method_count; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
400 if (if_count == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
401 continue; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
402 ufunc_T **if_fp = loop == 1 ? ifcl->class_class_functions |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
403 : ifcl->class_obj_methods; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
404 ufunc_T **cl_fp = (ufunc_T **)(loop == 1 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
405 ? classfunctions_gap->ga_data |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
406 : objmethods_gap->ga_data); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
407 int cl_count = loop == 1 ? classfunctions_gap->ga_len |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
408 : objmethods_gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
409 for (int if_i = 0; if_i < if_count; ++if_i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
410 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
411 char_u *if_name = if_fp[if_i]->uf_name; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
412 int cl_i; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
413 for (cl_i = 0; cl_i < cl_count; ++cl_i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
414 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
415 char_u *cl_name = cl_fp[cl_i]->uf_name; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
416 if (STRCMP(if_name, cl_name) == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
417 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
418 where_T where = WHERE_INIT; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
419 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
420 // Ensure the type is matching. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
421 where.wt_func_name = (char *)if_name; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
422 where.wt_kind = WT_METHOD; |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
423 if (check_type(if_fp[if_i]->uf_func_type, |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
424 cl_fp[cl_i]->uf_func_type, TRUE, where) == FAIL) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
425 return FALSE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
426 break; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
427 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
428 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
429 if (cl_i == cl_count) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
430 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
431 semsg(_(e_function_str_of_interface_str_not_implemented), |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
432 if_name, intf_class_name); |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
433 return FALSE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
434 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
435 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
436 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
437 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
438 return TRUE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
439 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
440 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
441 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
442 * Validate all the "implements" classes when creating a new class. The |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
443 * classes are returned in "intf_classes". The class functions, class members, |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
444 * object methods and object members in the new class are in |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
445 * "classfunctions_gap", "classmembers_gap", "objmethods_gap", and |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
446 * "objmembers_gap" respectively. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
447 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
448 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
449 validate_implements_classes( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
450 garray_T *impl_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
451 class_T **intf_classes, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
452 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
453 garray_T *classmembers_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
454 garray_T *objmethods_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
455 garray_T *objmembers_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
456 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
457 int success = TRUE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
458 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
459 for (int i = 0; i < impl_gap->ga_len && success; ++i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
460 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
461 char_u *impl = ((char_u **)impl_gap->ga_data)[i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
462 typval_T tv; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
463 tv.v_type = VAR_UNKNOWN; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
464 if (eval_variable_import(impl, &tv) == FAIL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
465 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
466 semsg(_(e_interface_name_not_found_str), impl); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
467 success = FALSE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
468 break; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
469 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
470 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
471 if (tv.v_type != VAR_CLASS |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
472 || tv.vval.v_class == NULL |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
473 || (tv.vval.v_class->class_flags & CLASS_INTERFACE) == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
474 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
475 semsg(_(e_not_valid_interface_str), impl); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
476 success = FALSE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
477 clear_tv(&tv); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
478 break; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
479 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
480 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
481 class_T *ifcl = tv.vval.v_class; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
482 intf_classes[i] = ifcl; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
483 ++ifcl->class_refcount; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
484 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
485 // check the members of the interface match the members of the class |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
486 success = validate_interface_members(impl, ifcl, classmembers_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
487 objmembers_gap); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
488 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
489 // check the functions/methods of the interface match the |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
490 // functions/methods of the class |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
491 if (success) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
492 success = validate_interface_methods(impl, ifcl, |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
493 classfunctions_gap, objmethods_gap); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
494 clear_tv(&tv); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
495 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
496 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
497 return success; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
498 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
499 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
500 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
501 * Check no function argument name is used as a class member. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
502 * (Object members are always accessed with "this." prefix, so no need |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
503 * to check them.) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
504 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
505 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
506 check_func_arg_names( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
507 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
508 garray_T *objmethods_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
509 garray_T *classmembers_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
510 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
511 // loop 1: class functions, loop 2: object methods |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
512 for (int loop = 1; loop <= 2; ++loop) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
513 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
514 garray_T *gap = loop == 1 ? classfunctions_gap : objmethods_gap; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
515 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
516 for (int fi = 0; fi < gap->ga_len; ++fi) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
517 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
518 ufunc_T *uf = ((ufunc_T **)gap->ga_data)[fi]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
519 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
520 for (int i = 0; i < uf->uf_args.ga_len; ++i) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
521 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
522 char_u *aname = ((char_u **)uf->uf_args.ga_data)[i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
523 garray_T *mgap = classmembers_gap; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
524 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
525 // Check all the class member names |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
526 for (int mi = 0; mi < mgap->ga_len; ++mi) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
527 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
528 char_u *mname = ((ocmember_T *)mgap->ga_data + mi) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
529 ->ocm_name; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
530 if (STRCMP(aname, mname) == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
531 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
532 if (uf->uf_script_ctx.sc_sid > 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
533 SOURCING_LNUM = uf->uf_script_ctx.sc_lnum; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
534 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
535 semsg(_(e_argument_already_declared_in_class_str), |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
536 aname); |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
537 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
538 return FALSE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
539 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
540 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
541 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
542 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
543 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
544 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
545 return TRUE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
546 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
547 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
548 /* |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
549 * Returns TRUE if the member "varname" is already defined. |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
550 */ |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
551 static int |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
552 is_duplicate_member(garray_T *mgap, char_u *varname, char_u *varname_end) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
553 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
554 char_u *pstr = (*varname == '_') ? varname + 1 : varname; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
555 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
556 for (int i = 0; i < mgap->ga_len; ++i) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
557 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
558 ocmember_T *m = ((ocmember_T *)mgap->ga_data) + i; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
559 char_u *qstr = *m->ocm_name == '_' ? m->ocm_name + 1 : m->ocm_name; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
560 if (STRNCMP(pstr, qstr, varname_end - pstr) == 0) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
561 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
562 char_u *name = vim_strnsave(varname, varname_end - varname); |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
563 semsg(_(e_duplicate_member_str), name); |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
564 vim_free(name); |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
565 return TRUE; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
566 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
567 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
568 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
569 return FALSE; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
570 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
571 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
572 /* |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
573 * Returns TRUE if the method "name" is already defined. |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
574 */ |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
575 static int |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
576 is_duplicate_method(garray_T *fgap, char_u *name) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
577 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
578 char_u *pstr = (*name == '_') ? name + 1 : name; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
579 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
580 for (int i = 0; i < fgap->ga_len; ++i) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
581 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
582 char_u *n = ((ufunc_T **)fgap->ga_data)[i]->uf_name; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
583 char_u *qstr = *n == '_' ? n + 1 : n; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
584 if (STRCMP(pstr, qstr) == 0) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
585 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
586 semsg(_(e_duplicate_function_str), name); |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
587 return TRUE; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
588 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
589 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
590 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
591 return FALSE; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
592 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
593 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
594 /* |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
595 * Returns TRUE if the constructor is valid. |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
596 */ |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
597 static int |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
598 is_valid_constructor(ufunc_T *uf, int is_abstract, int has_static) |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
599 { |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
600 // Constructors are not allowed in abstract classes. |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
601 if (is_abstract) |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
602 { |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
603 emsg(_(e_cannot_define_new_function_in_abstract_class)); |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
604 return FALSE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
605 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
606 // A constructor is always static, no need to define it so. |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
607 if (has_static) |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
608 { |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
609 emsg(_(e_cannot_define_new_function_as_static)); |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
610 return FALSE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
611 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
612 // A return type should not be specified for the new() |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
613 // constructor method. |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
614 if (uf->uf_ret_type->tt_type != VAR_VOID) |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
615 { |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
616 emsg(_(e_cannot_use_a_return_type_with_new)); |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
617 return FALSE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
618 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
619 return TRUE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
620 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
621 |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
622 /* |
32854
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
623 * Update the interface class lookup table for the member index on the |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
624 * interface to the member index in the class implementing the interface. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
625 * And a lookup table for the object method index on the interface |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
626 * to the object method index in the class implementing the interface. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
627 * This is also used for updating the lookup table for the extended class |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
628 * hierarchy. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
629 */ |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
630 static int |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
631 update_member_method_lookup_table( |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
632 class_T *ifcl, |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
633 class_T *cl, |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
634 garray_T *objmethods, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
635 int pobj_method_offset, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
636 int is_interface) |
32854
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
637 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
638 if (ifcl == NULL) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
639 return OK; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
640 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
641 // Table for members. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
642 itf2class_T *if2cl = alloc_clear(sizeof(itf2class_T) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
643 + ifcl->class_obj_member_count * sizeof(int)); |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
644 if (if2cl == NULL) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
645 return FAIL; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
646 if2cl->i2c_next = ifcl->class_itf2class; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
647 ifcl->class_itf2class = if2cl; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
648 if2cl->i2c_class = cl; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
649 if2cl->i2c_is_method = FALSE; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
650 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
651 for (int if_i = 0; if_i < ifcl->class_obj_member_count; ++if_i) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
652 for (int cl_i = 0; cl_i < cl->class_obj_member_count; ++cl_i) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
653 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
654 if (STRCMP(ifcl->class_obj_members[if_i].ocm_name, |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
655 cl->class_obj_members[cl_i].ocm_name) == 0) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
656 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
657 int *table = (int *)(if2cl + 1); |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
658 table[if_i] = cl_i; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
659 break; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
660 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
661 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
662 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
663 // Table for methods. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
664 if2cl = alloc_clear(sizeof(itf2class_T) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
665 + ifcl->class_obj_method_count * sizeof(int)); |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
666 if (if2cl == NULL) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
667 return FAIL; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
668 if2cl->i2c_next = ifcl->class_itf2class; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
669 ifcl->class_itf2class = if2cl; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
670 if2cl->i2c_class = cl; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
671 if2cl->i2c_is_method = TRUE; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
672 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
673 for (int if_i = 0; if_i < ifcl->class_obj_method_count; ++if_i) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
674 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
675 int done = FALSE; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
676 for (int cl_i = 0; cl_i < objmethods->ga_len; ++cl_i) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
677 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
678 if (STRCMP(ifcl->class_obj_methods[if_i]->uf_name, |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
679 ((ufunc_T **)objmethods->ga_data)[cl_i]->uf_name) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
680 == 0) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
681 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
682 int *table = (int *)(if2cl + 1); |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
683 table[if_i] = cl_i; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
684 done = TRUE; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
685 break; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
686 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
687 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
688 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
689 // extended class object method is not overridden by the child class. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
690 // Keep the method declared in one of the parent classes in the |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
691 // lineage. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
692 if (!done && !is_interface) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
693 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
694 // If "ifcl" is not the immediate parent of "cl", then search in |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
695 // the intermediate parent classes. |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
696 if (cl->class_extends != ifcl) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
697 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
698 class_T *parent = cl->class_extends; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
699 int method_offset = objmethods->ga_len; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
700 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
701 while (!done && parent != NULL && parent != ifcl) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
702 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
703 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
704 for (int cl_i = 0; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
705 cl_i < parent->class_obj_method_count_child; ++cl_i) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
706 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
707 if (STRCMP(ifcl->class_obj_methods[if_i]->uf_name, |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
708 parent->class_obj_methods[cl_i]->uf_name) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
709 == 0) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
710 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
711 int *table = (int *)(if2cl + 1); |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
712 table[if_i] = method_offset + cl_i; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
713 done = TRUE; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
714 break; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
715 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
716 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
717 method_offset += parent->class_obj_method_count_child; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
718 parent = parent->class_extends; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
719 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
720 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
721 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
722 if (!done) |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
723 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
724 int *table = (int *)(if2cl + 1); |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
725 table[if_i] = pobj_method_offset + if_i; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
726 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
727 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
728 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
729 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
730 return OK; |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
731 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
732 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
733 /* |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
734 * Update the member and object method lookup tables for a new class in the |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
735 * interface class. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
736 * For each interface add a lookup table for the member index on the interface |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
737 * to the member index in the new class. And a lookup table for the object |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
738 * method index on the interface to the object method index in the new class. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
739 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
740 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
741 add_lookup_tables(class_T *cl, class_T *extends_cl, garray_T *objmethods_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
742 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
743 for (int i = 0; i < cl->class_interface_count; ++i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
744 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
745 class_T *ifcl = cl->class_interfaces_cl[i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
746 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
747 if (update_member_method_lookup_table(ifcl, cl, objmethods_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
748 0, TRUE) == FAIL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
749 return FAIL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
750 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
751 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
752 // Update the lookup table for the extended class, if nay |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
753 if (extends_cl != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
754 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
755 class_T *pclass = extends_cl; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
756 int pobj_method_offset = objmethods_gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
757 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
758 // Update the entire lineage of extended classes. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
759 while (pclass != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
760 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
761 if (update_member_method_lookup_table(pclass, cl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
762 objmethods_gap, pobj_method_offset, FALSE) == FAIL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
763 return FAIL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
764 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
765 pobj_method_offset += pclass->class_obj_method_count_child; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
766 pclass = pclass->class_extends; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
767 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
768 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
769 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
770 return OK; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
771 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
772 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
773 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
774 * Add class members to a new class. Allocate a typval for each class member |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
775 * and initialize it. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
776 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
777 static void |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
778 add_class_members(class_T *cl, exarg_T *eap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
779 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
780 // Allocate a typval for each class member and initialize it. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
781 cl->class_members_tv = ALLOC_CLEAR_MULT(typval_T, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
782 cl->class_class_member_count); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
783 if (cl->class_members_tv == NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
784 return; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
785 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
786 for (int i = 0; i < cl->class_class_member_count; ++i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
787 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
788 ocmember_T *m = &cl->class_class_members[i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
789 typval_T *tv = &cl->class_members_tv[i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
790 if (m->ocm_init != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
791 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
792 typval_T *etv = eval_expr(m->ocm_init, eap); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
793 if (etv != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
794 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
795 *tv = *etv; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
796 vim_free(etv); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
797 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
798 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
799 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
800 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
801 // TODO: proper default value |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
802 tv->v_type = m->ocm_type->tt_type; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
803 tv->vval.v_string = NULL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
804 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
805 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
806 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
807 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
808 /* |
32903
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
809 * Add a default constructor method (new()) to the class "cl". |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
810 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
811 static void |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
812 add_default_constructor( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
813 class_T *cl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
814 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
815 garray_T *type_list_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
816 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
817 garray_T fga; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
818 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
819 ga_init2(&fga, 1, 1000); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
820 ga_concat(&fga, (char_u *)"new("); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
821 for (int i = 0; i < cl->class_obj_member_count; ++i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
822 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
823 if (i > 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
824 ga_concat(&fga, (char_u *)", "); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
825 ga_concat(&fga, (char_u *)"this."); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
826 ocmember_T *m = cl->class_obj_members + i; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
827 ga_concat(&fga, (char_u *)m->ocm_name); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
828 ga_concat(&fga, (char_u *)" = v:none"); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
829 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
830 ga_concat(&fga, (char_u *)")\nenddef\n"); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
831 ga_append(&fga, NUL); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
832 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
833 exarg_T fea; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
834 CLEAR_FIELD(fea); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
835 fea.cmdidx = CMD_def; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
836 fea.cmd = fea.arg = fga.ga_data; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
837 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
838 garray_T lines_to_free; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
839 ga_init2(&lines_to_free, sizeof(char_u *), 50); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
840 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
841 ufunc_T *nf = define_function(&fea, NULL, &lines_to_free, CF_CLASS); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
842 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
843 ga_clear_strings(&lines_to_free); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
844 vim_free(fga.ga_data); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
845 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
846 if (nf != NULL && ga_grow(classfunctions_gap, 1) == OK) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
847 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
848 ((ufunc_T **)classfunctions_gap->ga_data)[classfunctions_gap->ga_len] |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
849 = nf; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
850 ++classfunctions_gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
851 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
852 nf->uf_flags |= FC_NEW; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
853 nf->uf_ret_type = get_type_ptr(type_list_gap); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
854 if (nf->uf_ret_type != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
855 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
856 nf->uf_ret_type->tt_type = VAR_OBJECT; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
857 nf->uf_ret_type->tt_class = cl; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
858 nf->uf_ret_type->tt_argcount = 0; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
859 nf->uf_ret_type->tt_args = NULL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
860 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
861 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
862 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
863 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
864 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
865 * Add the class functions and object methods to the new class "cl". |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
866 * When extending a class, add the functions and methods from the parent class |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
867 * also. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
868 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
869 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
870 add_classfuncs_objmethods( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
871 class_T *cl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
872 class_T *extends_cl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
873 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
874 garray_T *objmethods_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
875 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
876 // loop 1: class functions, loop 2: object methods |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
877 for (int loop = 1; loop <= 2; ++loop) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
878 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
879 garray_T *gap = loop == 1 ? classfunctions_gap : objmethods_gap; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
880 int *fcount = loop == 1 ? &cl->class_class_function_count |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
881 : &cl->class_obj_method_count; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
882 ufunc_T ***fup = loop == 1 ? &cl->class_class_functions |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
883 : &cl->class_obj_methods; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
884 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
885 int parent_count = 0; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
886 if (extends_cl != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
887 // Include functions from the parent. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
888 parent_count = loop == 1 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
889 ? extends_cl->class_class_function_count |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
890 : extends_cl->class_obj_method_count; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
891 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
892 *fcount = parent_count + gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
893 if (*fcount == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
894 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
895 *fup = NULL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
896 continue; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
897 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
898 *fup = ALLOC_MULT(ufunc_T *, *fcount); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
899 if (*fup == NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
900 return FAIL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
901 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
902 if (gap->ga_len != 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
903 mch_memmove(*fup, gap->ga_data, sizeof(ufunc_T *) * gap->ga_len); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
904 vim_free(gap->ga_data); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
905 if (loop == 1) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
906 cl->class_class_function_count_child = gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
907 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
908 cl->class_obj_method_count_child = gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
909 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
910 int skipped = 0; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
911 for (int i = 0; i < parent_count; ++i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
912 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
913 // Copy functions from the parent. Can't use the same |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
914 // function, because "uf_class" is different and compilation |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
915 // will have a different result. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
916 // Put them after the functions in the current class, object |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
917 // methods may be overruled, then "super.Method()" is used to |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
918 // find a method from the parent. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
919 // Skip "new" functions. TODO: not all of them. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
920 if (loop == 1 && STRNCMP( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
921 extends_cl->class_class_functions[i]->uf_name, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
922 "new", 3) == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
923 ++skipped; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
924 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
925 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
926 ufunc_T *pf = (loop == 1 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
927 ? extends_cl->class_class_functions |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
928 : extends_cl->class_obj_methods)[i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
929 (*fup)[gap->ga_len + i - skipped] = copy_function(pf); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
930 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
931 // If the child class overrides a function from the parent |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
932 // the signature must be equal. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
933 char_u *pname = pf->uf_name; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
934 for (int ci = 0; ci < gap->ga_len; ++ci) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
935 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
936 ufunc_T *cf = (*fup)[ci]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
937 char_u *cname = cf->uf_name; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
938 if (STRCMP(pname, cname) == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
939 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
940 where_T where = WHERE_INIT; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
941 where.wt_func_name = (char *)pname; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
942 where.wt_kind = WT_METHOD; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
943 (void)check_type(pf->uf_func_type, cf->uf_func_type, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
944 TRUE, where); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
945 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
946 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
947 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
948 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
949 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
950 *fcount -= skipped; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
951 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
952 // Set the class pointer on all the functions and object methods. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
953 for (int i = 0; i < *fcount; ++i) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
954 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
955 ufunc_T *fp = (*fup)[i]; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
956 fp->uf_class = cl; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
957 if (loop == 2) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
958 fp->uf_flags |= FC_OBJECT; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
959 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
960 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
961 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
962 return OK; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
963 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
964 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
965 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
966 * Handle ":class" and ":abstract class" up to ":endclass". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
967 * Handle ":interface" up to ":endinterface". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
968 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
969 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
970 ex_class(exarg_T *eap) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
971 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
972 int is_class = eap->cmdidx == CMD_class; // FALSE for :interface |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
973 long start_lnum = SOURCING_LNUM; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
974 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
975 char_u *arg = eap->arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
976 int is_abstract = eap->cmdidx == CMD_abstract; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
977 if (is_abstract) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
978 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
979 if (STRNCMP(arg, "class", 5) != 0 || !VIM_ISWHITE(arg[5])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
980 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
981 semsg(_(e_invalid_argument_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
982 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
983 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
984 arg = skipwhite(arg + 5); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
985 is_class = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
986 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
987 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
988 if (!current_script_is_vim9() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
989 || (cmdmod.cmod_flags & CMOD_LEGACY) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
990 || !getline_equal(eap->getline, eap->cookie, getsourceline)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
991 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
992 if (is_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
993 emsg(_(e_class_can_only_be_defined_in_vim9_script)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
994 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
995 emsg(_(e_interface_can_only_be_defined_in_vim9_script)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
996 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
997 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
998 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
999 if (!ASCII_ISUPPER(*arg)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1000 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1001 if (is_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1002 semsg(_(e_class_name_must_start_with_uppercase_letter_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1003 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1004 semsg(_(e_interface_name_must_start_with_uppercase_letter_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1005 arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1006 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1007 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1008 char_u *name_end = find_name_end(arg, NULL, NULL, FNE_CHECK_START); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1009 if (!IS_WHITE_OR_NUL(*name_end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1010 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1011 semsg(_(e_white_space_required_after_name_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1012 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1013 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1014 char_u *name_start = arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1015 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1016 // "export class" gets used when creating the class, don't use "is_export" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1017 // for the items inside the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1018 int class_export = is_export; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1019 is_export = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1020 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1021 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1022 // generics: <Tkey, Tentry> |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1023 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1024 // Name for "extends BaseClass" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1025 char_u *extends = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1026 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1027 // Names for "implements SomeInterface" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1028 garray_T ga_impl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1029 ga_init2(&ga_impl, sizeof(char_u *), 5); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1030 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1031 arg = skipwhite(name_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1032 while (*arg != NUL && *arg != '#' && *arg != '\n') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1033 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1034 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1035 // specifies SomeInterface |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1036 if (STRNCMP(arg, "extends", 7) == 0 && IS_WHITE_OR_NUL(arg[7])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1037 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1038 if (extends != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1039 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1040 emsg(_(e_duplicate_extends)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1041 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1042 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1043 arg = skipwhite(arg + 7); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1044 char_u *end = find_name_end(arg, NULL, NULL, FNE_CHECK_START); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1045 if (!IS_WHITE_OR_NUL(*end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1046 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1047 semsg(_(e_white_space_required_after_name_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1048 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1049 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1050 extends = vim_strnsave(arg, end - arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1051 if (extends == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1052 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1053 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1054 arg = skipwhite(end + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1055 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1056 else if (STRNCMP(arg, "implements", 10) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1057 && IS_WHITE_OR_NUL(arg[10])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1058 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1059 if (ga_impl.ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1060 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1061 emsg(_(e_duplicate_implements)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1062 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1063 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1064 arg = skipwhite(arg + 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1065 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1066 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1067 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1068 char_u *impl_end = find_name_end(arg, NULL, NULL, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1069 FNE_CHECK_START); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1070 if (!IS_WHITE_OR_NUL(*impl_end) && *impl_end != ',') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1071 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1072 semsg(_(e_white_space_required_after_name_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1073 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1074 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1075 char_u *iname = vim_strnsave(arg, impl_end - arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1076 if (iname == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1077 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1078 for (int i = 0; i < ga_impl.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1079 if (STRCMP(((char_u **)ga_impl.ga_data)[i], iname) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1080 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1081 semsg(_(e_duplicate_interface_after_implements_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1082 iname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1083 vim_free(iname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1084 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1085 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1086 if (ga_add_string(&ga_impl, iname) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1087 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1088 vim_free(iname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1089 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1090 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1091 if (*impl_end != ',') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1092 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1093 arg = skipwhite(impl_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1094 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1095 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1096 arg = skipwhite(impl_end + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1097 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1098 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1099 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1100 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1101 semsg(_(e_trailing_characters_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1102 early_ret: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1103 vim_free(extends); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1104 ga_clear_strings(&ga_impl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1105 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1106 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1107 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1108 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1109 garray_T type_list; // list of pointers to allocated types |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1110 ga_init2(&type_list, sizeof(type_T *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1111 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1112 // Growarray with class members declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1113 garray_T classmembers; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1114 ga_init2(&classmembers, sizeof(ocmember_T), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1115 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1116 // Growarray with functions declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1117 garray_T classfunctions; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1118 ga_init2(&classfunctions, sizeof(ufunc_T *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1119 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1120 // Growarray with object members declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1121 garray_T objmembers; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1122 ga_init2(&objmembers, sizeof(ocmember_T), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1123 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1124 // Growarray with object methods declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1125 garray_T objmethods; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1126 ga_init2(&objmethods, sizeof(ufunc_T *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1127 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1128 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1129 * Go over the body of the class/interface until "endclass" or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1130 * "endinterface" is found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1131 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1132 char_u *theline = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1133 int success = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1134 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1135 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1136 vim_free(theline); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1137 theline = eap->getline(':', eap->cookie, 0, GETLINE_CONCAT_ALL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1138 if (theline == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1139 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1140 char_u *line = skipwhite(theline); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1141 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1142 // Skip empty and comment lines. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1143 if (*line == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1144 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1145 if (*line == '#') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1146 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1147 if (vim9_bad_comment(line)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1148 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1149 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1150 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1151 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1152 char_u *p = line; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1153 char *end_name = is_class ? "endclass" : "endinterface"; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1154 if (checkforcmd(&p, end_name, is_class ? 4 : 5)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1155 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1156 if (STRNCMP(line, end_name, is_class ? 8 : 12) != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1157 semsg(_(e_command_cannot_be_shortened_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1158 else if (*p == '|' || !ends_excmd2(line, p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1159 semsg(_(e_trailing_characters_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1160 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1161 success = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1162 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1163 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1164 char *wrong_name = is_class ? "endinterface" : "endclass"; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1165 if (checkforcmd(&p, wrong_name, is_class ? 5 : 4)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1166 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1167 semsg(_(e_invalid_command_str_expected_str), line, end_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1168 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1169 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1170 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1171 int has_public = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1172 if (checkforcmd(&p, "public", 3)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1173 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1174 if (STRNCMP(line, "public", 6) != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1175 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1176 semsg(_(e_command_cannot_be_shortened_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1177 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1178 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1179 has_public = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1180 p = skipwhite(line + 6); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1181 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1182 if (STRNCMP(p, "this", 4) != 0 && STRNCMP(p, "static", 6) != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1183 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1184 emsg(_(e_public_must_be_followed_by_this_or_static)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1185 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1186 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1187 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1188 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1189 int has_static = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1190 char_u *ps = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1191 if (checkforcmd(&p, "static", 4)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1192 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1193 if (STRNCMP(ps, "static", 6) != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1194 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1195 semsg(_(e_command_cannot_be_shortened_str), ps); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1196 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1197 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1198 has_static = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1199 p = skipwhite(ps + 6); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1200 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1201 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1202 // object members (public, read access, private): |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1203 // "this._varname" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1204 // "this.varname" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1205 // "public this.varname" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1206 if (STRNCMP(p, "this", 4) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1207 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1208 if (p[4] != '.' || !eval_isnamec1(p[5])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1209 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1210 semsg(_(e_invalid_object_member_declaration_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1211 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1212 } |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1213 if (has_static) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1214 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1215 emsg(_(e_static_cannot_be_followed_by_this)); |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1216 break; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1217 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1218 char_u *varname = p + 5; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1219 char_u *varname_end = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1220 type_T *type = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1221 char_u *init_expr = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1222 if (parse_member(eap, line, varname, has_public, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1223 &varname_end, &type_list, &type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1224 is_class ? &init_expr: NULL) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1225 break; |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1226 if (is_duplicate_member(&objmembers, varname, varname_end)) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1227 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1228 vim_free(init_expr); |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1229 break; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1230 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1231 if (add_member(&objmembers, varname, varname_end, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1232 has_public, type, init_expr) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1233 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1234 vim_free(init_expr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1235 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1236 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1237 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1238 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1239 // constructors: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1240 // def new() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1241 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1242 // def newOther() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1243 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1244 // object methods and class functions: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1245 // def SomeMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1246 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1247 // static def ClassFunction() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1248 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1249 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1250 // def <Tval> someMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1251 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1252 else if (checkforcmd(&p, "def", 3)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1253 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1254 exarg_T ea; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1255 garray_T lines_to_free; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1256 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1257 // TODO: error for "public static def Func()"? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1258 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1259 CLEAR_FIELD(ea); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1260 ea.cmd = line; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1261 ea.arg = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1262 ea.cmdidx = CMD_def; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1263 ea.getline = eap->getline; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1264 ea.cookie = eap->cookie; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1265 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1266 ga_init2(&lines_to_free, sizeof(char_u *), 50); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1267 ufunc_T *uf = define_function(&ea, NULL, &lines_to_free, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1268 is_class ? CF_CLASS : CF_INTERFACE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1269 ga_clear_strings(&lines_to_free); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1270 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1271 if (uf != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1272 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1273 char_u *name = uf->uf_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1274 int is_new = STRNCMP(name, "new", 3) == 0; |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
1275 |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
1276 if (is_new && !is_valid_constructor(uf, is_abstract, has_static)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1277 { |
32854
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1278 func_clear_free(uf, FALSE); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1279 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1280 } |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
1281 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1282 garray_T *fgap = has_static || is_new |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1283 ? &classfunctions : &objmethods; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1284 // Check the name isn't used already. |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1285 if (is_duplicate_method(fgap, name)) |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1286 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1287 success = FALSE; |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1288 func_clear_free(uf, FALSE); |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1289 break; |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1290 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1291 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1292 if (ga_grow(fgap, 1) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1293 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1294 if (is_new) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1295 uf->uf_flags |= FC_NEW; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1296 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1297 ((ufunc_T **)fgap->ga_data)[fgap->ga_len] = uf; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1298 ++fgap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1299 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1300 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1301 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1302 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1303 // class members |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1304 else if (has_static) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1305 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1306 // class members (public, read access, private): |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1307 // "static _varname" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1308 // "static varname" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1309 // "public static varname" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1310 char_u *varname = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1311 char_u *varname_end = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1312 type_T *type = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1313 char_u *init_expr = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1314 if (parse_member(eap, line, varname, has_public, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1315 &varname_end, &type_list, &type, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1316 is_class ? &init_expr : NULL) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1317 break; |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1318 if (is_duplicate_member(&classmembers, varname, varname_end)) |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1319 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1320 vim_free(init_expr); |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1321 break; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
1322 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1323 if (add_member(&classmembers, varname, varname_end, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1324 has_public, type, init_expr) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1325 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1326 vim_free(init_expr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1327 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1328 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1329 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1330 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1331 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1332 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1333 if (is_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1334 semsg(_(e_not_valid_command_in_class_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1335 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1336 semsg(_(e_not_valid_command_in_interface_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1337 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1338 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1339 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1340 vim_free(theline); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1341 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1342 class_T *extends_cl = NULL; // class from "extends" argument |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1343 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1344 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1345 * Check a few things before defining the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1346 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1347 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1348 // Check the "extends" class is valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1349 if (success && extends != NULL) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1350 success = validate_extends_class(extends, &extends_cl); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1351 VIM_CLEAR(extends); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1352 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1353 // Check the new class members and object members doesn't duplicate the |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1354 // members in the extended class lineage. |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1355 if (success && extends_cl != NULL) |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1356 success = validate_extends_members(&classmembers, &objmembers, |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1357 extends_cl); |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1358 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1359 class_T **intf_classes = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1360 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1361 // Check all "implements" entries are valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1362 if (success && ga_impl.ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1363 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1364 intf_classes = ALLOC_CLEAR_MULT(class_T *, ga_impl.ga_len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1365 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1366 success = validate_implements_classes(&ga_impl, intf_classes, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1367 &classfunctions, &classmembers, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1368 &objmethods, &objmembers); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1369 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1370 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1371 // Check no function argument name is used as a class member. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1372 if (success) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1373 success = check_func_arg_names(&classfunctions, &objmethods, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1374 &classmembers); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1375 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1376 class_T *cl = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1377 if (success) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1378 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1379 // "endclass" encountered without failures: Create the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1380 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1381 cl = ALLOC_CLEAR_ONE(class_T); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1382 if (cl == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1383 goto cleanup; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1384 if (!is_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1385 cl->class_flags = CLASS_INTERFACE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1386 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1387 cl->class_refcount = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1388 cl->class_name = vim_strnsave(name_start, name_end - name_start); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1389 if (cl->class_name == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1390 goto cleanup; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1391 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1392 if (extends_cl != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1393 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1394 cl->class_extends = extends_cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1395 extends_cl->class_flags |= CLASS_EXTENDED; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1396 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1397 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1398 // Add class and object members to "cl". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1399 if (add_members_to_class(&classmembers, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1400 extends_cl == NULL ? NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1401 : extends_cl->class_class_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1402 extends_cl == NULL ? 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1403 : extends_cl->class_class_member_count, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1404 &cl->class_class_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1405 &cl->class_class_member_count) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1406 || add_members_to_class(&objmembers, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1407 extends_cl == NULL ? NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1408 : extends_cl->class_obj_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1409 extends_cl == NULL ? 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1410 : extends_cl->class_obj_member_count, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1411 &cl->class_obj_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1412 &cl->class_obj_member_count) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1413 goto cleanup; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1414 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1415 if (ga_impl.ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1416 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1417 // Move the "implements" names into the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1418 cl->class_interface_count = ga_impl.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1419 cl->class_interfaces = ALLOC_MULT(char_u *, ga_impl.ga_len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1420 if (cl->class_interfaces == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1421 goto cleanup; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1422 for (int i = 0; i < ga_impl.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1423 cl->class_interfaces[i] = ((char_u **)ga_impl.ga_data)[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1424 VIM_CLEAR(ga_impl.ga_data); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1425 ga_impl.ga_len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1426 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1427 cl->class_interfaces_cl = intf_classes; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1428 intf_classes = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1429 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1430 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1431 if (cl->class_interface_count > 0 || extends_cl != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1432 { |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1433 // Add a method and member lookup table to each of the interface |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1434 // classes. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1435 if (add_lookup_tables(cl, extends_cl, &objmethods) == FAIL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1436 goto cleanup; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1437 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1438 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1439 // Allocate a typval for each class member and initialize it. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1440 if (is_class && cl->class_class_member_count > 0) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1441 add_class_members(cl, eap); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1442 |
32903
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1443 int have_new = FALSE; |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1444 ufunc_T *class_func = NULL; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1445 for (int i = 0; i < classfunctions.ga_len; ++i) |
32903
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1446 { |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1447 class_func = ((ufunc_T **)classfunctions.ga_data)[i]; |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1448 if (STRCMP(class_func->uf_name, "new") == 0) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1449 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1450 have_new = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1451 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1452 } |
32903
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1453 } |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1454 |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1455 if (have_new) |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1456 // The return type of new() is an object of class "cl" |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1457 class_func->uf_ret_type->tt_class = cl; |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1458 else if (is_class && !is_abstract && !have_new) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1459 // No new() method was defined, add the default constructor. |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1460 add_default_constructor(cl, &classfunctions, &type_list); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1461 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1462 // Move all the functions into the created class. |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1463 if (add_classfuncs_objmethods(cl, extends_cl, &classfunctions, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1464 &objmethods) == FAIL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1465 goto cleanup; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1466 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1467 cl->class_type.tt_type = VAR_CLASS; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1468 cl->class_type.tt_class = cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1469 cl->class_object_type.tt_type = VAR_OBJECT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1470 cl->class_object_type.tt_class = cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1471 cl->class_type_list = type_list; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1472 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1473 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1474 // - Fill hashtab with object members and methods ? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1475 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1476 // Add the class to the script-local variables. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1477 // TODO: handle other context, e.g. in a function |
33119
bede81965821
patch 9.0.1842: Need more accurate profiling
Christian Brabandt <cb@256bit.org>
parents:
33109
diff
changeset
|
1478 // TODO: does uf_hash need to be cleared? |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1479 typval_T tv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1480 tv.v_type = VAR_CLASS; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1481 tv.vval.v_class = cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1482 is_export = class_export; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1483 SOURCING_LNUM = start_lnum; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1484 set_var_const(cl->class_name, current_sctx.sc_sid, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1485 NULL, &tv, FALSE, 0, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1486 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1487 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1488 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1489 cleanup: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1490 if (cl != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1491 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1492 vim_free(cl->class_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1493 vim_free(cl->class_class_functions); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1494 if (cl->class_interfaces != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1495 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1496 for (int i = 0; i < cl->class_interface_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1497 vim_free(cl->class_interfaces[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1498 vim_free(cl->class_interfaces); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1499 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1500 if (cl->class_interfaces_cl != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1501 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1502 for (int i = 0; i < cl->class_interface_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1503 class_unref(cl->class_interfaces_cl[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1504 vim_free(cl->class_interfaces_cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1505 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1506 vim_free(cl->class_obj_members); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1507 vim_free(cl->class_obj_methods); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1508 vim_free(cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1509 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1510 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1511 vim_free(extends); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1512 class_unref(extends_cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1513 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1514 if (intf_classes != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1515 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1516 for (int i = 0; i < ga_impl.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1517 class_unref(intf_classes[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1518 vim_free(intf_classes); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1519 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1520 ga_clear_strings(&ga_impl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1521 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1522 for (int round = 1; round <= 2; ++round) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1523 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1524 garray_T *gap = round == 1 ? &classmembers : &objmembers; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1525 if (gap->ga_len == 0 || gap->ga_data == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1526 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1527 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1528 for (int i = 0; i < gap->ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1529 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1530 ocmember_T *m = ((ocmember_T *)gap->ga_data) + i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1531 vim_free(m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1532 vim_free(m->ocm_init); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1533 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1534 ga_clear(gap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1535 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1536 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1537 for (int i = 0; i < objmethods.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1538 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1539 ufunc_T *uf = ((ufunc_T **)objmethods.ga_data)[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1540 func_clear_free(uf, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1541 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1542 ga_clear(&objmethods); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1543 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1544 for (int i = 0; i < classfunctions.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1545 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1546 ufunc_T *uf = ((ufunc_T **)classfunctions.ga_data)[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1547 func_clear_free(uf, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1548 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1549 ga_clear(&classfunctions); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1550 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1551 clear_type_list(&type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1552 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1553 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1554 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1555 * Find member "name" in class "cl", set "member_idx" to the member index and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1556 * return its type. |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1557 * When "is_object" is TRUE, then look for object members. Otherwise look for |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1558 * class members. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1559 * When not found "member_idx" is set to -1 and t_any is returned. |
33106
d994ba4bd9ca
patch 9.0.1837: Vim9: class_member_type() can be optimized
Christian Brabandt <cb@256bit.org>
parents:
33088
diff
changeset
|
1560 * Set *p_m ocmmember_T if not NULL |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1561 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1562 type_T * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1563 class_member_type( |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
1564 class_T *cl, |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1565 int is_object, |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
1566 char_u *name, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
1567 char_u *name_end, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
1568 int *member_idx, |
33106
d994ba4bd9ca
patch 9.0.1837: Vim9: class_member_type() can be optimized
Christian Brabandt <cb@256bit.org>
parents:
33088
diff
changeset
|
1569 ocmember_T **p_m) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1570 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1571 *member_idx = -1; // not found (yet) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1572 size_t len = name_end - name; |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1573 int member_count = is_object ? cl->class_obj_member_count |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1574 : cl->class_class_member_count; |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1575 ocmember_T *members = is_object ? cl->class_obj_members |
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1576 : cl->class_class_members; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1577 |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1578 for (int i = 0; i < member_count; ++i) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1579 { |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
1580 ocmember_T *m = members + i; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1581 if (STRNCMP(m->ocm_name, name, len) == 0 && m->ocm_name[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1582 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1583 *member_idx = i; |
33106
d994ba4bd9ca
patch 9.0.1837: Vim9: class_member_type() can be optimized
Christian Brabandt <cb@256bit.org>
parents:
33088
diff
changeset
|
1584 if (p_m != NULL) |
d994ba4bd9ca
patch 9.0.1837: Vim9: class_member_type() can be optimized
Christian Brabandt <cb@256bit.org>
parents:
33088
diff
changeset
|
1585 *p_m = m; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1586 return m->ocm_type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1587 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1588 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1589 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1590 semsg(_(e_unknown_variable_str), name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1591 return &t_any; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1592 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1593 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1594 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1595 * Handle ":enum" up to ":endenum". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1596 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1597 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1598 ex_enum(exarg_T *eap UNUSED) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1599 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1600 // TODO |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1601 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1602 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1603 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1604 * Handle ":type". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1605 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1606 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1607 ex_type(exarg_T *eap UNUSED) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1608 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1609 // TODO |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1610 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1611 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1612 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1613 * Evaluate what comes after a class: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1614 * - class member: SomeClass.varname |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1615 * - class function: SomeClass.SomeMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1616 * - class constructor: SomeClass.new() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1617 * - object member: someObject.varname |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1618 * - object method: someObject.SomeMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1619 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1620 * "*arg" points to the '.'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1621 * "*arg" is advanced to after the member name or method call. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1622 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1623 * Returns FAIL or OK. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1624 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1625 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1626 class_object_index( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1627 char_u **arg, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1628 typval_T *rettv, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1629 evalarg_T *evalarg, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1630 int verbose UNUSED) // give error messages |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1631 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1632 if (VIM_ISWHITE((*arg)[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1633 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1634 semsg(_(e_no_white_space_allowed_after_str_str), ".", *arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1635 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1636 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1637 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1638 ++*arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1639 char_u *name = *arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1640 char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1641 if (name_end == name) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1642 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1643 size_t len = name_end - name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1644 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1645 class_T *cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1646 if (rettv->v_type == VAR_CLASS) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1647 cl = rettv->vval.v_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1648 else // VAR_OBJECT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1649 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1650 if (rettv->vval.v_object == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1651 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1652 emsg(_(e_using_null_object)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1653 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1654 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1655 cl = rettv->vval.v_object->obj_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1656 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1657 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1658 if (cl == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1659 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1660 emsg(_(e_incomplete_type)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1661 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1662 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1663 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1664 if (*name_end == '(') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1665 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1666 int on_class = rettv->v_type == VAR_CLASS; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1667 int count = on_class ? cl->class_class_function_count |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1668 : cl->class_obj_method_count; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1669 for (int i = 0; i < count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1670 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1671 ufunc_T *fp = on_class ? cl->class_class_functions[i] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1672 : cl->class_obj_methods[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1673 // Use a separate pointer to avoid that ASAN complains about |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1674 // uf_name[] only being 4 characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1675 char_u *ufname = (char_u *)fp->uf_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1676 if (STRNCMP(name, ufname, len) == 0 && ufname[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1677 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1678 typval_T argvars[MAX_FUNC_ARGS + 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1679 int argcount = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1680 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
1681 if (*ufname == '_') |
33025
1d18c7fe609f
patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1682 { |
1d18c7fe609f
patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1683 // Cannot access a private method outside of a class |
1d18c7fe609f
patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1684 semsg(_(e_cannot_access_private_method_str), name); |
1d18c7fe609f
patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1685 return FAIL; |
1d18c7fe609f
patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1686 } |
1d18c7fe609f
patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1687 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1688 char_u *argp = name_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1689 int ret = get_func_arguments(&argp, evalarg, 0, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1690 argvars, &argcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1691 if (ret == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1692 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1693 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1694 funcexe_T funcexe; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1695 CLEAR_FIELD(funcexe); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1696 funcexe.fe_evaluate = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1697 if (rettv->v_type == VAR_OBJECT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1698 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1699 funcexe.fe_object = rettv->vval.v_object; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1700 ++funcexe.fe_object->obj_refcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1701 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1702 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1703 // Clear the class or object after calling the function, in |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1704 // case the refcount is one. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1705 typval_T tv_tofree = *rettv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1706 rettv->v_type = VAR_UNKNOWN; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1707 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1708 // Call the user function. Result goes into rettv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1709 int error = call_user_func_check(fp, argcount, argvars, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1710 rettv, &funcexe, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1711 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1712 // Clear the previous rettv and the arguments. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1713 clear_tv(&tv_tofree); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1714 for (int idx = 0; idx < argcount; ++idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1715 clear_tv(&argvars[idx]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1716 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1717 if (error != FCERR_NONE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1718 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1719 user_func_error(error, printable_func_name(fp), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1720 funcexe.fe_found_var); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1721 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1722 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1723 *arg = argp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1724 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1725 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1726 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1727 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1728 semsg(_(e_method_not_found_on_class_str_str), cl->class_name, name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1729 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1730 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1731 else if (rettv->v_type == VAR_OBJECT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1732 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1733 for (int i = 0; i < cl->class_obj_member_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1734 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1735 ocmember_T *m = &cl->class_obj_members[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1736 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1737 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1738 if (*name == '_') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1739 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1740 semsg(_(e_cannot_access_private_member_str), m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1741 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1742 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1743 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1744 // The object only contains a pointer to the class, the member |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1745 // values array follows right after that. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1746 object_T *obj = rettv->vval.v_object; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1747 typval_T *tv = (typval_T *)(obj + 1) + i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1748 copy_tv(tv, rettv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1749 object_unref(obj); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1750 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1751 *arg = name_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1752 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1753 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1754 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1755 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1756 semsg(_(e_member_not_found_on_object_str_str), cl->class_name, name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1757 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1758 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1759 else if (rettv->v_type == VAR_CLASS) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1760 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1761 // class member |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1762 for (int i = 0; i < cl->class_class_member_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1763 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1764 ocmember_T *m = &cl->class_class_members[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1765 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1766 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1767 if (*name == '_') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1768 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1769 semsg(_(e_cannot_access_private_member_str), m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1770 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1771 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1772 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1773 typval_T *tv = &cl->class_members_tv[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1774 copy_tv(tv, rettv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1775 class_unref(cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1776 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1777 *arg = name_end; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1778 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1779 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1780 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1781 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1782 semsg(_(e_member_not_found_on_class_str_str), cl->class_name, name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1783 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1784 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1785 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1786 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1787 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1788 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1789 * If "arg" points to a class or object method, return it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1790 * Otherwise return NULL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1791 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1792 ufunc_T * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1793 find_class_func(char_u **arg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1794 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1795 char_u *name = *arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1796 char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1797 if (name_end == name || *name_end != '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1798 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1799 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1800 size_t len = name_end - name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1801 typval_T tv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1802 tv.v_type = VAR_UNKNOWN; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1803 if (eval_variable(name, (int)len, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1804 0, &tv, NULL, EVAL_VAR_NOAUTOLOAD) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1805 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1806 if (tv.v_type != VAR_CLASS && tv.v_type != VAR_OBJECT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1807 goto fail_after_eval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1808 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1809 class_T *cl = tv.v_type == VAR_CLASS ? tv.vval.v_class |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1810 : tv.vval.v_object->obj_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1811 if (cl == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1812 goto fail_after_eval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1813 char_u *fname = name_end + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1814 char_u *fname_end = find_name_end(fname, NULL, NULL, FNE_CHECK_START); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1815 if (fname_end == fname) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1816 goto fail_after_eval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1817 len = fname_end - fname; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1818 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1819 int count = tv.v_type == VAR_CLASS ? cl->class_class_function_count |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1820 : cl->class_obj_method_count; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1821 ufunc_T **funcs = tv.v_type == VAR_CLASS ? cl->class_class_functions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1822 : cl->class_obj_methods; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1823 for (int i = 0; i < count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1824 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1825 ufunc_T *fp = funcs[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1826 // Use a separate pointer to avoid that ASAN complains about |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1827 // uf_name[] only being 4 characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1828 char_u *ufname = (char_u *)fp->uf_name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1829 if (STRNCMP(fname, ufname, len) == 0 && ufname[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1830 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1831 clear_tv(&tv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1832 return fp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1833 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1834 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1835 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1836 fail_after_eval: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1837 clear_tv(&tv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1838 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1839 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1840 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1841 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1842 * If "name[len]" is a class member in cctx->ctx_ufunc->uf_class return the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1843 * index in class.class_class_members[]. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1844 * If "cl_ret" is not NULL set it to the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1845 * Otherwise return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1846 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1847 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1848 class_member_index(char_u *name, size_t len, class_T **cl_ret, cctx_T *cctx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1849 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1850 if (cctx == NULL || cctx->ctx_ufunc == NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1851 || cctx->ctx_ufunc->uf_class == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1852 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1853 class_T *cl = cctx->ctx_ufunc->uf_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1854 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1855 for (int i = 0; i < cl->class_class_member_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1856 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1857 ocmember_T *m = &cl->class_class_members[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1858 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1859 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1860 if (cl_ret != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1861 *cl_ret = cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1862 return i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1863 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1864 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1865 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1866 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1867 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1868 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1869 * Return TRUE if current context "cctx_arg" is inside class "cl". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1870 * Return FALSE if not. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1871 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1872 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1873 inside_class(cctx_T *cctx_arg, class_T *cl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1874 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1875 for (cctx_T *cctx = cctx_arg; cctx != NULL; cctx = cctx->ctx_outer) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1876 if (cctx->ctx_ufunc != NULL && cctx->ctx_ufunc->uf_class == cl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1877 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1878 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1879 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1880 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1881 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1882 * Make a copy of an object. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1883 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1884 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1885 copy_object(typval_T *from, typval_T *to) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1886 { |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1887 if (from->vval.v_object == NULL) |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1888 to->vval.v_object = NULL; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1889 else |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1890 { |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1891 to->vval.v_object = from->vval.v_object; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1892 ++to->vval.v_object->obj_refcount; |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1893 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1894 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1895 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1896 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1897 * Free an object. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1898 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1899 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1900 object_clear(object_T *obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1901 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1902 // Avoid a recursive call, it can happen if "obj" has a circular reference. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1903 obj->obj_refcount = INT_MAX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1904 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1905 class_T *cl = obj->obj_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1906 |
32792
ba5a67216596
patch 9.0.1712: missing null check in object_clear()
Christian Brabandt <cb@256bit.org>
parents:
32772
diff
changeset
|
1907 if (!cl) |
33006
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32984
diff
changeset
|
1908 return; |
32792
ba5a67216596
patch 9.0.1712: missing null check in object_clear()
Christian Brabandt <cb@256bit.org>
parents:
32772
diff
changeset
|
1909 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1910 // the member values are just after the object structure |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1911 typval_T *tv = (typval_T *)(obj + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1912 for (int i = 0; i < cl->class_obj_member_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1913 clear_tv(tv + i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1914 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1915 // Remove from the list headed by "first_object". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1916 object_cleared(obj); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1917 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1918 vim_free(obj); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1919 class_unref(cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1920 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1921 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1922 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1923 * Unreference an object. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1924 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1925 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1926 object_unref(object_T *obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1927 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1928 if (obj != NULL && --obj->obj_refcount <= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1929 object_clear(obj); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1930 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1931 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1932 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1933 * Make a copy of a class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1934 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1935 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1936 copy_class(typval_T *from, typval_T *to) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1937 { |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1938 if (from->vval.v_class == NULL) |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1939 to->vval.v_class = NULL; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1940 else |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1941 { |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1942 to->vval.v_class = from->vval.v_class; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1943 ++to->vval.v_class->class_refcount; |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
1944 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1945 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1946 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1947 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1948 * Unreference a class. Free it when the reference count goes down to zero. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1949 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1950 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1951 class_unref(class_T *cl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1952 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1953 if (cl != NULL && --cl->class_refcount <= 0 && cl->class_name != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1954 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1955 // Freeing what the class contains may recursively come back here. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1956 // Clear "class_name" first, if it is NULL the class does not need to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1957 // be freed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1958 VIM_CLEAR(cl->class_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1959 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1960 class_unref(cl->class_extends); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1961 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1962 for (int i = 0; i < cl->class_interface_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1963 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1964 vim_free(((char_u **)cl->class_interfaces)[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1965 if (cl->class_interfaces_cl[i] != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1966 class_unref(cl->class_interfaces_cl[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1967 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1968 vim_free(cl->class_interfaces); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1969 vim_free(cl->class_interfaces_cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1970 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1971 itf2class_T *next; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1972 for (itf2class_T *i2c = cl->class_itf2class; i2c != NULL; i2c = next) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1973 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1974 next = i2c->i2c_next; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1975 vim_free(i2c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1976 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1977 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1978 for (int i = 0; i < cl->class_class_member_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1979 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1980 ocmember_T *m = &cl->class_class_members[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1981 vim_free(m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1982 vim_free(m->ocm_init); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1983 if (cl->class_members_tv != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1984 clear_tv(&cl->class_members_tv[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1985 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1986 vim_free(cl->class_class_members); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1987 vim_free(cl->class_members_tv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1988 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1989 for (int i = 0; i < cl->class_obj_member_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1990 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1991 ocmember_T *m = &cl->class_obj_members[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1992 vim_free(m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1993 vim_free(m->ocm_init); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1994 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1995 vim_free(cl->class_obj_members); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1996 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1997 for (int i = 0; i < cl->class_class_function_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1998 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1999 ufunc_T *uf = cl->class_class_functions[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2000 func_clear_free(uf, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2001 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2002 vim_free(cl->class_class_functions); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2003 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2004 for (int i = 0; i < cl->class_obj_method_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2005 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2006 ufunc_T *uf = cl->class_obj_methods[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2007 func_clear_free(uf, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2008 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2009 vim_free(cl->class_obj_methods); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2010 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2011 clear_type_list(&cl->class_type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2012 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2013 vim_free(cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2014 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2015 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2016 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2017 static object_T *first_object = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2018 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2019 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2020 * Call this function when an object has been created. It will be added to the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2021 * list headed by "first_object". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2022 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2023 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2024 object_created(object_T *obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2025 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2026 if (first_object != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2027 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2028 obj->obj_next_used = first_object; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2029 first_object->obj_prev_used = obj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2030 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2031 first_object = obj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2032 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2033 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2034 static object_T *next_nonref_obj = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2035 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2036 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2037 * Call this function when an object has been cleared and is about to be freed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2038 * It is removed from the list headed by "first_object". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2039 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2040 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2041 object_cleared(object_T *obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2042 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2043 if (obj->obj_next_used != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2044 obj->obj_next_used->obj_prev_used = obj->obj_prev_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2045 if (obj->obj_prev_used != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2046 obj->obj_prev_used->obj_next_used = obj->obj_next_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2047 else if (first_object == obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2048 first_object = obj->obj_next_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2049 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2050 // update the next object to check if needed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2051 if (obj == next_nonref_obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2052 next_nonref_obj = obj->obj_next_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2053 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2054 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2055 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2056 * Go through the list of all objects and free items without "copyID". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2057 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2058 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2059 object_free_nonref(int copyID) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2060 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2061 int did_free = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2062 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2063 for (object_T *obj = first_object; obj != NULL; obj = next_nonref_obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2064 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2065 next_nonref_obj = obj->obj_next_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2066 if ((obj->obj_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2067 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2068 // Free the object and items it contains. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2069 object_clear(obj); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2070 did_free = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2071 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2072 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2073 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2074 next_nonref_obj = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2075 return did_free; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2076 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2077 |
32984 | 2078 /* |
33006
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32984
diff
changeset
|
2079 * Return TRUE when the class "cl", its base class or one of the implemented |
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32984
diff
changeset
|
2080 * interfaces matches the class "other_cl". |
32984 | 2081 */ |
2082 int | |
2083 class_instance_of(class_T *cl, class_T *other_cl) | |
2084 { | |
2085 if (cl == other_cl) | |
2086 return TRUE; | |
2087 | |
2088 // Recursively check the base classes. | |
2089 for (; cl != NULL; cl = cl->class_extends) | |
2090 { | |
2091 if (cl == other_cl) | |
2092 return TRUE; | |
2093 // Check the implemented interfaces. | |
2094 for (int i = cl->class_interface_count - 1; i >= 0; --i) | |
2095 if (cl->class_interfaces_cl[i] == other_cl) | |
2096 return TRUE; | |
2097 } | |
2098 | |
2099 return FALSE; | |
2100 } | |
2101 | |
2102 /* | |
2103 * "instanceof(object, classinfo)" function | |
2104 */ | |
2105 void | |
2106 f_instanceof(typval_T *argvars, typval_T *rettv) | |
2107 { | |
2108 typval_T *object_tv = &argvars[0]; | |
2109 typval_T *classinfo_tv = &argvars[1]; | |
2110 listitem_T *li; | |
2111 | |
2112 rettv->vval.v_number = VVAL_FALSE; | |
2113 | |
2114 if (check_for_object_arg(argvars, 0) == FAIL | |
2115 || check_for_class_or_list_arg(argvars, 1) == FAIL) | |
2116 return; | |
2117 | |
2118 if (classinfo_tv->v_type == VAR_LIST) | |
2119 { | |
2120 FOR_ALL_LIST_ITEMS(classinfo_tv->vval.v_list, li) | |
2121 { | |
2122 if (li->li_tv.v_type != VAR_CLASS) | |
2123 { | |
2124 emsg(_(e_class_required)); | |
2125 return; | |
2126 } | |
2127 | |
2128 if (class_instance_of(object_tv->vval.v_object->obj_class, | |
2129 li->li_tv.vval.v_class) == TRUE) | |
2130 { | |
2131 rettv->vval.v_number = VVAL_TRUE; | |
2132 return; | |
2133 } | |
2134 } | |
2135 } | |
2136 else if (classinfo_tv->v_type == VAR_CLASS) | |
2137 { | |
2138 rettv->vval.v_number = class_instance_of(object_tv->vval.v_object->obj_class, | |
2139 classinfo_tv->vval.v_class); | |
2140 } | |
2141 } | |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2142 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2143 #endif // FEAT_EVAL |