Mercurial > vim
annotate src/vim9class.c @ 36515:9c7cfa946771 draft default tip
runtime(tex): extra Number highlighting causes issues
Commit: https://github.com/vim/vim/commit/622f6f5b9a9c2b88423f31a98e99cd3324446fcf
Author: Christian Brabandt <cb@256bit.org>
Date: Mon Nov 11 08:49:04 2024 +0100
runtime(tex): extra Number highlighting causes issues
So let's revert "runtime(tex): add Number highlighting to syntax file"
This (partly) reverts commits 8e6b5034f32049fd0 and 6065755a39d838aab
fixes: #16030
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 11 Nov 2024 09:00:05 +0100 |
parents | 71ec10757d8e |
children |
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 |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
24 static class_T *first_class = NULL; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
25 static class_T *next_nonref_class = NULL; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
26 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
27 /* |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
28 * Call this function when a class has been created. It will be added to the |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
29 * list headed by "first_class". |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
30 */ |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
31 static void |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
32 class_created(class_T *cl) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
33 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
34 if (first_class != NULL) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
35 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
36 cl->class_next_used = first_class; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
37 first_class->class_prev_used = cl; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
38 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
39 first_class = cl; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
40 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
41 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
42 /* |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
43 * Call this function when a class has been cleared and is about to be freed. |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
44 * It is removed from the list headed by "first_class". |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
45 */ |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
46 static void |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
47 class_cleared(class_T *cl) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
48 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
49 if (cl->class_next_used != NULL) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
50 cl->class_next_used->class_prev_used = cl->class_prev_used; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
51 if (cl->class_prev_used != NULL) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
52 cl->class_prev_used->class_next_used = cl->class_next_used; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
53 else if (first_class == cl) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
54 first_class = cl->class_next_used; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
55 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
56 // update the next class to check if needed |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
57 if (cl == next_nonref_class) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
58 next_nonref_class = cl->class_next_used; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
59 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
60 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
61 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
62 * Parse a member declaration, both object and class member. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
63 * 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
|
64 * 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
|
65 * "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
|
66 * one. For an interface "init_expr" is NULL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
67 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
68 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
69 parse_member( |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
70 exarg_T *eap, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
71 char_u *line, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
72 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
|
73 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
|
74 char_u **varname_end, |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
75 int *has_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
|
76 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
|
77 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
|
78 char_u **init_expr) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
79 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
80 *varname_end = to_name_end(varname, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
81 if (*varname == '_' && has_public) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
82 { |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
83 semsg(_(e_public_variable_name_cannot_start_with_underscore_str), line); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
84 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
85 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
86 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
87 char_u *colon = skipwhite(*varname_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
88 char_u *type_arg = colon; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
89 type_T *type = NULL; |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
90 *has_type = FALSE; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
91 if (*colon == ':') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
92 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
93 if (VIM_ISWHITE(**varname_end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
94 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
95 semsg(_(e_no_white_space_allowed_before_colon_str), varname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
96 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
97 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
98 if (!VIM_ISWHITE(colon[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
99 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
100 semsg(_(e_white_space_required_after_str_str), ":", varname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
101 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
102 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
103 type_arg = skipwhite(colon + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
104 type = parse_type(&type_arg, type_list, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
105 if (type == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
106 return FAIL; |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
107 *has_type = TRUE; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
108 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
109 |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
110 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
|
111 if (type == NULL && *init_arg != '=') |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
112 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
113 emsg(_(e_type_or_initialization_required)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
114 return FAIL; |
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 |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
117 if (init_expr == NULL && *init_arg == '=') |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
118 { |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
119 emsg(_(e_cannot_initialize_variable_in_interface)); |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
120 return FAIL; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
121 } |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
122 |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
123 if (*init_arg == '=') |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
124 { |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
125 evalarg_T evalarg; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
126 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
|
127 |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
128 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
|
129 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
130 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
|
131 "=", type_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
132 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
133 } |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
134 init_arg = skipwhite(init_arg + 1); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
135 |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
136 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
|
137 (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
|
138 |
35062
f57990be7526
patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
139 init_arg = skipwhite(init_arg); |
35068
60a7fae99560
patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents:
35062
diff
changeset
|
140 if (*init_arg != NUL && !vim9_comment_start(init_arg)) |
35062
f57990be7526
patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
141 { |
f57990be7526
patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
142 semsg(_(e_trailing_characters_str), init_arg); |
f57990be7526
patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
143 return FAIL; |
f57990be7526
patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
144 } |
f57990be7526
patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents:
34907
diff
changeset
|
145 |
33006
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32972
diff
changeset
|
146 // 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:
32972
diff
changeset
|
147 // 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
|
148 if (type == NULL) |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
149 type = &t_any; |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
150 |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
151 *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
|
152 // Free the memory pointed by expr_start. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
153 clear_evalarg(&evalarg, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
154 } |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
155 else if (!valid_declaration_type(type)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
156 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
157 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
158 *type_ret = type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
159 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
160 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
161 |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
162 typedef struct oc_newmember_S oc_newmember_T; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
163 struct oc_newmember_S |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
164 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
165 garray_T *gap; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
166 char_u *varname; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
167 char_u *varname_end; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
168 int has_public; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
169 int has_final; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
170 int has_type; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
171 type_T *type; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
172 char_u *init_expr; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
173 }; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
174 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
175 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
176 * Add a member to an object or a class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
177 * Returns OK when successful, "init_expr" will be consumed then. |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
178 * Returns OK on success and FAIL on memory allocation failure (caller might |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
179 * need to free "init_expr"). |
32670
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 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 int has_public, |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
187 int has_final, |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
188 int has_const, |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
189 int has_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
|
190 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
|
191 char_u *init_expr) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
192 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
193 if (ga_grow(gap, 1) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
194 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
195 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
|
196 m->ocm_name = vim_strnsave(varname, varname_end - varname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
197 m->ocm_access = has_public ? VIM_ACCESS_ALL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
198 : *varname == '_' ? VIM_ACCESS_PRIVATE : VIM_ACCESS_READ; |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
199 if (has_final) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
200 m->ocm_flags |= OCMFLAG_FINAL; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
201 if (has_const) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
202 m->ocm_flags |= OCMFLAG_CONST; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
203 if (has_type) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
204 m->ocm_flags |= OCMFLAG_HAS_TYPE; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
205 m->ocm_type = type; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
206 if (init_expr != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
207 m->ocm_init = init_expr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
208 ++gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
209 return OK; |
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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
212 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
213 * 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
|
214 * "gap" contains the found members. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
215 * "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
|
216 * "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
|
217 * "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
|
218 * "member_count" set to the number of members. |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
219 * Returns OK on success and FAIL on memory allocation failure. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
220 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
221 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
222 add_members_to_class( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
223 garray_T *gap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
224 ocmember_T *parent_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
225 int parent_count, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
226 ocmember_T **members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
227 int *member_count) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
228 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
229 *member_count = parent_count + gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
230 *members = *member_count == 0 ? NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
231 : ALLOC_MULT(ocmember_T, *member_count); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
232 if (*member_count > 0 && *members == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
233 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
234 for (int i = 0; i < parent_count; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
235 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
236 // parent members need to be copied |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
237 ocmember_T *m = *members + i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
238 *m = parent_members[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
239 m->ocm_name = vim_strsave(m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
240 if (m->ocm_init != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
241 m->ocm_init = vim_strsave(m->ocm_init); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
242 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
243 if (gap->ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
244 // new members are moved |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
245 mch_memmove(*members + parent_count, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
246 gap->ga_data, sizeof(ocmember_T) * gap->ga_len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
247 VIM_CLEAR(gap->ga_data); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
248 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
249 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
250 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
251 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
252 * 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
|
253 * "cl" implementing that interface. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
254 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
255 int |
33387
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
256 object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
257 { |
33173
9efd99a717c1
patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents:
33160
diff
changeset
|
258 if (idx >= (is_method ? itf->class_obj_method_count |
33387
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
259 : itf->class_obj_member_count)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
260 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
261 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
|
262 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
263 } |
32772
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
264 |
0dc750a24875
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32764
diff
changeset
|
265 // 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
|
266 // 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
|
267 // 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
|
268 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
|
269 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
|
270 |
33211
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
271 itf2class_T *i2c = NULL; |
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
272 int searching = TRUE; |
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
273 int method_offset = 0; |
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
274 |
33204
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
275 for (class_T *super = cl; super != NULL && searching; |
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
276 super = super->class_extends) |
33211
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
277 { |
33204
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
278 for (i2c = itf->class_itf2class; i2c != NULL; i2c = i2c->i2c_next) |
33211
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
279 { |
33204
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
280 if (i2c->i2c_class == super && i2c->i2c_is_method == is_method) |
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
281 { |
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
282 searching = FALSE; |
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
283 break; |
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
284 } |
33211
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
285 } |
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
286 if (searching && is_method) |
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
287 // The parent class methods are stored after the current class |
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
288 // methods. |
33387
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
289 method_offset += super->class_obj_method_count_child; |
33211
71a097aab64d
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents:
33204
diff
changeset
|
290 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
291 if (i2c == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
292 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
293 siemsg("class %s not found on interface %s", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
294 cl->class_name, itf->class_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
295 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
296 } |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
297 |
33387
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
298 // A table follows the i2c for the class |
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
299 int *table = (int *)(i2c + 1); |
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
300 // "method_offset" is 0, if method is in the current class. If method |
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
301 // is in a parent class, then it is non-zero. |
577ef266309d
patch 9.0.1952: Vim9: unused static field
Christian Brabandt <cb@256bit.org>
parents:
33385
diff
changeset
|
302 return table[idx] + method_offset; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
303 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
304 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
305 /* |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
306 * 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
|
307 * 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
|
308 * 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
|
309 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
310 static int |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
311 validate_extends_class( |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
312 class_T *cl, |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
313 char_u *extends_name, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
314 class_T **extends_clp, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
315 int is_class) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
316 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
317 typval_T tv; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
318 int success = FALSE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
319 |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
320 if (STRCMP(cl->class_name, extends_name) == 0) |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
321 { |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
322 semsg(_(e_cannot_extend_str), extends_name); |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
323 return success; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
324 } |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
325 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
326 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
|
327 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
|
328 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
329 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
|
330 return success; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
331 } |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
332 |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
333 if (tv.v_type != VAR_CLASS || tv.vval.v_class == NULL |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
334 || (is_class && IS_INTERFACE(tv.vval.v_class)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
335 || (!is_class && !IS_INTERFACE(tv.vval.v_class)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
336 || (is_class && IS_ENUM(tv.vval.v_class))) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
337 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
338 // a class cannot extend an interface |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
339 // an interface cannot extend a class |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
340 // a class cannot extend an enum. |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
341 semsg(_(e_cannot_extend_str), extends_name); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
342 } |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
343 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
344 { |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
345 class_T *extends_cl = tv.vval.v_class; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
346 ++extends_cl->class_refcount; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
347 *extends_clp = extends_cl; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
348 success = TRUE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
349 } |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
350 clear_tv(&tv); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
351 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
352 return success; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
353 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
354 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
355 /* |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
356 * Check method names in the parent class lineage to make sure the access is |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
357 * the same for overridden methods. |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
358 */ |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
359 static int |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
360 validate_extends_methods( |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
361 garray_T *objmethods_gap, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
362 class_T *extends_cl) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
363 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
364 class_T *super = extends_cl; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
365 int method_count = objmethods_gap->ga_len; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
366 ufunc_T **cl_fp = (ufunc_T **)(objmethods_gap->ga_data); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
367 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
368 while (super != NULL) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
369 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
370 int extends_method_count = super->class_obj_method_count_child; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
371 if (extends_method_count == 0) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
372 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
373 super = super->class_extends; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
374 continue; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
375 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
376 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
377 ufunc_T **extends_methods = super->class_obj_methods; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
378 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
379 for (int i = 0; i < extends_method_count; i++) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
380 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
381 char_u *pstr = extends_methods[i]->uf_name; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
382 int extends_private = (*pstr == '_'); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
383 if (extends_private) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
384 pstr++; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
385 |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
386 // When comparing the method names, ignore the access type (public |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
387 // and private methods are considered the same). |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
388 for (int j = 0; j < method_count; j++) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
389 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
390 char_u *qstr = cl_fp[j]->uf_name; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
391 int priv_method = (*qstr == '_'); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
392 if (priv_method) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
393 qstr++; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
394 if (STRCMP(pstr, qstr) == 0 && priv_method != extends_private) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
395 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
396 // Method access is different between the super class and |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
397 // the subclass |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
398 semsg(_(e_method_str_of_class_str_has_different_access), |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
399 cl_fp[j]->uf_name, super->class_name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
400 return FALSE; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
401 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
402 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
403 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
404 super = super->class_extends; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
405 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
406 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
407 return TRUE; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
408 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
409 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
410 /* |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
411 * Check whether a object member variable in "objmembers_gap" is a duplicate of |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
412 * a member in any of the extended parent class lineage. Returns TRUE if there |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
413 * are no duplicates. |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
414 */ |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
415 static int |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
416 extends_check_dup_members( |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
417 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
|
418 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
|
419 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
420 int member_count = objmembers_gap->ga_len; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
421 if (member_count == 0) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
422 return TRUE; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
423 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
424 ocmember_T *members = (ocmember_T *)(objmembers_gap->ga_data); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
425 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
426 // Validate each member variable |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
427 for (int c_i = 0; c_i < member_count; c_i++) |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
428 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
429 class_T *p_cl = extends_cl; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
430 ocmember_T *c_m = members + c_i; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
431 char_u *pstr = (*c_m->ocm_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
|
432 ? 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
|
433 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
434 // Check in all the parent classes in the lineage |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
435 while (p_cl != NULL) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
436 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
437 int p_member_count = p_cl->class_obj_member_count; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
438 if (p_member_count == 0) |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
439 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
440 p_cl = p_cl->class_extends; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
441 continue; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
442 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
443 ocmember_T *p_members = p_cl->class_obj_members; |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
444 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
445 // Compare against all the members in the parent class |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
446 for (int p_i = 0; p_i < p_member_count; p_i++) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
447 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
448 ocmember_T *p_m = p_members + p_i; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
449 char_u *qstr = (*p_m->ocm_name == '_') |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
450 ? p_m->ocm_name + 1 : p_m->ocm_name; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
451 if (STRCMP(pstr, qstr) == 0) |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
452 { |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
453 semsg(_(e_duplicate_variable_str), c_m->ocm_name); |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
454 return FALSE; |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
455 } |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
456 } |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
457 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
458 p_cl = p_cl->class_extends; |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
459 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
460 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
461 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
462 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
|
463 } |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
464 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
465 /* |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
466 * Compare the variable type of interface variables in "objmembers_gap" against |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
467 * the variable in any of the extended super interface lineage. Used to |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
468 * compare the variable types when extending interfaces. Returns TRUE if the |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
469 * variable types are the same. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
470 */ |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
471 static int |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
472 extends_check_intf_var_type( |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
473 garray_T *objmembers_gap, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
474 class_T *extends_cl) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
475 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
476 int member_count = objmembers_gap->ga_len; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
477 if (member_count == 0) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
478 return TRUE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
479 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
480 ocmember_T *members = (ocmember_T *)(objmembers_gap->ga_data); |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
481 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
482 // Validate each member variable |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
483 for (int c_i = 0; c_i < member_count; c_i++) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
484 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
485 class_T *p_cl = extends_cl; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
486 ocmember_T *c_m = members + c_i; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
487 int var_found = FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
488 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
489 // Check in all the parent classes in the lineage |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
490 while (p_cl != NULL && !var_found) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
491 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
492 int p_member_count = p_cl->class_obj_member_count; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
493 if (p_member_count == 0) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
494 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
495 p_cl = p_cl->class_extends; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
496 continue; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
497 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
498 ocmember_T *p_members = p_cl->class_obj_members; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
499 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
500 // Compare against all the members in the parent class |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
501 for (int p_i = 0; p_i < p_member_count; p_i++) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
502 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
503 where_T where = WHERE_INIT; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
504 ocmember_T *p_m = p_members + p_i; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
505 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
506 if (STRCMP(p_m->ocm_name, c_m->ocm_name) != 0) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
507 continue; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
508 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
509 // Ensure the type is matching. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
510 where.wt_func_name = (char *)c_m->ocm_name; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
511 where.wt_kind = WT_MEMBER; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
512 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
513 if (check_type(p_m->ocm_type, c_m->ocm_type, TRUE, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
514 where) == FAIL) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
515 return FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
516 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
517 var_found = TRUE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
518 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
519 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
520 p_cl = p_cl->class_extends; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
521 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
522 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
523 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
524 return TRUE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
525 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
526 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
527 /* |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
528 * When extending an abstract class, check whether all the abstract methods in |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
529 * the parent class are implemented. Returns TRUE if all the methods are |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
530 * implemented. |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
531 */ |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
532 static int |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
533 validate_abstract_class_methods( |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
534 garray_T *classmethods_gap, |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
535 garray_T *objmethods_gap, |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
536 class_T *extends_cl) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
537 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
538 for (int loop = 1; loop <= 2; ++loop) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
539 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
540 // loop == 1: check class methods |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
541 // loop == 2: check object methods |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
542 int extends_method_count = loop == 1 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
543 ? extends_cl->class_class_function_count |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
544 : extends_cl->class_obj_method_count; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
545 if (extends_method_count == 0) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
546 continue; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
547 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
548 ufunc_T **extends_methods = loop == 1 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
549 ? extends_cl->class_class_functions |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
550 : extends_cl->class_obj_methods; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
551 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
552 int method_count = loop == 1 ? classmethods_gap->ga_len |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
553 : objmethods_gap->ga_len; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
554 ufunc_T **cl_fp = (ufunc_T **)(loop == 1 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
555 ? classmethods_gap->ga_data |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
556 : objmethods_gap->ga_data); |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
557 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
558 for (int i = 0; i < extends_method_count; i++) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
559 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
560 ufunc_T *uf = extends_methods[i]; |
33297
6340c608ca54
patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents:
33291
diff
changeset
|
561 if (!IS_ABSTRACT_METHOD(uf)) |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
562 continue; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
563 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
564 int method_found = FALSE; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
565 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
566 for (int j = 0; j < method_count; j++) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
567 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
568 if (STRCMP(uf->uf_name, cl_fp[j]->uf_name) == 0) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
569 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
570 method_found = TRUE; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
571 break; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
572 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
573 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
574 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
575 if (!method_found) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
576 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
577 semsg(_(e_abstract_method_str_not_found), uf->uf_name); |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
578 return FALSE; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
579 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
580 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
581 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
582 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
583 return TRUE; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
584 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
585 |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
586 /* |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
587 * Returns TRUE if the interface variable "if_var" is present in the list of |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
588 * variables in "cl_mt" or in the parent lineage of one of the extended classes |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
589 * in "extends_cl". For a class variable, 'is_class_var' is TRUE. |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
590 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
591 static int |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
592 intf_variable_present( |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
593 char_u *intf_class_name, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
594 ocmember_T *if_var, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
595 ocmember_T *cl_mt, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
596 int cl_member_count, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
597 class_T *extends_cl) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
598 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
599 int variable_present = FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
600 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
601 for (int cl_i = 0; cl_i < cl_member_count; ++cl_i) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
602 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
603 ocmember_T *m = &cl_mt[cl_i]; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
604 where_T where = WHERE_INIT; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
605 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
606 if (STRCMP(if_var->ocm_name, m->ocm_name) != 0) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
607 continue; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
608 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
609 // Ensure the access type is same |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
610 if (if_var->ocm_access != m->ocm_access) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
611 { |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
612 semsg(_(e_variable_str_of_interface_str_has_different_access), |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
613 if_var->ocm_name, intf_class_name); |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
614 return FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
615 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
616 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
617 // Ensure the type is matching. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
618 if (m->ocm_type == &t_any) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
619 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
620 // variable type is not specified. Use the variable type in the |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
621 // interface. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
622 m->ocm_type = if_var->ocm_type; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
623 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
624 else |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
625 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
626 where.wt_func_name = (char *)m->ocm_name; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
627 where.wt_kind = WT_MEMBER; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
628 if (check_type(if_var->ocm_type, m->ocm_type, TRUE, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
629 where) == FAIL) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
630 return FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
631 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
632 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
633 variable_present = TRUE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
634 break; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
635 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
636 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
637 if (!variable_present && extends_cl != NULL) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
638 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
639 int ext_cl_count = extends_cl->class_obj_member_count; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
640 ocmember_T *ext_cl_mt = extends_cl->class_obj_members; |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
641 return intf_variable_present(intf_class_name, if_var, |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
642 ext_cl_mt, ext_cl_count, |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
643 extends_cl->class_extends); |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
644 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
645 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
646 return variable_present; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
647 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
648 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
649 /* |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
650 * Check the variables of the interface class "ifcl" match object variables |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
651 * ("objmembers_gap") of a class. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
652 * Returns TRUE if the object variables names are valid. |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
653 */ |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
654 static int |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
655 validate_interface_variables( |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
656 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
|
657 class_T *ifcl, |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
658 garray_T *objmembers_gap, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
659 class_T *extends_cl) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
660 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
661 int if_count = ifcl->class_obj_member_count; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
662 if (if_count == 0) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
663 return TRUE; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
664 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
665 ocmember_T *if_ms = ifcl->class_obj_members; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
666 ocmember_T *cl_ms = (ocmember_T *)(objmembers_gap->ga_data); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
667 int cl_count = objmembers_gap->ga_len; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
668 for (int if_i = 0; if_i < if_count; ++if_i) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
669 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
670 if (!intf_variable_present(intf_class_name, &if_ms[if_i], cl_ms, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
671 cl_count, extends_cl)) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
672 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
673 semsg(_(e_variable_str_of_interface_str_not_implemented), |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
674 if_ms[if_i].ocm_name, intf_class_name); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
675 return FALSE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
676 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
677 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
678 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
679 return TRUE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
680 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
681 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
682 /* |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
683 * Returns TRUE if the method signature of "if_method" and "cl_method" matches. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
684 */ |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
685 static int |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
686 intf_method_type_matches(ufunc_T *if_method, ufunc_T *cl_method) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
687 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
688 where_T where = WHERE_INIT; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
689 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
690 // Ensure the type is matching. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
691 where.wt_func_name = (char *)if_method->uf_name; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
692 where.wt_kind = WT_METHOD; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
693 if (check_type(if_method->uf_func_type, cl_method->uf_func_type, TRUE, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
694 where) == FAIL) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
695 return FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
696 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
697 return TRUE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
698 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
699 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
700 /* |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
701 * Returns TRUE if the interface method "if_ufunc" is present in the list of |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
702 * methods in "cl_fp" or in the parent lineage of one of the extended classes |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
703 * in "extends_cl". For a class method, 'is_class_method' is TRUE. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
704 */ |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
705 static int |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
706 intf_method_present( |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
707 ufunc_T *if_ufunc, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
708 ufunc_T **cl_fp, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
709 int cl_count, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
710 class_T *extends_cl) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
711 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
712 int method_present = FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
713 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
714 for (int cl_i = 0; cl_i < cl_count; ++cl_i) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
715 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
716 char_u *cl_name = cl_fp[cl_i]->uf_name; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
717 if (STRCMP(if_ufunc->uf_name, cl_name) == 0) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
718 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
719 // Ensure the type is matching. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
720 if (!intf_method_type_matches(if_ufunc, cl_fp[cl_i])) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
721 return FALSE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
722 method_present = TRUE; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
723 break; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
724 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
725 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
726 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
727 if (!method_present && extends_cl != NULL) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
728 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
729 ufunc_T **ext_cl_fp = (ufunc_T **)(extends_cl->class_obj_methods); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
730 int ext_cl_count = extends_cl->class_obj_method_count; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
731 return intf_method_present(if_ufunc, ext_cl_fp, ext_cl_count, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
732 extends_cl->class_extends); |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
733 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
734 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
735 return method_present; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
736 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
737 |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
738 /* |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
739 * Validate that a new class implements all the class/instance methods in the |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
740 * interface "ifcl". The new class methods are in "classfunctions_gap" and the |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
741 * new object methods are in "objmemthods_gap". Also validates the method |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
742 * types. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
743 * Returns TRUE if all the interface class/object methods are implemented in |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
744 * the new class. |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
745 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
746 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
747 validate_interface_methods( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
748 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
|
749 class_T *ifcl, |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
750 garray_T *objmethods_gap, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
751 class_T *extends_cl) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
752 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
753 int if_count = ifcl->class_obj_method_count; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
754 if (if_count == 0) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
755 return TRUE; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
756 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
757 ufunc_T **if_fp = ifcl->class_obj_methods; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
758 ufunc_T **cl_fp = (ufunc_T **)(objmethods_gap->ga_data); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
759 int cl_count = objmethods_gap->ga_len; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
760 for (int if_i = 0; if_i < if_count; ++if_i) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
761 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
762 char_u *if_name = if_fp[if_i]->uf_name; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
763 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
764 if (!intf_method_present(if_fp[if_i], cl_fp, cl_count, extends_cl)) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
765 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
766 semsg(_(e_method_str_of_interface_str_not_implemented), |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
767 if_name, intf_class_name); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
768 return FALSE; |
32896
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 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
771 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
772 return TRUE; |
32896
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 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
775 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
776 * 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
|
777 * 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
|
778 * 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
|
779 * "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
|
780 * "objmembers_gap" respectively. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
781 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
782 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
783 validate_implements_classes( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
784 garray_T *impl_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
785 class_T **intf_classes, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
786 garray_T *objmethods_gap, |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
787 garray_T *objmembers_gap, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
788 class_T *extends_cl) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
789 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
790 int success = TRUE; |
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 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
|
793 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
794 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
|
795 typval_T tv; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
796 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
|
797 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
|
798 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
799 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
|
800 success = FALSE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
801 break; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
802 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
803 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
804 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
|
805 || tv.vval.v_class == NULL |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
806 || !IS_INTERFACE(tv.vval.v_class)) |
32896
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 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
|
809 success = FALSE; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
810 clear_tv(&tv); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
811 break; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
812 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
813 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
814 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
|
815 intf_classes[i] = ifcl; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
816 ++ifcl->class_refcount; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
817 |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
818 // check the variables of the interface match the members of the class |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
819 success = validate_interface_variables(impl, ifcl, objmembers_gap, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
820 extends_cl); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
821 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
822 // 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
|
823 // 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
|
824 if (success) |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
825 success = validate_interface_methods(impl, ifcl, objmethods_gap, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
826 extends_cl); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
827 clear_tv(&tv); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
828 } |
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 return success; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
831 } |
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 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
834 * 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
|
835 * (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
|
836 * to check them.) |
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 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
839 check_func_arg_names( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
840 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
841 garray_T *objmethods_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
842 garray_T *classmembers_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
843 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
844 // 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
|
845 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
|
846 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
847 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
|
848 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
849 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
|
850 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
851 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
|
852 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
853 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
|
854 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
855 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
|
856 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
|
857 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
858 // 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
|
859 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
|
860 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
861 char_u *mname = |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
862 ((ocmember_T *)mgap->ga_data + mi)->ocm_name; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
863 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
|
864 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
865 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
|
866 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
|
867 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
868 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
|
869 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
|
870 |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
871 return FALSE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
872 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
873 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
874 } |
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 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
877 |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
878 return TRUE; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
879 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
880 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
881 /* |
33381
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
882 * Returns TRUE if 'varname' is a reserved keyword name |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
883 */ |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
884 static int |
33381
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
885 is_reserved_varname(char_u *varname, char_u *varname_end) |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
886 { |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
887 int reserved = FALSE; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
888 char_u save_varname_end = *varname_end; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
889 *varname_end = NUL; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
890 |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
891 reserved = check_reserved_name(varname, FALSE) == FAIL; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
892 |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
893 *varname_end = save_varname_end; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
894 |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
895 return reserved; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
896 } |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
897 |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
898 /* |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
899 * Returns TRUE if the variable "varname" is already defined either as a class |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
900 * variable or as an object variable. |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
901 */ |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
902 static int |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
903 is_duplicate_variable( |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
904 garray_T *class_members, |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
905 garray_T *obj_members, |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
906 char_u *varname, |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
907 char_u *varname_end) |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
908 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
909 char_u *name = vim_strnsave(varname, varname_end - varname); |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
910 char_u *pstr = (*name == '_') ? name + 1 : name; |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
911 int dup = FALSE; |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
912 |
33381
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
913 for (int loop = 1; loop <= 2; loop++) |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
914 { |
33381
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
915 // loop == 1: class variables, loop == 2: object variables |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
916 garray_T *vgap = (loop == 1) ? class_members : obj_members; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
917 for (int i = 0; i < vgap->ga_len; ++i) |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
918 { |
33381
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
919 ocmember_T *m = ((ocmember_T *)vgap->ga_data) + i; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
920 char_u *qstr = *m->ocm_name == '_' ? m->ocm_name + 1 |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
921 : m->ocm_name; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
922 if (STRCMP(pstr, qstr) == 0) |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
923 { |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
924 semsg(_(e_duplicate_variable_str), name); |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
925 dup = TRUE; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
926 break; |
17301c641749
patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents:
33372
diff
changeset
|
927 } |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
928 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
929 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
930 |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
931 vim_free(name); |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
932 return dup; |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
933 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
934 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
935 /* |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
936 * 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
|
937 */ |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
938 static int |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
939 is_duplicate_method( |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
940 garray_T *classmethods_gap, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
941 garray_T *objmethods_gap, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
942 char_u *name) |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
943 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
944 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
|
945 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
946 // loop 1: class methods, loop 2: object methods |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
947 for (int loop = 1; loop <= 2; loop++) |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
948 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
949 garray_T *fgap = (loop == 1) ? classmethods_gap : objmethods_gap; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
950 for (int i = 0; i < fgap->ga_len; ++i) |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
951 { |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
952 char_u *n = ((ufunc_T **)fgap->ga_data)[i]->uf_name; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
953 char_u *qstr = *n == '_' ? n + 1 : n; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
954 if (STRCMP(pstr, qstr) == 0) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
955 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
956 semsg(_(e_duplicate_function_str), name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
957 return TRUE; |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
958 } |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
959 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
960 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
961 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
962 return FALSE; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
963 } |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
964 |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
965 /* |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
966 * 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
|
967 */ |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
968 static int |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
969 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
|
970 { |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
971 // 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
|
972 if (is_abstract) |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
973 { |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
974 emsg(_(e_cannot_define_new_method_in_abstract_class)); |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
975 return FALSE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
976 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
977 // 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
|
978 if (has_static) |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
979 { |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
980 emsg(_(e_cannot_define_new_method_as_static)); |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
981 return FALSE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
982 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
983 // 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
|
984 // constructor method. |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
985 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
|
986 { |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
987 emsg(_(e_cannot_use_a_return_type_with_new_method)); |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
988 return FALSE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
989 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
990 return TRUE; |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
991 } |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
992 |
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
993 /* |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
994 * Returns TRUE if 'uf' is a supported builtin method and has the correct |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
995 * method signature. |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
996 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
997 static int |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
998 object_check_builtin_method_sig(ufunc_T *uf) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
999 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1000 char_u *name = uf->uf_name; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1001 int valid = FALSE; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1002 type_T method_sig; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1003 type_T method_rt; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1004 where_T where = WHERE_INIT; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1005 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1006 // validate the method signature |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1007 CLEAR_FIELD(method_sig); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1008 CLEAR_FIELD(method_rt); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1009 method_sig.tt_type = VAR_FUNC; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1010 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1011 if (STRCMP(name, "len") == 0) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1012 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1013 // def __len(): number |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1014 method_rt.tt_type = VAR_NUMBER; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1015 method_sig.tt_member = &method_rt; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1016 valid = TRUE; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1017 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1018 else if (STRCMP(name, "empty") == 0) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1019 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1020 // def __empty(): bool |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1021 method_rt.tt_type = VAR_BOOL; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1022 method_sig.tt_member = &method_rt; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1023 valid = TRUE; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1024 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1025 else if (STRCMP(name, "string") == 0) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1026 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1027 // def __string(): string |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1028 method_rt.tt_type = VAR_STRING; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1029 method_sig.tt_member = &method_rt; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1030 valid = TRUE; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1031 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1032 else |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1033 semsg(_(e_builtin_object_method_str_not_supported), uf->uf_name); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1034 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1035 where.wt_func_name = (char *)uf->uf_name; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1036 where.wt_kind = WT_METHOD; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1037 if (valid && !check_type(&method_sig, uf->uf_func_type, TRUE, where)) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1038 valid = FALSE; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1039 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1040 return valid; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1041 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1042 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1043 /* |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1044 * Returns TRUE if "funcname" is a supported builtin object method name |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1045 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1046 int |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1047 is_valid_builtin_obj_methodname(char_u *funcname) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1048 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1049 switch (funcname[0]) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1050 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1051 case 'e': |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1052 return STRNCMP(funcname, "empty", 5) == 0; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1053 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1054 case 'l': |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1055 return STRNCMP(funcname, "len", 3) == 0; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1056 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1057 case 'n': |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1058 return STRNCMP(funcname, "new", 3) == 0; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1059 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1060 case 's': |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1061 return STRNCMP(funcname, "string", 6) == 0; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1062 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1063 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1064 return FALSE; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1065 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1066 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1067 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1068 /* |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1069 * Returns the builtin method "name" in object "obj". Returns NULL if the |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1070 * method is not found. |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1071 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1072 ufunc_T * |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1073 class_get_builtin_method( |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1074 class_T *cl, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1075 class_builtin_T builtin_method, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1076 int *method_idx) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1077 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1078 *method_idx = -1; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1079 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1080 if (cl == NULL) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1081 return NULL; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1082 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1083 *method_idx = cl->class_builtin_methods[builtin_method]; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1084 return *method_idx != -1 ? cl->class_obj_methods[*method_idx] : NULL; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1085 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1086 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1087 /* |
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
|
1088 * 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
|
1089 * 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
|
1090 * 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
|
1091 * 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
|
1092 * 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
|
1093 * 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
|
1094 */ |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1095 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
|
1096 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
|
1097 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
|
1098 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
|
1099 garray_T *objmethods, |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1100 int pobj_method_offset) |
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
|
1101 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1102 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
|
1103 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
|
1104 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1105 // 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
|
1106 itf2class_T *if2cl = alloc_clear(sizeof(itf2class_T) |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1107 + ifcl->class_obj_member_count * sizeof(int)); |
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
|
1108 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
|
1109 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
|
1110 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
|
1111 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
|
1112 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
|
1113 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
|
1114 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1115 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
|
1116 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
|
1117 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1118 if (STRCMP(ifcl->class_obj_members[if_i].ocm_name, |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1119 cl->class_obj_members[cl_i].ocm_name) == 0) |
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
|
1120 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1121 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
|
1122 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
|
1123 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
|
1124 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1125 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1126 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1127 // 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
|
1128 if2cl = alloc_clear(sizeof(itf2class_T) |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1129 + ifcl->class_obj_method_count * sizeof(int)); |
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
|
1130 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
|
1131 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
|
1132 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
|
1133 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
|
1134 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
|
1135 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
|
1136 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1137 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
|
1138 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1139 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
|
1140 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
|
1141 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1142 if (STRCMP(ifcl->class_obj_methods[if_i]->uf_name, |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1143 ((ufunc_T **)objmethods->ga_data)[cl_i]->uf_name) == 0) |
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
|
1144 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1145 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
|
1146 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
|
1147 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
|
1148 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
|
1149 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1150 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1151 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1152 // 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
|
1153 // 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
|
1154 // lineage. |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1155 if (!done) |
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
|
1156 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1157 // 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
|
1158 // 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
|
1159 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
|
1160 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1161 class_T *parent = cl->class_extends; |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1162 int method_offset = objmethods->ga_len; |
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
|
1163 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1164 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
|
1165 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1166 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1167 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
|
1168 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
|
1169 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1170 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
|
1171 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
|
1172 == 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
|
1173 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1179 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1180 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
|
1181 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
|
1182 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1183 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1184 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1185 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
|
1186 { |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1187 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
|
1188 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
|
1189 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1190 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1191 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1192 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1193 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
|
1194 } |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1195 |
5fd9fe58c791
patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents:
32812
diff
changeset
|
1196 /* |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1197 * 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
|
1198 * interface class. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1199 * 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
|
1200 * 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
|
1201 * 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
|
1202 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1203 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1204 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
|
1205 { |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1206 // update the lookup table for all the implemented interfaces |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1207 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
|
1208 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1209 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
|
1210 |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1211 // update the lookup table for this interface and all its super |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1212 // interfaces. |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1213 while (ifcl != NULL) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1214 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1215 if (update_member_method_lookup_table(ifcl, cl, objmethods_gap, |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1216 0) == FAIL) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1217 return FAIL; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1218 ifcl = ifcl->class_extends; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1219 } |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1220 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1221 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
1222 // Update the lookup table for the extended class, if any |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1223 if (extends_cl != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1224 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1225 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
|
1226 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
|
1227 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1228 // 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
|
1229 while (pclass != NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1230 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1231 if (update_member_method_lookup_table(pclass, cl, |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1232 objmethods_gap, pobj_method_offset) == FAIL) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1233 return FAIL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1234 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1235 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
|
1236 pclass = pclass->class_extends; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1237 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1238 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1239 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1240 return OK; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1241 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1242 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1243 /* |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1244 * 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
|
1245 * and initialize it. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1246 */ |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1247 static int |
33471
baa62f464436
patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents:
33456
diff
changeset
|
1248 add_class_members(class_T *cl, exarg_T *eap, garray_T *type_list_gap) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1249 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1250 // 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
|
1251 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
|
1252 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
|
1253 if (cl->class_members_tv == NULL) |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1254 return FAIL; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1255 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1256 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
|
1257 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1258 ocmember_T *m = &cl->class_class_members[i]; |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1259 typval_T *tv = &cl->class_members_tv[i]; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1260 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
|
1261 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1262 typval_T *etv = eval_expr(m->ocm_init, eap); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1263 if (etv == NULL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1264 return FAIL; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1265 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1266 if (m->ocm_type->tt_type == VAR_ANY |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1267 && !(m->ocm_flags & OCMFLAG_HAS_TYPE) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1268 && etv->v_type != VAR_SPECIAL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1269 // If the member variable type is not yet set, then use |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1270 // the initialization expression type. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1271 m->ocm_type = typval2type(etv, get_copyID(), |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1272 type_list_gap, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1273 TVTT_DO_MEMBER|TVTT_MORE_SPECIFIC); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1274 *tv = *etv; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1275 vim_free(etv); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1276 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1277 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1278 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1279 // TODO: proper default value |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1280 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
|
1281 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
|
1282 } |
35518
0e8dbbe586c3
patch 9.1.0520: Vim9: incorrect type checking for modifying lists
Christian Brabandt <cb@256bit.org>
parents:
35499
diff
changeset
|
1283 set_tv_type(tv, m->ocm_type); |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
1284 if (m->ocm_flags & OCMFLAG_CONST) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
1285 item_lock(tv, DICT_MAXNEST, TRUE, TRUE); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1286 } |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1287 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1288 return OK; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1289 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1290 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1291 /* |
32903
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
1292 * 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
|
1293 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1294 static void |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1295 add_default_constructor( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1296 class_T *cl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1297 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1298 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
|
1299 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1300 garray_T fga; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1301 int is_enum = IS_ENUM(cl); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1302 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1303 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
|
1304 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
|
1305 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
|
1306 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1307 if (i < 2 && is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1308 // The first two object variables in an enum are the enum value |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1309 // name and ordinal. Don't initialize these object variables in |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1310 // the default constructor as they are already initialized right |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1311 // after creating the object. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1312 continue; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1313 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1314 if (i > (is_enum ? 2 : 0)) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1321 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
|
1322 ga_append(&fga, NUL); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1323 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1324 exarg_T fea; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1325 CLEAR_FIELD(fea); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1326 fea.cmdidx = CMD_def; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1327 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
|
1328 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1329 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
|
1330 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
|
1331 |
33326
4e531adb3fac
patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents:
33297
diff
changeset
|
1332 ufunc_T *nf = define_function(&fea, NULL, &lines_to_free, CF_CLASS, |
4e531adb3fac
patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents:
33297
diff
changeset
|
1333 cl->class_obj_members, cl->class_obj_member_count); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1334 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1335 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
|
1336 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
|
1337 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1338 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
|
1339 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1340 ((ufunc_T **)classfunctions_gap->ga_data)[classfunctions_gap->ga_len] |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1341 = nf; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1342 ++classfunctions_gap->ga_len; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1343 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1344 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
|
1345 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
|
1346 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
|
1347 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1348 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
|
1349 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
|
1350 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
|
1351 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
|
1352 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1353 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1354 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1355 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1356 /* |
33268
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1357 * Add the class methods and object methods to the new class "cl". |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1358 * When extending a class "extends_cl", add the instance methods from the |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1359 * parent class also. |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1360 * Returns OK on success and FAIL on memory allocation failure. |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1361 */ |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1362 static int |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1363 add_classfuncs_objmethods( |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1364 class_T *cl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1365 class_T *extends_cl, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1366 garray_T *classfunctions_gap, |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1367 garray_T *objmethods_gap) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1368 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1369 // 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
|
1370 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
|
1371 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1372 garray_T *gap = loop == 1 ? classfunctions_gap : objmethods_gap; |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1373 int *fcount = loop == 1 ? &cl->class_class_function_count |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1374 : &cl->class_obj_method_count; |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1375 ufunc_T ***fup = loop == 1 ? &cl->class_class_functions |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1376 : &cl->class_obj_methods; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1377 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1378 int parent_count = 0; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1379 if (extends_cl != NULL) |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
1380 // Include object methods from the parent. |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
1381 // Don't include the parent class methods. |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1382 parent_count = loop == 1 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
1383 ? 0 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1384 : 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
|
1385 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1386 *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
|
1387 if (*fcount == 0) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1388 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1389 *fup = NULL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1390 continue; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1391 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1392 *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
|
1393 if (*fup == NULL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1394 return FAIL; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1395 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1396 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
|
1397 mch_memmove(*fup, gap->ga_data, sizeof(ufunc_T *) * gap->ga_len); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1398 VIM_CLEAR(gap->ga_data); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1399 if (loop == 1) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1400 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
|
1401 else |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1402 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
|
1403 |
33268
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1404 if (loop == 2) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1405 { |
33268
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1406 // Copy instance methods from the parent. |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1407 |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1408 for (int i = 0; i < parent_count; ++i) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1409 { |
33268
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1410 // Can't use the same parent function, because "uf_class" is |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1411 // different and compilation will have a different result. |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1412 // Put them after the functions in the current class, object |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1413 // methods may be overruled, then "super.Method()" is used to |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1414 // find a method from the parent. |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1415 ufunc_T *pf = (extends_cl->class_obj_methods)[i]; |
e231b9af0f44
patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents:
33260
diff
changeset
|
1416 (*fup)[gap->ga_len + i] = copy_function(pf); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1417 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1418 // 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
|
1419 // 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
|
1420 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
|
1421 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
|
1422 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1423 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
|
1424 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
|
1425 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
|
1426 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1427 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
|
1428 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
|
1429 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
|
1430 (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
|
1431 TRUE, where); |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1432 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1433 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1434 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1435 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1436 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1437 // 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
|
1438 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
|
1439 { |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1440 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
|
1441 fp->uf_class = cl; |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
1442 if (i < gap->ga_len) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
1443 fp->uf_defclass = cl; |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1444 if (loop == 2) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1445 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
|
1446 } |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1447 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1448 ga_clear(gap); |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1449 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1450 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1451 return OK; |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1452 } |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1453 |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
1454 /* |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1455 * Update the index of object methods called by builtin functions. |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1456 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1457 static void |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1458 update_builtin_method_index(class_T *cl) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1459 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1460 int i; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1461 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1462 for (i = 0; i < CLASS_BUILTIN_MAX; i++) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1463 cl->class_builtin_methods[i] = -1; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1464 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1465 for (i = 0; i < cl->class_obj_method_count; i++) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1466 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1467 ufunc_T *uf = cl->class_obj_methods[i]; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1468 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1469 if (cl->class_builtin_methods[CLASS_BUILTIN_STRING] == -1 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1470 && STRCMP(uf->uf_name, "string") == 0) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1471 cl->class_builtin_methods[CLASS_BUILTIN_STRING] = i; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1472 else if (cl->class_builtin_methods[CLASS_BUILTIN_EMPTY] == -1 && |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1473 STRCMP(uf->uf_name, "empty") == 0) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1474 cl->class_builtin_methods[CLASS_BUILTIN_EMPTY] = i; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1475 else if (cl->class_builtin_methods[CLASS_BUILTIN_LEN] == -1 && |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1476 STRCMP(uf->uf_name, "len") == 0) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1477 cl->class_builtin_methods[CLASS_BUILTIN_LEN] = i; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1478 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1479 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1480 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
1481 /* |
33929
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1482 * Return the end of the class name starting at "arg". Valid characters in a |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1483 * class name are alphanumeric characters and "_". Also handles imported class |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1484 * names. |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1485 */ |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1486 static char_u * |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1487 find_class_name_end(char_u *arg) |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1488 { |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1489 char_u *end = arg; |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1490 |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1491 while (ASCII_ISALNUM(*end) || *end == '_' |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1492 || (*end == '.' && (ASCII_ISALNUM(end[1]) || end[1] == '_'))) |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1493 ++end; |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1494 |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1495 return end; |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1496 } |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1497 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1498 /* |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1499 * Returns TRUE if the enum value "varname" is already defined. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1500 */ |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1501 static int |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1502 is_duplicate_enum( |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1503 garray_T *enum_gap, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1504 char_u *varname, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1505 char_u *varname_end) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1506 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1507 char_u *name = vim_strnsave(varname, varname_end - varname); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1508 int dup = FALSE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1509 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1510 for (int i = 0; i < enum_gap->ga_len; ++i) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1511 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1512 ocmember_T *m = ((ocmember_T *)enum_gap->ga_data) + i; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1513 if (STRCMP(name, m->ocm_name) == 0) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1514 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1515 semsg(_(e_duplicate_enum_str), name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1516 dup = TRUE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1517 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1518 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1519 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1520 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1521 vim_free(name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1522 return dup; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1523 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1524 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1525 /* |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1526 * Parse the enum values in "line" separated by comma and add them to "gap". |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1527 * If the last enum value is found, then "enum_end" is set to TRUE. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1528 */ |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1529 static int |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1530 enum_parse_values( |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1531 exarg_T *eap, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1532 class_T *en, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1533 char_u *line, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1534 garray_T *gap, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1535 int *num_enum_values, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1536 int *enum_end) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1537 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1538 evalarg_T evalarg; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1539 char_u *p = line; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1540 char initexpr_buf[1024]; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1541 char_u last_char = NUL; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1542 int rc = OK; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1543 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1544 fill_evalarg_from_eap(&evalarg, eap, FALSE); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1545 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1546 int did_emsg_before = did_emsg; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1547 while (*p != NUL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1548 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1549 // ignore comment |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1550 if (*p == '#') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1551 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1552 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1553 if (!eval_isnamec1(*p)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1554 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1555 semsg(_(e_invalid_enum_value_declaration_str), p); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1556 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1557 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1558 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1559 char_u *eni_name_start = p; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1560 char_u *eni_name_end = to_name_end(p, FALSE); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1561 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1562 if (is_duplicate_enum(gap, eni_name_start, eni_name_end)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1563 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1564 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1565 p = skipwhite(eni_name_end); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1566 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1567 char_u *init_expr = NULL; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1568 if (*p == '(') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1569 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1570 if (VIM_ISWHITE(p[-1])) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1571 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1572 semsg(_(e_no_white_space_allowed_before_str_str), "(", line); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1573 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1574 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1575 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1576 char_u *expr_start, *expr_end; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1577 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1578 p = eni_name_start; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1579 (void)skip_expr_concatenate(&p, &expr_start, &expr_end, &evalarg); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1580 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1581 while (*expr_start && *expr_start != '(') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1582 expr_start++; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1583 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1584 if (expr_end > expr_start) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1585 init_expr = vim_strnsave(expr_start, expr_end - expr_start); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1586 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1587 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1588 if (init_expr == NULL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1589 vim_snprintf(initexpr_buf, sizeof(initexpr_buf), "%s.new()", |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1590 en->class_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1591 else |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1592 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1593 vim_snprintf(initexpr_buf, sizeof(initexpr_buf), "%s.new%s", |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1594 en->class_name, init_expr); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1595 vim_free(init_expr); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1596 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1597 if (add_member(gap, eni_name_start, eni_name_end, FALSE, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1598 TRUE, TRUE, TRUE, &en->class_object_type, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1599 vim_strsave((char_u *)initexpr_buf)) == FAIL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1600 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1601 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1602 ++*num_enum_values; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1603 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1604 if (*p != '#') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1605 last_char = *p; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1606 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1607 if (*p != NUL && *p != ',') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1608 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1609 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1610 if (*p == ',') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1611 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1612 if (!IS_WHITE_OR_NUL(p[1])) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1613 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1614 semsg(_(e_white_space_required_after_str_str), ",", line); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1615 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1616 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1617 if (VIM_ISWHITE(p[-1])) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1618 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1619 semsg(_(e_no_white_space_allowed_before_str_str), ",", line); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1620 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1621 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1622 p = skipwhite(p + 1); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1623 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1624 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1625 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1626 if (*p != NUL && *p != '#') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1627 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1628 if (did_emsg == did_emsg_before) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1629 semsg(_(e_missing_comma_before_argument_str), p); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1630 rc = FAIL; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1631 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1632 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1633 if (last_char != ',') |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1634 // last enum value should not be terminated by "," |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1635 *enum_end = TRUE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1636 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1637 // Free the memory pointed by expr_start. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1638 clear_evalarg(&evalarg, NULL); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1639 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1640 return rc; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1641 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1642 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1643 /* |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1644 * Add the "values" class variable (List of enum value objects) to the enum |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1645 * class "en" |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1646 */ |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1647 static int |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1648 enum_add_values_member( |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1649 class_T *en, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1650 garray_T *gap, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1651 int num_enum_values, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1652 garray_T *type_list_gap) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1653 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1654 garray_T fga; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1655 int rc = FAIL; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1656 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1657 ga_init2(&fga, 1, 1000); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1658 ga_concat(&fga, (char_u *)"["); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1659 for (int i = 0; i < num_enum_values; ++i) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1660 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1661 ocmember_T *m = ((ocmember_T *)gap->ga_data) + i; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1662 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1663 if (i > 0) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1664 ga_concat(&fga, (char_u *)", "); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1665 ga_concat(&fga, en->class_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1666 ga_concat(&fga, (char_u *)"."); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1667 ga_concat(&fga, (char_u *)m->ocm_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1668 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1669 ga_concat(&fga, (char_u *)"]"); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1670 ga_append(&fga, NUL); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1671 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1672 char_u *varname = (char_u *)"values"; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1673 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1674 type_T *type = get_type_ptr(type_list_gap); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1675 if (type == NULL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1676 goto done; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1677 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1678 type->tt_type = VAR_LIST; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1679 type->tt_member = get_type_ptr(type_list_gap); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1680 if (type->tt_member != NULL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1681 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1682 type->tt_member->tt_type = VAR_OBJECT; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1683 type->tt_member->tt_class = en; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1684 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1685 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1686 rc = add_member(gap, varname, varname + 6, FALSE, FALSE, TRUE, TRUE, type, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1687 vim_strsave((char_u *)fga.ga_data)); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1688 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1689 done: |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1690 vim_free(fga.ga_data); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1691 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1692 return rc; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1693 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1694 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1695 /* |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1696 * Clear the constructor method names in a enum class, so that an enum class |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1697 * cannot be instantiated. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1698 */ |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1699 static void |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1700 enum_clear_constructors(class_T *en) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1701 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1702 for (int i = 0; i < en->class_class_function_count; ++i) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1703 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1704 ufunc_T *fp = en->class_class_functions[i]; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1705 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1706 if (fp->uf_flags & FC_NEW) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1707 *fp->uf_name = NUL; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1708 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1709 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1710 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1711 /* |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1712 * Initialize the name and ordinal object variable in the enum value "enval" in |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1713 * the enum "en". These values are set during the enum value object creation. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1714 */ |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1715 void |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1716 enum_set_internal_obj_vars(class_T *en, object_T *enval) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1717 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1718 int i; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1719 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1720 for (i = 0; i < en->class_class_member_count; ++i) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1721 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1722 typval_T *en_tv = en->class_members_tv + i; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1723 if (en_tv != NULL && en_tv->v_type == VAR_UNKNOWN) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1724 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1725 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1726 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1727 // First object variable is the name |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1728 ocmember_T *value_ocm = en->class_class_members + i; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1729 typval_T *name_tv = (typval_T *)(enval + 1); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1730 name_tv->v_type = VAR_STRING; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1731 name_tv->vval.v_string = vim_strsave(value_ocm->ocm_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1732 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1733 // Second object variable is the ordinal |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1734 typval_T *ord_tv = (typval_T *)(name_tv + 1); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1735 ord_tv->v_type = VAR_NUMBER; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1736 ord_tv->vval.v_number = i; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1737 } |
33929
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1738 |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1739 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1740 * Handle ":class" and ":abstract class" up to ":endclass". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1741 * Handle ":interface" up to ":endinterface". |
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 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1744 ex_class(exarg_T *eap) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1745 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1746 int is_class = eap->cmdidx == CMD_class; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1747 int is_abstract = eap->cmdidx == CMD_abstract; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1748 int is_enum = eap->cmdidx == CMD_enum; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1749 int is_interface; |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1750 long start_lnum = SOURCING_LNUM; |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
1751 char_u *arg = eap->arg; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1752 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1753 if (is_abstract) |
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 if (STRNCMP(arg, "class", 5) != 0 || !VIM_ISWHITE(arg[5])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1756 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1757 semsg(_(e_invalid_argument_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1758 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1759 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1760 arg = skipwhite(arg + 5); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1761 is_class = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1762 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1763 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1764 is_interface = !is_class && !is_enum; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1765 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1766 if (!current_script_is_vim9() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1767 || (cmdmod.cmod_flags & CMOD_LEGACY) |
33988
7c30841c60a0
patch 9.0.2180: POSIX function name in exarg causes issues
Christian Brabandt <cb@256bit.org>
parents:
33951
diff
changeset
|
1768 || !getline_equal(eap->ea_getline, eap->cookie, getsourceline)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1769 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1770 if (is_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1771 emsg(_(e_class_can_only_be_defined_in_vim9_script)); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1772 else if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1773 emsg(_(e_enum_can_only_be_defined_in_vim9_script)); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1774 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1775 emsg(_(e_interface_can_only_be_defined_in_vim9_script)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1776 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1777 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1778 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1779 if (!ASCII_ISUPPER(*arg)) |
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 if (is_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1782 semsg(_(e_class_name_must_start_with_uppercase_letter_str), arg); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1783 else if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1784 semsg(_(e_enum_name_must_start_with_uppercase_letter_str), arg); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1785 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1786 semsg(_(e_interface_name_must_start_with_uppercase_letter_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1787 arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1788 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1789 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1790 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
|
1791 if (!IS_WHITE_OR_NUL(*name_end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1792 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1793 semsg(_(e_white_space_required_after_name_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1794 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1795 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1796 char_u *name_start = arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1797 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1798 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1799 // generics: <Tkey, Tentry> |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1800 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1801 // Name for "extends BaseClass" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1802 char_u *extends = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1803 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1804 // Names for "implements SomeInterface" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1805 garray_T ga_impl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1806 ga_init2(&ga_impl, sizeof(char_u *), 5); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1807 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1808 arg = skipwhite(name_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1809 while (*arg != NUL && *arg != '#' && *arg != '\n') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1810 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1811 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1812 // specifies SomeInterface |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1813 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
|
1814 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1815 if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1816 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1817 emsg(_(e_enum_cannot_extend_class)); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1818 goto early_ret; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1819 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1820 if (extends != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1821 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1822 emsg(_(e_duplicate_extends)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1823 goto early_ret; |
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 arg = skipwhite(arg + 7); |
33929
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1826 |
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1827 char_u *end = find_class_name_end(arg); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1828 if (!IS_WHITE_OR_NUL(*end)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1829 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1830 semsg(_(e_white_space_required_after_name_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1831 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1832 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1833 extends = vim_strnsave(arg, end - arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1834 if (extends == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1835 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1836 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1837 arg = skipwhite(end + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1838 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1839 else if (STRNCMP(arg, "implements", 10) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1840 && IS_WHITE_OR_NUL(arg[10])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1841 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1842 if (is_interface) |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1843 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1844 emsg(_(e_interface_cannot_use_implements)); |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1845 goto early_ret; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1846 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
1847 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1848 if (ga_impl.ga_len > 0) |
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 emsg(_(e_duplicate_implements)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1851 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1852 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1853 arg = skipwhite(arg + 10); |
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 (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1856 { |
33929
34c5f47e98ba
patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
1857 char_u *impl_end = find_class_name_end(arg); |
33372
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1858 if ((!IS_WHITE_OR_NUL(*impl_end) && *impl_end != ',') |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1859 || (*impl_end == ',' |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1860 && !IS_WHITE_OR_NUL(*(impl_end + 1)))) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1861 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1862 semsg(_(e_white_space_required_after_name_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1863 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1864 } |
33372
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1865 if (impl_end - arg == 0) |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1866 { |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1867 emsg(_(e_missing_name_after_implements)); |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1868 goto early_ret; |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1869 } |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
1870 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1871 char_u *iname = vim_strnsave(arg, impl_end - arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1872 if (iname == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1873 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1874 for (int i = 0; i < ga_impl.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1875 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
|
1876 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1877 semsg(_(e_duplicate_interface_after_implements_str), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1878 iname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1879 vim_free(iname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1880 goto early_ret; |
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 if (ga_add_string(&ga_impl, iname) == FAIL) |
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 vim_free(iname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1885 goto early_ret; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1886 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1887 if (*impl_end != ',') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1888 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1889 arg = skipwhite(impl_end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1890 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1891 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1892 arg = skipwhite(impl_end + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1893 } |
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 else |
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 semsg(_(e_trailing_characters_str), arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1898 early_ret: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1899 vim_free(extends); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1900 ga_clear_strings(&ga_impl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1901 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1902 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1903 } |
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 garray_T type_list; // list of pointers to allocated types |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1906 ga_init2(&type_list, sizeof(type_T *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1907 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1908 // Growarray with class members declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1909 garray_T classmembers; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1910 ga_init2(&classmembers, sizeof(ocmember_T), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1911 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1912 // Growarray with functions declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1913 garray_T classfunctions; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1914 ga_init2(&classfunctions, sizeof(ufunc_T *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1915 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1916 // Growarray with object members declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1917 garray_T objmembers; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1918 ga_init2(&objmembers, sizeof(ocmember_T), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1919 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1920 // Growarray with object methods declared in the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1921 garray_T objmethods; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1922 ga_init2(&objmethods, sizeof(ufunc_T *), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1923 |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1924 class_T *cl = NULL; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1925 class_T *extends_cl = NULL; // class from "extends" argument |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1926 class_T **intf_classes = NULL; |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1927 int num_enum_values = 0; |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1928 |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1929 cl = ALLOC_CLEAR_ONE(class_T); |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1930 if (cl == NULL) |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1931 goto cleanup; |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1932 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1933 if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1934 cl->class_flags = CLASS_ENUM; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1935 else if (is_interface) |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1936 cl->class_flags = CLASS_INTERFACE; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1937 else if (is_abstract) |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1938 cl->class_flags = CLASS_ABSTRACT; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1939 |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1940 cl->class_refcount = 1; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1941 cl->class_name = vim_strnsave(name_start, name_end - name_start); |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1942 if (cl->class_name == NULL) |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1943 goto cleanup; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1944 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1945 cl->class_type.tt_type = VAR_CLASS; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1946 cl->class_type.tt_class = cl; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1947 cl->class_object_type.tt_type = VAR_OBJECT; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1948 cl->class_object_type.tt_class = cl; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1949 |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1950 // Add the class to the script-local variables. |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1951 // TODO: handle other context, e.g. in a function |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1952 // TODO: does uf_hash need to be cleared? |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1953 typval_T tv; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1954 tv.v_type = VAR_CLASS; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1955 tv.vval.v_class = cl; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1956 SOURCING_LNUM = start_lnum; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1957 int rc = set_var_const(cl->class_name, current_sctx.sc_sid, |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1958 NULL, &tv, FALSE, 0, 0); |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1959 if (rc == FAIL) |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1960 goto cleanup; |
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
1961 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1962 if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1963 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1964 // All the enum classes have the name and ordinal object variables. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1965 char_u *varname = (char_u *)"name"; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1966 if (add_member(&objmembers, varname, varname + 4, FALSE, FALSE, TRUE, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1967 TRUE, &t_string, NULL) == FAIL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1968 goto cleanup; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1969 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1970 varname = (char_u *)"ordinal"; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1971 if (add_member(&objmembers, varname, varname + 7, FALSE, FALSE, TRUE, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1972 TRUE, &t_number, NULL) == FAIL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1973 goto cleanup; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1974 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1975 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1976 // "export class" gets used when creating the class, don't use "is_export" |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1977 // for the items inside the class. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1978 is_export = FALSE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1979 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1980 // When parsing an enum definition, this denotes whether all the enumerated |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1981 // values are parsed or not. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1982 int enum_end = FALSE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1983 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1984 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1985 * Go over the body of the class/interface until "endclass" or |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
1986 * "endinterface" or "endenum" is found. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1987 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1988 char_u *theline = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1989 int success = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1990 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1991 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1992 vim_free(theline); |
33988
7c30841c60a0
patch 9.0.2180: POSIX function name in exarg causes issues
Christian Brabandt <cb@256bit.org>
parents:
33951
diff
changeset
|
1993 theline = eap->ea_getline(':', eap->cookie, 0, GETLINE_CONCAT_ALL); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1994 if (theline == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1995 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1996 char_u *line = skipwhite(theline); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1997 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1998 // Skip empty and comment lines. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1999 if (*line == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2000 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2001 if (*line == '#') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2002 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2003 if (vim9_bad_comment(line)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2004 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2005 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2006 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2007 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2008 char_u *p = line; |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2009 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2010 char *end_name; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2011 int shortlen; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2012 int fullen; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2013 if (is_class) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2014 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2015 end_name = "endclass"; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2016 shortlen = 4; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2017 fullen = 8; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2018 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2019 else if (is_enum) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2020 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2021 end_name = "endenum"; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2022 shortlen = 4; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2023 fullen = 7; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2024 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2025 else |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2026 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2027 end_name = "endinterface"; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2028 shortlen = 5; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2029 fullen = 12; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2030 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2031 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2032 if (checkforcmd(&p, end_name, shortlen)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2033 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2034 if (STRNCMP(line, end_name, fullen) != 0) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2035 semsg(_(e_command_cannot_be_shortened_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2036 else if (*p == '|' || !ends_excmd2(line, p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2037 semsg(_(e_trailing_characters_str), p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2038 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2039 success = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2040 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2041 } |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2042 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2043 int wrong_endname = FALSE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2044 if (is_class) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2045 wrong_endname = checkforcmd(&p, "endinterface", 5) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2046 || checkforcmd(&p, "endenum", 4); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2047 else if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2048 wrong_endname = checkforcmd(&p, "endclass", 4) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2049 || checkforcmd(&p, "endinterface", 5); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2050 else |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2051 wrong_endname = checkforcmd(&p, "endclass", 4) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2052 || checkforcmd(&p, "endenum", 4); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2053 if (wrong_endname) |
32670
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 semsg(_(e_invalid_command_str_expected_str), line, end_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2056 break; |
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 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2059 if (is_enum && !enum_end) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2060 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2061 // In an enum, all the enumerated values are at the beginning |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2062 // separated by comma. The class and object variables/methods |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2063 // follow the values. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2064 if (enum_parse_values(eap, cl, line, &classmembers, |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2065 &num_enum_values, &enum_end) == FAIL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2066 break; |
34690
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2067 |
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2068 if (enum_end) |
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2069 // Add the enum "values" class variable. |
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2070 enum_add_values_member(cl, &classmembers, num_enum_values, |
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2071 &type_list); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2072 continue; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2073 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2074 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2075 int has_public = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2076 if (checkforcmd(&p, "public", 3)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2077 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2078 if (STRNCMP(line, "public", 6) != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2079 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2080 semsg(_(e_command_cannot_be_shortened_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2081 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2082 } |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2083 if (is_interface) |
33372
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2084 { |
33385
b5ad84fdc702
patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents:
33381
diff
changeset
|
2085 emsg(_(e_public_variable_not_supported_in_interface)); |
33372
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2086 break; |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2087 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2088 has_public = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2089 p = skipwhite(line + 6); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2090 |
34907
8c9e43278b2c
patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents:
34834
diff
changeset
|
2091 if (STRNCMP(p, "def", 3) == 0) |
8c9e43278b2c
patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents:
34834
diff
changeset
|
2092 { |
8c9e43278b2c
patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents:
34834
diff
changeset
|
2093 emsg(_(e_public_keyword_not_supported_for_method)); |
8c9e43278b2c
patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents:
34834
diff
changeset
|
2094 break; |
8c9e43278b2c
patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents:
34834
diff
changeset
|
2095 } |
8c9e43278b2c
patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents:
34834
diff
changeset
|
2096 |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2097 if (STRNCMP(p, "var", 3) != 0 && STRNCMP(p, "static", 6) != 0 |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2098 && STRNCMP(p, "final", 5) != 0 && STRNCMP(p, "const", 5) != 0) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2099 { |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2100 emsg(_(e_public_must_be_followed_by_var_static_final_or_const)); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2101 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2102 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2103 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2104 |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2105 int abstract_method = FALSE; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2106 char_u *pa = p; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2107 if (checkforcmd(&p, "abstract", 3)) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2108 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2109 if (STRNCMP(pa, "abstract", 8) != 0) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2110 { |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2111 semsg(_(e_command_cannot_be_shortened_str), pa); |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2112 break; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2113 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2114 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2115 if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2116 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2117 // "abstract" not supported in an enum |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2118 emsg(_(e_abstract_cannot_be_used_in_enum)); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2119 break; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2120 } |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2121 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2122 if (is_interface) |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2123 { |
33700
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2124 // "abstract" not supported in an interface |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2125 emsg(_(e_abstract_cannot_be_used_in_interface)); |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2126 break; |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2127 } |
33700
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2128 |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2129 if (!is_abstract) |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2130 { |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2131 semsg(_(e_abstract_method_in_concrete_class), pa); |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2132 break; |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2133 } |
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2134 |
33708
b076a133faf9
patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents:
33704
diff
changeset
|
2135 p = skipwhite(pa + 8); |
b076a133faf9
patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents:
33704
diff
changeset
|
2136 if (STRNCMP(p, "def", 3) != 0) |
b076a133faf9
patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents:
33704
diff
changeset
|
2137 { |
b076a133faf9
patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents:
33704
diff
changeset
|
2138 emsg(_(e_abstract_must_be_followed_by_def)); |
b076a133faf9
patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents:
33704
diff
changeset
|
2139 break; |
b076a133faf9
patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents:
33704
diff
changeset
|
2140 } |
b076a133faf9
patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents:
33704
diff
changeset
|
2141 |
33700
275617cdd99f
patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents:
33698
diff
changeset
|
2142 abstract_method = TRUE; |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2143 } |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2144 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2145 int has_static = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2146 char_u *ps = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2147 if (checkforcmd(&p, "static", 4)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2148 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2149 if (STRNCMP(ps, "static", 6) != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2150 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2151 semsg(_(e_command_cannot_be_shortened_str), ps); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2152 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2153 } |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2154 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2155 if (is_interface) |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2156 { |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33278
diff
changeset
|
2157 emsg(_(e_static_member_not_supported_in_interface)); |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2158 break; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2159 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2160 has_static = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2161 p = skipwhite(ps + 6); |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2162 |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2163 if (STRNCMP(p, "var", 3) != 0 && STRNCMP(p, "def", 3) != 0 |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2164 && STRNCMP(p, "final", 5) != 0 && STRNCMP(p, "const", 5) != 0) |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2165 { |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2166 emsg(_(e_static_must_be_followed_by_var_def_final_or_const)); |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2167 break; |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2168 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2169 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2170 |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2171 int has_final = FALSE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2172 int has_var = FALSE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2173 int has_const = FALSE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2174 if (checkforcmd(&p, "var", 3)) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2175 has_var = TRUE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2176 else if (checkforcmd(&p, "final", 5)) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2177 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2178 if (is_interface) |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2179 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2180 emsg(_(e_final_variable_not_supported_in_interface)); |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2181 break; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2182 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2183 has_final = TRUE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2184 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2185 else if (checkforcmd(&p, "const", 5)) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2186 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2187 if (is_interface) |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2188 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2189 emsg(_(e_const_variable_not_supported_in_interface)); |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2190 break; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2191 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2192 has_const = TRUE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2193 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2194 p = skipwhite(p); |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2195 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2196 // object members (public, read access, private): |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2197 // "var _varname" |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2198 // "var varname" |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2199 // "public var varname" |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2200 // "final _varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2201 // "final varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2202 // "public final varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2203 // "const _varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2204 // "const varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2205 // "public const varname" |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2206 // class members (public, read access, private): |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2207 // "static var _varname" |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2208 // "static var varname" |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2209 // "public static var varname" |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2210 // "static final _varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2211 // "static final varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2212 // "public static final varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2213 // "static const _varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2214 // "static const varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2215 // "public static const varname" |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2216 if (has_var || has_final || has_const) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2217 { |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2218 char_u *varname = p; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2219 char_u *varname_end = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2220 type_T *type = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2221 char_u *init_expr = NULL; |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2222 int has_type = FALSE; |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2223 |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2224 if (!eval_isnamec1(*p)) |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2225 { |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2226 if (has_static) |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2227 semsg(_(e_invalid_class_variable_declaration_str), line); |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2228 else |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2229 semsg(_(e_invalid_object_variable_declaration_str), line); |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2230 break; |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2231 } |
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
2232 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2233 if (is_interface && *varname == '_') |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2234 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2235 // private variables are not supported in an interface |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33708
diff
changeset
|
2236 semsg(_(e_protected_variable_not_supported_in_interface), |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33278
diff
changeset
|
2237 varname); |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2238 break; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2239 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2240 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2241 if (parse_member(eap, line, varname, has_public, |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2242 &varname_end, &has_type, &type_list, &type, |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2243 !is_interface ? &init_expr: NULL) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2244 break; |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2245 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2246 if (is_reserved_varname(varname, varname_end) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2247 || is_duplicate_variable(&classmembers, &objmembers, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2248 varname, varname_end)) |
33047
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
2249 { |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
2250 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
|
2251 break; |
9ef43d02dd8f
patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents:
33025
diff
changeset
|
2252 } |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2253 if (add_member(has_static ? &classmembers : &objmembers, varname, |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2254 varname_end, has_public, has_final, has_const, |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
2255 has_type, type, init_expr) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2256 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2257 vim_free(init_expr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2258 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2259 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2260 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2261 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2262 // constructors: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2263 // def new() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2264 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2265 // def newOther() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2266 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2267 // object methods and class functions: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2268 // def SomeMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2269 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2270 // static def ClassFunction() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2271 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2272 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2273 // def <Tval> someMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2274 // enddef |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2275 else if (checkforcmd(&p, "def", 3)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2276 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2277 exarg_T ea; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2278 garray_T lines_to_free; |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2279 int is_new = STRNCMP(p, "new", 3) == 0; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2280 |
33372
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2281 if (has_public) |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2282 { |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2283 // "public" keyword is not supported when defining an object or |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2284 // class method |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2285 emsg(_(e_public_keyword_not_supported_for_method)); |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2286 break; |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2287 } |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2288 |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2289 if (*p == NUL) |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2290 { |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2291 // No method name following def |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2292 semsg(_(e_not_valid_command_in_class_str), line); |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2293 break; |
3e9a91624b40
patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents:
33343
diff
changeset
|
2294 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2295 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2296 if (is_interface && *p == '_') |
33996
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33988
diff
changeset
|
2297 { |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2298 // private methods are not supported in an interface |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2299 semsg(_(e_protected_method_not_supported_in_interface), p); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2300 break; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2301 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2302 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2303 if (has_static && !is_new && SAFE_islower(*p) && |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2304 is_valid_builtin_obj_methodname(p)) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2305 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2306 semsg(_(e_builtin_class_method_not_supported), p); |
33996
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33988
diff
changeset
|
2307 break; |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33988
diff
changeset
|
2308 } |
6d33f47b71b8
patch 9.0.2182: Vim9: need a way to reserve future extension
Christian Brabandt <cb@256bit.org>
parents:
33988
diff
changeset
|
2309 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2310 CLEAR_FIELD(ea); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2311 ea.cmd = line; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2312 ea.arg = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2313 ea.cmdidx = CMD_def; |
33988
7c30841c60a0
patch 9.0.2180: POSIX function name in exarg causes issues
Christian Brabandt <cb@256bit.org>
parents:
33951
diff
changeset
|
2314 ea.ea_getline = eap->ea_getline; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2315 ea.cookie = eap->cookie; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2316 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2317 ga_init2(&lines_to_free, sizeof(char_u *), 50); |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2318 int class_flags; |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2319 if (is_interface) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2320 class_flags = CF_INTERFACE; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2321 else |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2322 class_flags = abstract_method ? CF_ABSTRACT_METHOD : CF_CLASS; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2323 ufunc_T *uf = define_function(&ea, NULL, &lines_to_free, |
33326
4e531adb3fac
patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents:
33297
diff
changeset
|
2324 class_flags, objmembers.ga_data, objmembers.ga_len); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2325 ga_clear_strings(&lines_to_free); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2326 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2327 if (uf != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2328 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2329 char_u *name = uf->uf_name; |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2330 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2331 if (is_new && !is_valid_constructor(uf, is_abstract, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2332 has_static)) |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2333 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2334 // private variables are not supported in an interface |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33708
diff
changeset
|
2335 semsg(_(e_protected_method_not_supported_in_interface), |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33278
diff
changeset
|
2336 name); |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2337 func_clear_free(uf, FALSE); |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2338 break; |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2339 } |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2340 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2341 // check for builtin method |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2342 if (!is_new && SAFE_islower(*name) && |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2343 !object_check_builtin_method_sig(uf)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2344 { |
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
|
2345 func_clear_free(uf, FALSE); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2346 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2347 } |
33068
d42927c6e556
patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents:
33047
diff
changeset
|
2348 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2349 // Check the name isn't used already. |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2350 if (is_duplicate_method(&classfunctions, &objmethods, 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
|
2351 { |
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
2352 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
|
2353 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
|
2354 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
|
2355 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2356 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2357 garray_T *fgap = has_static || is_new |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2358 ? &classfunctions : &objmethods; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2359 if (ga_grow(fgap, 1) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2360 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2361 if (is_new) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2362 uf->uf_flags |= FC_NEW; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2363 |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2364 if (abstract_method) |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2365 uf->uf_flags |= FC_ABSTRACT; |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2366 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2367 ((ufunc_T **)fgap->ga_data)[fgap->ga_len] = uf; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2368 ++fgap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2369 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2370 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2371 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2372 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2373 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2374 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2375 if (is_class) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2376 semsg(_(e_not_valid_command_in_class_str), line); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2377 else if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2378 semsg(_(e_not_valid_command_in_enum_str), line); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2379 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2380 semsg(_(e_not_valid_command_in_interface_str), line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2381 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2382 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2383 } |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2384 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2385 if (theline == NULL && !success && is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2386 emsg(_(e_missing_endenum)); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2387 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2388 vim_free(theline); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2389 |
34690
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2390 if (success && is_enum && num_enum_values == 0) |
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2391 // Empty enum statement. Add an empty "values" class variable |
ad86d59d7510
patch 9.1.0226: Not able to assign enum values to an enum static variable
Christian Brabandt <cb@256bit.org>
parents:
34678
diff
changeset
|
2392 enum_add_values_member(cl, &classmembers, 0, &type_list); |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2393 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2394 /* |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2395 * Check a few things |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2396 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2397 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2398 // Check the "extends" class is valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2399 if (success && extends != NULL) |
34508
d7b7fa7edb3b
patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents:
34472
diff
changeset
|
2400 success = validate_extends_class(cl, extends, &extends_cl, is_class); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2401 VIM_CLEAR(extends); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2402 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2403 // Check the new object methods to make sure their access (public or |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2404 // private) is the same as that in the extended class lineage. |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
2405 if (success && extends_cl != NULL) |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2406 success = validate_extends_methods(&objmethods, extends_cl); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2407 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2408 // Check the new class and object variables are not duplicates of the |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2409 // variables in the extended class lineage. If an interface is extending |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2410 // another interface, then it can duplicate the member variables. |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2411 if (success && extends_cl != NULL) |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2412 { |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2413 if (is_class) |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2414 success = extends_check_dup_members(&objmembers, extends_cl); |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2415 else |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2416 success = extends_check_intf_var_type(&objmembers, extends_cl); |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
2417 } |
33070
8362975375a4
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents:
33068
diff
changeset
|
2418 |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2419 // When extending an abstract class, make sure all the abstract methods in |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2420 // the parent class are implemented. If the current class is an abstract |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2421 // class, then there is no need for this check. |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2422 if (success && !is_abstract && extends_cl != NULL |
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2423 && (extends_cl->class_flags & CLASS_ABSTRACT)) |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2424 success = validate_abstract_class_methods(&classfunctions, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2425 &objmethods, extends_cl); |
33217
499ba27ba0f6
patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
33211
diff
changeset
|
2426 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2427 // Check all "implements" entries are valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2428 if (success && ga_impl.ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2429 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2430 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
|
2431 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
2432 success = validate_implements_classes(&ga_impl, intf_classes, |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2433 &objmethods, &objmembers, extends_cl); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2434 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2435 |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
2436 // 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
|
2437 if (success) |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
2438 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
|
2439 &classmembers); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2440 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2441 if (success) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2442 { |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2443 // "endclass" or "endinterface" or "endenum" encountered without any |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2444 // failures |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2445 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2446 if (extends_cl != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2447 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2448 cl->class_extends = extends_cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2449 extends_cl->class_flags |= CLASS_EXTENDED; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2450 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2451 |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2452 // Add class and object variables to "cl". |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2453 if (add_members_to_class(&classmembers, |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2454 NULL, |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
2455 0, |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2456 &cl->class_class_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2457 &cl->class_class_member_count) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2458 || add_members_to_class(&objmembers, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2459 extends_cl == NULL ? NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2460 : extends_cl->class_obj_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2461 extends_cl == NULL ? 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2462 : extends_cl->class_obj_member_count, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2463 &cl->class_obj_members, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2464 &cl->class_obj_member_count) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2465 goto cleanup; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2466 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2467 if (ga_impl.ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2468 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2469 // Move the "implements" names into the class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2470 cl->class_interface_count = ga_impl.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2471 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
|
2472 if (cl->class_interfaces == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2473 goto cleanup; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2474 for (int i = 0; i < ga_impl.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2475 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
|
2476 VIM_CLEAR(ga_impl.ga_data); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2477 ga_impl.ga_len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2478 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2479 cl->class_interfaces_cl = intf_classes; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2480 intf_classes = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2481 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2482 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2483 if (cl->class_interface_count > 0 || extends_cl != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2484 { |
32896
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
2485 // 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
|
2486 // classes. |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
2487 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
|
2488 goto cleanup; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2489 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2490 |
32903
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
2491 int have_new = FALSE; |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
2492 ufunc_T *class_func = NULL; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2493 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
|
2494 { |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
2495 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
|
2496 if (STRCMP(class_func->uf_name, "new") == 0) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2497 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2498 have_new = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2499 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2500 } |
32903
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
2501 } |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
2502 |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
2503 if (have_new) |
54c01bb98b8e
patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents:
32896
diff
changeset
|
2504 // 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
|
2505 class_func->uf_ret_type->tt_class = cl; |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2506 else if ((is_class || is_enum) && !is_abstract && !have_new) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2507 // 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
|
2508 add_default_constructor(cl, &classfunctions, &type_list); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2509 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2510 // 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
|
2511 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
|
2512 &objmethods) == FAIL) |
223765c87ea9
patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents:
32874
diff
changeset
|
2513 goto cleanup; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2514 |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2515 update_builtin_method_index(cl); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
2516 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2517 class_created(cl); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2518 |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2519 // Allocate a typval for each class member and initialize it. |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2520 if ((is_class || is_enum) && cl->class_class_member_count > 0) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2521 if (add_class_members(cl, eap, &type_list) == FAIL) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2522 goto cleanup; |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2523 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2524 cl->class_type_list = type_list; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2525 |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2526 if (is_enum) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2527 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2528 // clear the constructor method names, so that an enum class cannot |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2529 // be instantiated |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2530 enum_clear_constructors(cl); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
2531 } |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
2532 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2533 // TODO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2534 // - Fill hashtab with object members and methods ? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2535 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2536 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2537 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2538 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2539 cleanup: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2540 vim_free(extends); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2541 class_unref(extends_cl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2542 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2543 if (intf_classes != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2544 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2545 for (int i = 0; i < ga_impl.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2546 class_unref(intf_classes[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2547 vim_free(intf_classes); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2548 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2549 ga_clear_strings(&ga_impl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2550 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2551 for (int round = 1; round <= 2; ++round) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2552 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2553 garray_T *gap = round == 1 ? &classmembers : &objmembers; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2554 if (gap->ga_len == 0 || gap->ga_data == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2555 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2556 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2557 for (int i = 0; i < gap->ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2558 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2559 ocmember_T *m = ((ocmember_T *)gap->ga_data) + i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2560 vim_free(m->ocm_name); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2561 vim_free(m->ocm_init); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2562 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2563 ga_clear(gap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2564 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2565 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2566 for (int i = 0; i < objmethods.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2567 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2568 ufunc_T *uf = ((ufunc_T **)objmethods.ga_data)[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2569 func_clear_free(uf, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2570 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2571 ga_clear(&objmethods); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2572 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2573 for (int i = 0; i < classfunctions.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2574 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2575 ufunc_T *uf = ((ufunc_T **)classfunctions.ga_data)[i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2576 func_clear_free(uf, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2577 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2578 ga_clear(&classfunctions); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2579 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2580 clear_type_list(&type_list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2581 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2582 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2583 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2584 * 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
|
2585 * 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
|
2586 * 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
|
2587 * class members. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2588 * 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
|
2589 * Set *p_m ocmmember_T if not NULL |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2590 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2591 type_T * |
33534
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2592 oc_member_type( |
33088
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
2593 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
|
2594 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
|
2595 char_u *name, |
667a17904f64
patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents:
33070
diff
changeset
|
2596 char_u *name_end, |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33278
diff
changeset
|
2597 int *member_idx) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2598 { |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2599 size_t len = name_end - name; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2600 ocmember_T *m; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2601 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2602 *member_idx = -1; // not found (yet) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2603 |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2604 m = member_lookup(cl, is_object ? VAR_OBJECT : VAR_CLASS, name, len, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2605 member_idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2606 if (m == NULL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2607 { |
33286
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33278
diff
changeset
|
2608 member_not_found_msg(cl, is_object ? VAR_OBJECT : VAR_CLASS, name, |
0c3553cfe22e
patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents:
33278
diff
changeset
|
2609 len); |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2610 return &t_any; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2611 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2612 |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2613 return m->ocm_type; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2614 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2615 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2616 /* |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2617 * Given a class or object variable index, return the variable type |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2618 */ |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2619 type_T * |
33534
c8bd88bdb630
patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents:
33506
diff
changeset
|
2620 oc_member_type_by_idx( |
33446
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2621 class_T *cl, |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2622 int is_object, |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2623 int member_idx) |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2624 { |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2625 ocmember_T *m; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2626 int member_count; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2627 |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2628 if (is_object) |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2629 { |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2630 m = cl->class_obj_members; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2631 member_count = cl->class_obj_member_count; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2632 } |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2633 else |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2634 { |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2635 m = cl->class_class_members; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2636 member_count = cl->class_class_member_count; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2637 } |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2638 |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2639 if (member_idx >= member_count) |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2640 return NULL; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2641 |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2642 return m[member_idx].ocm_type; |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2643 } |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2644 |
508dfc0c261c
patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents:
33432
diff
changeset
|
2645 /* |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2646 * Type aliases (:type) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2647 */ |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2648 |
36399
71ec10757d8e
patch 9.1.0818: some global functions are only used in single files
Christian Brabandt <cb@256bit.org>
parents:
35829
diff
changeset
|
2649 static void |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2650 typealias_free(typealias_T *ta) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2651 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2652 // ta->ta_type is freed in clear_type_list() |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2653 vim_free(ta->ta_name); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2654 vim_free(ta); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2655 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2656 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2657 void |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2658 typealias_unref(typealias_T *ta) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2659 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2660 if (ta != NULL && --ta->ta_refcount <= 0) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2661 typealias_free(ta); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2662 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2663 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2664 /* |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2665 * Handle ":type". Create an alias for a type specification. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2666 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2667 void |
35829
3e5c832bba3f
patch 9.1.0633: Compilation warnings with `-Wunused-parameter`
Christian Brabandt <cb@256bit.org>
parents:
35685
diff
changeset
|
2668 ex_type(exarg_T *eap) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2669 { |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2670 char_u *arg = eap->arg; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2671 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2672 if (!current_script_is_vim9() |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2673 || (cmdmod.cmod_flags & CMOD_LEGACY) |
33988
7c30841c60a0
patch 9.0.2180: POSIX function name in exarg causes issues
Christian Brabandt <cb@256bit.org>
parents:
33951
diff
changeset
|
2674 || !getline_equal(eap->ea_getline, eap->cookie, getsourceline)) |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2675 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2676 emsg(_(e_type_can_only_be_defined_in_vim9_script)); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2677 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2678 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2679 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2680 if (*arg == NUL) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2681 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2682 emsg(_(e_missing_typealias_name)); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2683 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2684 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2685 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2686 if (!ASCII_ISUPPER(*arg)) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2687 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2688 semsg(_(e_type_name_must_start_with_uppercase_letter_str), arg); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2689 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2690 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2691 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2692 char_u *name_end = find_name_end(arg, NULL, NULL, FNE_CHECK_START); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2693 if (!IS_WHITE_OR_NUL(*name_end)) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2694 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2695 semsg(_(e_white_space_required_after_name_str), arg); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2696 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2697 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2698 char_u *name_start = arg; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2699 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2700 arg = skipwhite(name_end); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2701 if (*arg != '=') |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2702 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2703 semsg(_(e_missing_equal_str), arg); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2704 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2705 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2706 if (!IS_WHITE_OR_NUL(*(arg + 1))) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2707 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2708 semsg(_(e_white_space_required_after_str_str), "=", arg); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2709 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2710 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2711 arg++; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2712 arg = skipwhite(arg); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2713 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2714 if (*arg == NUL) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2715 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2716 emsg(_(e_missing_typealias_type)); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2717 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2718 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2719 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2720 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2721 type_T *type = parse_type(&arg, &si->sn_type_list, TRUE); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2722 if (type == NULL) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2723 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2724 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2725 if (*arg != NUL) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2726 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2727 // some text after the type |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2728 semsg(_(e_trailing_characters_str), arg); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2729 return; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2730 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2731 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2732 int cc = *name_end; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2733 *name_end = NUL; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2734 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2735 typval_T tv; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2736 tv.v_type = VAR_UNKNOWN; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2737 if (eval_variable_import(name_start, &tv) == OK) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2738 { |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2739 if (tv.v_type == VAR_TYPEALIAS) |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2740 semsg(_(e_typealias_already_exists_for_str), name_start); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2741 else |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2742 semsg(_(e_redefining_script_item_str), name_start); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2743 clear_tv(&tv); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2744 goto done; |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2745 } |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2746 |
33682
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2747 // Create a script-local variable for the type alias. |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2748 if (type->tt_type != VAR_OBJECT) |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2749 { |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2750 tv.v_type = VAR_TYPEALIAS; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2751 tv.v_lock = 0; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2752 tv.vval.v_typealias = ALLOC_CLEAR_ONE(typealias_T); |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2753 ++tv.vval.v_typealias->ta_refcount; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2754 tv.vval.v_typealias->ta_name = vim_strsave(name_start); |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2755 tv.vval.v_typealias->ta_type = type; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2756 } |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2757 else |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2758 { |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2759 // When creating a type alias for a class, use the class type itself to |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2760 // create the type alias variable. This is needed to use the type |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2761 // alias to invoke class methods (e.g. new()) and use class variables. |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2762 tv.v_type = VAR_CLASS; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2763 tv.v_lock = 0; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2764 tv.vval.v_class = type->tt_class; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2765 ++tv.vval.v_class->class_refcount; |
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
2766 } |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2767 set_var_const(name_start, current_sctx.sc_sid, NULL, &tv, FALSE, |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2768 ASSIGN_CONST | ASSIGN_FINAL, 0); |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2769 |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2770 done: |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33636
diff
changeset
|
2771 *name_end = cc; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2772 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2773 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2774 /* |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2775 * Returns OK if a member variable named "name" is present in the class "cl". |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2776 * Otherwise returns FAIL. If found, the member variable typval is set in |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2777 * "rettv". If "is_object" is TRUE, then the object member variable table is |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2778 * searched. Otherwise the class member variable table is searched. |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2779 */ |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2780 static int |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2781 get_member_tv( |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2782 class_T *cl, |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2783 int is_object, |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2784 char_u *name, |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2785 size_t namelen, |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2786 typval_T *rettv) |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2787 { |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2788 ocmember_T *m; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2789 int m_idx; |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2790 |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2791 m = member_lookup(cl, is_object ? VAR_OBJECT : VAR_CLASS, name, namelen, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2792 &m_idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2793 if (m == NULL) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2794 return FAIL; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2795 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2796 if (*name == '_') |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2797 { |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33708
diff
changeset
|
2798 emsg_var_cl_define(e_cannot_access_protected_variable_str, |
33498
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
2799 m->ocm_name, 0, cl); |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2800 return FAIL; |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2801 } |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2802 |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2803 if (is_object) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2804 { |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2805 // The object only contains a pointer to the class, the member values |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2806 // array follows right after that. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2807 object_T *obj = rettv->vval.v_object; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2808 typval_T *tv = (typval_T *)(obj + 1) + m_idx; |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2809 copy_tv(tv, rettv); |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2810 object_unref(obj); |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2811 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2812 else |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2813 { |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2814 copy_tv(&cl->class_members_tv[m_idx], rettv); |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2815 class_unref(cl); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2816 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2817 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2818 return OK; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2819 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2820 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2821 /* |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2822 * Call an object or class method "name" in class "cl". The method return |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2823 * value is returned in "rettv". |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2824 */ |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2825 static int |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2826 call_oc_method( |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2827 class_T *cl, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2828 char_u *name, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2829 size_t len, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2830 char_u *name_end, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2831 evalarg_T *evalarg, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2832 char_u **arg, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2833 typval_T *rettv) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2834 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2835 ufunc_T *fp; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2836 typval_T argvars[MAX_FUNC_ARGS + 1]; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2837 int argcount = 0; |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2838 ocmember_T *ocm = NULL; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2839 int m_idx; |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2840 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2841 fp = method_lookup(cl, rettv->v_type, name, len, NULL); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2842 if (fp == NULL) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2843 { |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2844 // could be an object or class funcref variable |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2845 ocm = member_lookup(cl, rettv->v_type, name, len, &m_idx); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2846 if (ocm == NULL || ocm->ocm_type->tt_type != VAR_FUNC) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2847 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2848 method_not_found_msg(cl, rettv->v_type, name, len); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2849 return FAIL; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2850 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2851 |
34769
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2852 if (*name == '_') |
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2853 { |
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2854 // Protected object or class funcref variable |
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2855 semsg(_(e_cannot_access_protected_variable_str), ocm->ocm_name, |
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2856 cl->class_name); |
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2857 return FAIL; |
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2858 } |
d4fb6ea26ae4
patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents:
34709
diff
changeset
|
2859 |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2860 if (rettv->v_type == VAR_OBJECT) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2861 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2862 // funcref object variable |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2863 object_T *obj = rettv->vval.v_object; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2864 typval_T *tv = (typval_T *)(obj + 1) + m_idx; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2865 copy_tv(tv, rettv); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2866 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2867 else |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2868 // funcref class variable |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2869 copy_tv(&cl->class_members_tv[m_idx], rettv); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2870 *arg = name_end; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2871 return OK; |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2872 } |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2873 |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2874 if (ocm == NULL && *fp->uf_name == '_') |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2875 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2876 // Cannot access a private method outside of a class |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33708
diff
changeset
|
2877 semsg(_(e_cannot_access_protected_method_str), fp->uf_name); |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2878 return FAIL; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2879 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2880 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2881 char_u *argp = name_end; |
33936
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33929
diff
changeset
|
2882 int ret = get_func_arguments(&argp, evalarg, 0, argvars, &argcount, FALSE); |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2883 if (ret == FAIL) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2884 return FAIL; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2885 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2886 funcexe_T funcexe; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2887 CLEAR_FIELD(funcexe); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2888 funcexe.fe_evaluate = TRUE; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2889 if (rettv->v_type == VAR_OBJECT) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2890 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2891 funcexe.fe_object = rettv->vval.v_object; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2892 ++funcexe.fe_object->obj_refcount; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2893 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2894 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2895 // Clear the class or object after calling the function, in |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2896 // case the refcount is one. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2897 typval_T tv_tofree = *rettv; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2898 rettv->v_type = VAR_UNKNOWN; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2899 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2900 // Call the user function. Result goes into rettv; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2901 int error = call_user_func_check(fp, argcount, argvars, rettv, &funcexe, |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2902 NULL); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2903 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2904 // Clear the previous rettv and the arguments. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2905 clear_tv(&tv_tofree); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2906 for (int idx = 0; idx < argcount; ++idx) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2907 clear_tv(&argvars[idx]); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2908 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2909 if (error != FCERR_NONE) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2910 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2911 user_func_error(error, printable_func_name(fp), funcexe.fe_found_var); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2912 return FAIL; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2913 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2914 *arg = argp; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2915 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2916 return OK; |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2917 } |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2918 |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2919 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2920 * Evaluate what comes after a class: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2921 * - class member: SomeClass.varname |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2922 * - class function: SomeClass.SomeMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2923 * - class constructor: SomeClass.new() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2924 * - object member: someObject.varname |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2925 * - object method: someObject.SomeMethod() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2926 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2927 * "*arg" points to the '.'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2928 * "*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
|
2929 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2930 * Returns FAIL or OK. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2931 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2932 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2933 class_object_index( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2934 char_u **arg, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2935 typval_T *rettv, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2936 evalarg_T *evalarg, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2937 int verbose UNUSED) // give error messages |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2938 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2939 if (VIM_ISWHITE((*arg)[1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2940 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2941 semsg(_(e_no_white_space_allowed_after_str_str), ".", *arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2942 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2943 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2944 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2945 ++*arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2946 char_u *name = *arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2947 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
|
2948 if (name_end == name) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2949 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2950 size_t len = name_end - name; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2951 |
33473
156d07bea2ac
patch 9.0.1989: Vim9: double error message given
Christian Brabandt <cb@256bit.org>
parents:
33471
diff
changeset
|
2952 int did_emsg_save = did_emsg; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2953 class_T *cl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2954 if (rettv->v_type == VAR_CLASS) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2955 cl = rettv->vval.v_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2956 else // VAR_OBJECT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2957 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2958 if (rettv->vval.v_object == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2959 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2960 emsg(_(e_using_null_object)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2961 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2962 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2963 cl = rettv->vval.v_object->obj_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2964 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2965 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2966 if (cl == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2967 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2968 emsg(_(e_incomplete_type)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2969 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2970 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2971 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2972 if (*name_end == '(') |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2973 // Invoke the class or object method |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2974 return call_oc_method(cl, name, len, name_end, evalarg, arg, rettv); |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
2975 |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2976 else if (rettv->v_type == VAR_OBJECT || rettv->v_type == VAR_CLASS) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2977 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2978 // Search in the object member variable table and the class member |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2979 // variable table. |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2980 int is_object = rettv->v_type == VAR_OBJECT; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
2981 if (get_member_tv(cl, is_object, name, len, rettv) == OK) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2982 { |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2983 *arg = name_end; |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
2984 return OK; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2985 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2986 |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2987 // could be a class method or an object method |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2988 int fidx; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2989 ufunc_T *fp = method_lookup(cl, rettv->v_type, name, len, &fidx); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2990 if (fp != NULL) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2991 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2992 // Private methods are not accessible outside the class |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2993 if (*name == '_') |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2994 { |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33708
diff
changeset
|
2995 semsg(_(e_cannot_access_protected_method_str), fp->uf_name); |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2996 return FAIL; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2997 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2998 |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
2999 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3000 if (pt == NULL) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3001 return FAIL; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3002 |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3003 pt->pt_refcount = 1; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3004 if (is_object) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3005 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3006 pt->pt_obj = rettv->vval.v_object; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3007 ++pt->pt_obj->obj_refcount; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3008 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3009 pt->pt_auto = TRUE; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3010 pt->pt_func = fp; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3011 func_ptr_ref(pt->pt_func); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3012 rettv->v_type = VAR_PARTIAL; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3013 rettv->vval.v_partial = pt; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3014 *arg = name_end; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3015 return OK; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3016 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3017 |
33473
156d07bea2ac
patch 9.0.1989: Vim9: double error message given
Christian Brabandt <cb@256bit.org>
parents:
33471
diff
changeset
|
3018 if (did_emsg == did_emsg_save) |
33636
53416c49a7ab
patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents:
33627
diff
changeset
|
3019 member_not_found_msg(cl, rettv->v_type, name, len); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3020 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3021 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3022 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3023 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3024 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3025 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3026 * 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
|
3027 * Otherwise return NULL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3028 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3029 ufunc_T * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3030 find_class_func(char_u **arg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3031 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3032 char_u *name = *arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3033 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
|
3034 if (name_end == name || *name_end != '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3035 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3036 |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3037 ufunc_T *fp = NULL; |
33201
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
3038 size_t len = name_end - name; |
36c13b964eb3
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents:
33173
diff
changeset
|
3039 typval_T tv; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3040 tv.v_type = VAR_UNKNOWN; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3041 if (eval_variable(name, (int)len, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3042 0, &tv, NULL, EVAL_VAR_NOAUTOLOAD) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3043 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3044 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
|
3045 goto fail_after_eval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3046 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3047 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
|
3048 : tv.vval.v_object->obj_class; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3049 if (cl == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3050 goto fail_after_eval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3051 char_u *fname = name_end + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3052 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
|
3053 if (fname_end == fname) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3054 goto fail_after_eval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3055 len = fname_end - fname; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3056 |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3057 fp = method_lookup(cl, tv.v_type, fname, len, NULL); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3058 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3059 fail_after_eval: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3060 clear_tv(&tv); |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3061 return fp; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3062 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3063 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3064 /* |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3065 * Returns the index of class variable "name" in the class "cl". |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3066 * Returns -1, if the variable is not found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3067 * If "namelen" is zero, then it is assumed that "name" is NUL terminated. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3068 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3069 int |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3070 class_member_idx(class_T *cl, char_u *name, size_t namelen) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3071 { |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3072 int idx; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3073 class_member_lookup(cl, name, namelen, &idx); |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3074 return idx; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3075 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3076 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3077 /* |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3078 * Returns a pointer to the class member variable "name" in the class "cl". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3079 * Returns NULL if the variable is not found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3080 * The member variable index is set in "idx". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3081 */ |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3082 ocmember_T * |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3083 class_member_lookup(class_T *cl, char_u *name, size_t namelen, int *idx) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3084 { |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3085 ocmember_T *ret_m = NULL; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3086 int ret_idx = -1; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3087 for (int i = 0; i < cl->class_class_member_count; ++i) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3088 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3089 ocmember_T *m = &cl->class_class_members[i]; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3090 if (namelen) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3091 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3092 if (STRNCMP(name, m->ocm_name, namelen) == 0 |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3093 && m->ocm_name[namelen] == NUL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3094 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3095 ret_m = m; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3096 ret_idx = i; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3097 break; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3098 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3099 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3100 else if (STRCMP(name, m->ocm_name) == 0) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3101 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3102 ret_m = m; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3103 ret_idx = i; |
35685
5c89a485e597
patch 9.1.0581: Various lines are indented inconsistently
Christian Brabandt <cb@256bit.org>
parents:
35527
diff
changeset
|
3104 break; |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3105 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3106 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3107 if (idx != NULL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3108 *idx = ret_idx; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3109 return ret_m; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3110 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3111 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3112 /* |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3113 * Returns a pointer to the class method "name" in class "cl". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3114 * Returns NULL if the method is not found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3115 * The method index is set in "idx". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3116 */ |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3117 static ufunc_T * |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3118 class_method_lookup(class_T *cl, char_u *name, size_t namelen, int *idx) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3119 { |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3120 ufunc_T *ret_fp = NULL; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3121 int ret_idx = -1; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3122 for (int i = 0; i < cl->class_class_function_count; ++i) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3123 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3124 ufunc_T *fp = cl->class_class_functions[i]; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3125 char_u *ufname = (char_u *)fp->uf_name; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3126 if (STRNCMP(name, ufname, namelen) == 0 && ufname[namelen] == NUL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3127 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3128 ret_fp = fp; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3129 ret_idx = i; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3130 break; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3131 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3132 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3133 if (idx != NULL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3134 *idx = ret_idx; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3135 return ret_fp; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3136 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3137 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3138 /* |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3139 * Returns the index of class method "name" in the class "cl". |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3140 * Returns -1, if the method is not found. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3141 */ |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3142 int |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3143 class_method_idx(class_T *cl, char_u *name, size_t namelen) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3144 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3145 int idx; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3146 class_method_lookup(cl, name, namelen, &idx); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3147 return idx; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3148 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3149 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3150 /* |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3151 * Returns the index of object member variable "name" in the class "cl". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3152 * Returns -1, if the variable is not found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3153 * If "namelen" is zero, then it is assumed that "name" is NUL terminated. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3154 */ |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3155 static int |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3156 object_member_idx(class_T *cl, char_u *name, size_t namelen) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3157 { |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3158 int idx; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3159 object_member_lookup(cl, name, namelen, &idx); |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3160 return idx; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3161 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3162 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3163 /* |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3164 * Returns a pointer to the object member variable "name" in the class "cl". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3165 * Returns NULL if the variable is not found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3166 * The object member variable index is set in "idx". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3167 */ |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3168 ocmember_T * |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3169 object_member_lookup(class_T *cl, char_u *name, size_t namelen, int *idx) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3170 { |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3171 ocmember_T *ret_m = NULL; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3172 int ret_idx = -1; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3173 for (int i = 0; i < cl->class_obj_member_count; ++i) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3174 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3175 ocmember_T *m = &cl->class_obj_members[i]; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3176 if (namelen) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3177 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3178 if (STRNCMP(name, m->ocm_name, namelen) == 0 |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3179 && m->ocm_name[namelen] == NUL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3180 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3181 ret_m = m; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3182 ret_idx = i; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3183 break; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3184 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3185 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3186 else if (STRCMP(name, m->ocm_name) == 0) |
35685
5c89a485e597
patch 9.1.0581: Various lines are indented inconsistently
Christian Brabandt <cb@256bit.org>
parents:
35527
diff
changeset
|
3187 { |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3188 ret_m = m; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3189 ret_idx = i; |
35685
5c89a485e597
patch 9.1.0581: Various lines are indented inconsistently
Christian Brabandt <cb@256bit.org>
parents:
35527
diff
changeset
|
3190 break; |
5c89a485e597
patch 9.1.0581: Various lines are indented inconsistently
Christian Brabandt <cb@256bit.org>
parents:
35527
diff
changeset
|
3191 } |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3192 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3193 if (idx != NULL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3194 *idx = ret_idx; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3195 return ret_m; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3196 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3197 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3198 /* |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3199 * Returns a pointer to the object method "name" in class "cl". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3200 * Returns NULL if the method is not found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3201 * The object method index is set in "idx". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3202 */ |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3203 static ufunc_T * |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3204 object_method_lookup(class_T *cl, char_u *name, size_t namelen, int *idx) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3205 { |
33246
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3206 ufunc_T *ret_fp = NULL; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3207 int ret_idx = -1; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3208 for (int i = 0; i < cl->class_obj_method_count; ++i) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3209 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3210 ufunc_T *fp = cl->class_obj_methods[i]; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3211 // Use a separate pointer to avoid that ASAN complains about |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3212 // uf_name[] only being 4 characters. |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3213 char_u *ufname = (char_u *)fp->uf_name; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3214 if (STRNCMP(name, ufname, namelen) == 0 && ufname[namelen] == NUL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3215 { |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3216 ret_fp = fp; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3217 ret_idx = i; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3218 break; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3219 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3220 } |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3221 if (idx != NULL) |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3222 *idx = ret_idx; |
877dddec681f
patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
3223 return ret_fp; |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3224 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3225 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3226 /* |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3227 * Returns the index of object method "name" in the class "cl". |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3228 * Returns -1, if the method is not found. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3229 */ |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3230 int |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3231 object_method_idx(class_T *cl, char_u *name, size_t namelen) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3232 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3233 int idx; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3234 object_method_lookup(cl, name, namelen, &idx); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3235 return idx; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3236 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3237 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3238 /* |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3239 * Lookup a class or object member variable by name. If v_type is VAR_CLASS, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3240 * then lookup a class member variable and if it is VAR_OBJECT, then lookup a |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3241 * object member variable. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3242 * |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3243 * Returns a pointer to the member variable structure if variable is found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3244 * Otherwise returns NULL. The member variable index is set in "*idx". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3245 */ |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3246 ocmember_T * |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3247 member_lookup( |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3248 class_T *cl, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3249 vartype_T v_type, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3250 char_u *name, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3251 size_t namelen, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3252 int *idx) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3253 { |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3254 if (v_type == VAR_CLASS) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3255 return class_member_lookup(cl, name, namelen, idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3256 else |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3257 return object_member_lookup(cl, name, namelen, idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3258 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3259 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3260 /* |
33498
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3261 * Find the class that defines the named member. Look up the hierarchy |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3262 * starting at "cl". |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3263 * |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3264 * Return the class that defines the member "name", else NULL. |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3265 * Fill in "p_m", if specified, for ocmember_T in found class. |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3266 */ |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3267 // NOTE: if useful for something could also indirectly return vartype and idx. |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3268 static class_T * |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3269 class_defining_member(class_T *cl, char_u *name, size_t len, ocmember_T **p_m) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3270 { |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3271 class_T *cl_found = NULL; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3272 vartype_T vartype = VAR_UNKNOWN; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3273 ocmember_T *m_found = NULL; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3274 |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3275 len = len != 0 ? len : STRLEN(name); |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3276 |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3277 // Loop assumes if member is not defined in "cl", then it is not |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3278 // defined in any super class; the last class where it's found is the |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3279 // class where it is defined. Once the vartype is found, the other |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3280 // type is no longer checked. |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3281 for (class_T *super = cl; super != NULL; super = super->class_extends) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3282 { |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3283 class_T *cl_tmp = NULL; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3284 ocmember_T *m = NULL; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3285 if (vartype == VAR_UNKNOWN || vartype == VAR_OBJECT) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3286 { |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3287 if ((m = object_member_lookup(super, name, len, NULL)) != NULL) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3288 { |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3289 cl_tmp = super; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3290 vartype = VAR_OBJECT; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3291 } |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3292 } |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3293 if (vartype == VAR_UNKNOWN || vartype == VAR_CLASS) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3294 { |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3295 if (( m = class_member_lookup(super, name, len, NULL)) != NULL) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3296 { |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3297 cl_tmp = super; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3298 vartype = VAR_OBJECT; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3299 } |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3300 } |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3301 if (cl_tmp == NULL) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3302 break; // member is not in this or any super class. |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3303 cl_found = cl_tmp; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3304 m_found = m; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3305 } |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3306 if (p_m != NULL) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3307 *p_m = m_found; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3308 return cl_found; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3309 } |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3310 |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3311 /* |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3312 * Lookup a class or object method by name. If v_type is VAR_CLASS, then |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3313 * lookup a class method and if it is VAR_OBJECT, then lookup a object method. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3314 * |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3315 * Returns a pointer to the method structure if variable is found. |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3316 * Otherwise returns NULL. The method variable index is set in "*idx". |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3317 */ |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3318 ufunc_T * |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3319 method_lookup( |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3320 class_T *cl, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3321 vartype_T v_type, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3322 char_u *name, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3323 size_t namelen, |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3324 int *idx) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3325 { |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3326 if (v_type == VAR_CLASS) |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3327 return class_method_lookup(cl, name, namelen, idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3328 else |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3329 return object_method_lookup(cl, name, namelen, idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3330 } |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3331 |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
3332 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3333 * 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
|
3334 * Return FALSE if not. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3335 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3336 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3337 inside_class(cctx_T *cctx_arg, class_T *cl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3338 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3339 for (cctx_T *cctx = cctx_arg; cctx != NULL; cctx = cctx->ctx_outer) |
33204
36aebbf8389f
patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents:
33201
diff
changeset
|
3340 if (cctx->ctx_ufunc != NULL |
33432
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3341 && class_instance_of(cctx->ctx_ufunc->uf_class, cl)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3342 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3343 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3344 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3345 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3346 /* |
33951
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3347 * Return TRUE if object/class variable "m" is read-only. |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3348 * Also give an error message. |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3349 */ |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3350 int |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3351 oc_var_check_ro(class_T *cl, ocmember_T *m) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3352 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3353 if (m->ocm_flags & (OCMFLAG_FINAL | OCMFLAG_CONST)) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3354 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3355 semsg(_(e_cannot_change_readonly_variable_str_in_class_str), |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3356 m->ocm_name, cl->class_name); |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3357 return TRUE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3358 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3359 return FALSE; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3360 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3361 |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3362 /* |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3363 * Lock all the constant object variables. Called after creating and |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3364 * initializing a new object. |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3365 */ |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3366 void |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3367 obj_lock_const_vars(object_T *obj) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3368 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3369 for (int i = 0; i < obj->obj_class->class_obj_member_count; i++) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3370 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3371 ocmember_T *ocm = &obj->obj_class->class_obj_members[i]; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3372 if (ocm->ocm_flags & OCMFLAG_CONST) |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3373 { |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3374 typval_T *mtv = ((typval_T *)(obj + 1)) + i; |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3375 item_lock(mtv, DICT_MAXNEST, TRUE, TRUE); |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3376 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3377 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3378 } |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3379 |
45a50fd59a73
patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents:
33942
diff
changeset
|
3380 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3381 * Make a copy of an object. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3382 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3383 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3384 copy_object(typval_T *from, typval_T *to) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3385 { |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
3386 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
|
3387 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
|
3388 else |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
3389 { |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
3390 to->vval.v_object = from->vval.v_object; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3391 ++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
|
3392 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3393 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3394 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3395 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3396 * Make a copy of a class. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3397 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3398 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3399 copy_class(typval_T *from, typval_T *to) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3400 { |
32960
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
3401 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
|
3402 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
|
3403 else |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
3404 { |
d5c05e15cf81
patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents:
32903
diff
changeset
|
3405 to->vval.v_class = from->vval.v_class; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3406 ++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
|
3407 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3408 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3409 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3410 /* |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3411 * Free the class "cl" and its contents. |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3412 */ |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3413 static void |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3414 class_free(class_T *cl) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3415 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3416 // Freeing what the class contains may recursively come back here. |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3417 // Clear "class_name" first, if it is NULL the class does not need to |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3418 // be freed. |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3419 VIM_CLEAR(cl->class_name); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3420 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3421 class_unref(cl->class_extends); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3422 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3423 for (int i = 0; i < cl->class_interface_count; ++i) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3424 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3425 vim_free(((char_u **)cl->class_interfaces)[i]); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3426 if (cl->class_interfaces_cl[i] != NULL) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3427 class_unref(cl->class_interfaces_cl[i]); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3428 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3429 vim_free(cl->class_interfaces); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3430 vim_free(cl->class_interfaces_cl); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3431 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3432 itf2class_T *next; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3433 for (itf2class_T *i2c = cl->class_itf2class; i2c != NULL; i2c = next) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3434 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3435 next = i2c->i2c_next; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3436 vim_free(i2c); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3437 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3438 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3439 for (int i = 0; i < cl->class_class_member_count; ++i) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3440 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3441 ocmember_T *m = &cl->class_class_members[i]; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3442 vim_free(m->ocm_name); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3443 vim_free(m->ocm_init); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3444 if (cl->class_members_tv != NULL) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3445 clear_tv(&cl->class_members_tv[i]); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3446 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3447 vim_free(cl->class_class_members); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3448 vim_free(cl->class_members_tv); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3449 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3450 for (int i = 0; i < cl->class_obj_member_count; ++i) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3451 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3452 ocmember_T *m = &cl->class_obj_members[i]; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3453 vim_free(m->ocm_name); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3454 vim_free(m->ocm_init); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3455 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3456 vim_free(cl->class_obj_members); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3457 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3458 for (int i = 0; i < cl->class_class_function_count; ++i) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3459 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3460 ufunc_T *uf = cl->class_class_functions[i]; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3461 func_clear_free(uf, FALSE); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3462 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3463 vim_free(cl->class_class_functions); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3464 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3465 for (int i = 0; i < cl->class_obj_method_count; ++i) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3466 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3467 ufunc_T *uf = cl->class_obj_methods[i]; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3468 func_clear_free(uf, FALSE); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3469 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3470 vim_free(cl->class_obj_methods); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3471 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3472 clear_type_list(&cl->class_type_list); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3473 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3474 class_cleared(cl); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3475 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3476 vim_free(cl); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3477 } |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3478 |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3479 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3480 * 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
|
3481 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3482 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3483 class_unref(class_T *cl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3484 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3485 if (cl != NULL && --cl->class_refcount <= 0 && cl->class_name != NULL) |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3486 class_free(cl); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3487 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3488 |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3489 /* |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3490 * Go through the list of all classes and free items without "copyID". |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3491 */ |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3492 int |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3493 class_free_nonref(int copyID) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3494 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3495 int did_free = FALSE; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3496 |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3497 for (class_T *cl = first_class; cl != NULL; cl = next_nonref_class) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3498 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3499 next_nonref_class = cl->class_next_used; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3500 if ((cl->class_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3501 { |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3502 // Free the class and items it contains. |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3503 class_free(cl); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3504 did_free = TRUE; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3505 } |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3506 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3507 |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3508 next_nonref_class = NULL; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3509 return did_free; |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3510 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3511 |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3512 int |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3513 set_ref_in_classes(int copyID) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3514 { |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3515 for (class_T *cl = first_class; cl != NULL; cl = cl->class_next_used) |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3516 set_ref_in_item_class(cl, copyID, NULL, NULL); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3517 |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33119
diff
changeset
|
3518 return FALSE; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3519 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3520 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3521 static object_T *first_object = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3522 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3523 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3524 * 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
|
3525 * list headed by "first_object". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3526 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3527 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3528 object_created(object_T *obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3529 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3530 if (first_object != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3531 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3532 obj->obj_next_used = first_object; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3533 first_object->obj_prev_used = obj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3534 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3535 first_object = obj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3536 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3537 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3538 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3539 * 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
|
3540 * It is removed from the list headed by "first_object". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3541 */ |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3542 static void |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3543 object_cleared(object_T *obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3544 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3545 if (obj->obj_next_used != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3546 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
|
3547 if (obj->obj_prev_used != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3548 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
|
3549 else if (first_object == obj) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3550 first_object = obj->obj_next_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3551 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3552 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3553 /* |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3554 * Free the contents of an object ignoring the reference count. |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3555 */ |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3556 static void |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3557 object_free_contents(object_T *obj) |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3558 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3559 class_T *cl = obj->obj_class; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3560 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3561 if (!cl) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3562 return; |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3563 |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3564 // Avoid a recursive call, it can happen if "obj" has a circular reference. |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3565 obj->obj_refcount = INT_MAX; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3566 |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3567 // the member values are just after the object structure |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3568 typval_T *tv = (typval_T *)(obj + 1); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3569 for (int i = 0; i < cl->class_obj_member_count; ++i) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3570 clear_tv(tv + i); |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3571 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3572 |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3573 static void |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3574 object_free_object(object_T *obj) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3575 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3576 class_T *cl = obj->obj_class; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3577 |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3578 if (!cl) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3579 return; |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3580 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3581 // Remove from the list headed by "first_object". |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3582 object_cleared(obj); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3583 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3584 vim_free(obj); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3585 class_unref(cl); |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3586 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3587 |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3588 static void |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3589 object_free(object_T *obj) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3590 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3591 if (in_free_unref_items) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3592 return; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3593 |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3594 object_free_contents(obj); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3595 object_free_object(obj); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3596 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3597 |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3598 /* |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3599 * Unreference an object. |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3600 */ |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3601 void |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3602 object_unref(object_T *obj) |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3603 { |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3604 if (obj != NULL && --obj->obj_refcount <= 0) |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3605 object_free(obj); |
33506
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3606 } |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3607 |
f61713271934
patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents:
33498
diff
changeset
|
3608 /* |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3609 * 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
|
3610 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3611 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3612 object_free_nonref(int copyID) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3613 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3614 int did_free = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3615 |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3616 for (object_T *obj = first_object; obj != NULL; obj = obj->obj_next_used) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3617 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3618 if ((obj->obj_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3619 { |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3620 // Free the object contents. Object itself will be freed later. |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3621 object_free_contents(obj); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3622 did_free = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3623 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3624 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3625 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3626 return did_free; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3627 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3628 |
33540
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3629 void |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3630 object_free_items(int copyID) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3631 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3632 object_T *obj_next; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3633 |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3634 for (object_T *obj = first_object; obj != NULL; obj = obj_next) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3635 { |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3636 obj_next = obj->obj_next_used; |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3637 if ((obj->obj_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3638 object_free_object(obj); |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3639 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3640 } |
86dbcbb94fdb
patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents:
33534
diff
changeset
|
3641 |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3642 /* |
33498
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3643 * Output message which takes a variable name and the class that defines it. |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3644 * "cl" is that class where the name was found. Search "cl"'s hierarchy to |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3645 * find the defining class. |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3646 */ |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3647 void |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3648 emsg_var_cl_define(char *msg, char_u *name, size_t len, class_T *cl) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3649 { |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3650 ocmember_T *m; |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3651 class_T *cl_def = class_defining_member(cl, name, len, &m); |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3652 if (cl_def != NULL) |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3653 semsg(_(msg), m->ocm_name, cl_def->class_name); |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3654 else |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3655 emsg(_(e_internal_error_please_report_a_bug)); |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3656 } |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3657 |
bff8ac203a22
patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents:
33473
diff
changeset
|
3658 /* |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3659 * Echo a class or object method not found message. |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3660 */ |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3661 void |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3662 method_not_found_msg(class_T *cl, vartype_T v_type, char_u *name, size_t len) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3663 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3664 char_u *method_name = vim_strnsave(name, len); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3665 if ((v_type == VAR_OBJECT) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3666 && (class_method_idx(cl, name, len) >= 0)) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3667 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3668 // If this is a class method, then give a different error |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3669 if (*name == '_') |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33708
diff
changeset
|
3670 semsg(_(e_cannot_access_protected_method_str), method_name); |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3671 else |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
3672 semsg(_(e_class_method_str_accessible_only_using_class_str), |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3673 method_name, cl->class_name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3674 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3675 else if ((v_type == VAR_CLASS) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3676 && (object_method_idx(cl, name, len) >= 0)) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3677 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3678 // If this is an object method, then give a different error |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3679 if (*name == '_') |
33738
2172872dfbcd
patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents:
33708
diff
changeset
|
3680 semsg(_(e_cannot_access_protected_method_str), method_name); |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3681 else |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
3682 semsg(_(e_object_method_str_accessible_only_using_object_str), |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3683 method_name, cl->class_name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3684 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3685 else |
33627
41c64cb748c1
patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33618
diff
changeset
|
3686 semsg(_(e_method_not_found_on_class_str_str), method_name, |
35685
5c89a485e597
patch 9.1.0581: Various lines are indented inconsistently
Christian Brabandt <cb@256bit.org>
parents:
35527
diff
changeset
|
3687 cl->class_name); |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3688 vim_free(method_name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3689 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3690 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3691 /* |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3692 * Echo a class or object member not found message. |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3693 */ |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3694 void |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3695 member_not_found_msg(class_T *cl, vartype_T v_type, char_u *name, size_t len) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3696 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3697 char_u *varname = len ? vim_strnsave(name, len) : vim_strsave(name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3698 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3699 if (v_type == VAR_OBJECT) |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3700 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3701 if (class_member_idx(cl, name, len) >= 0) |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
3702 semsg(_(e_class_variable_str_accessible_only_using_class_str), |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3703 varname, cl->class_name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3704 else |
33627
41c64cb748c1
patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33618
diff
changeset
|
3705 semsg(_(e_variable_not_found_on_object_str_str), varname, |
41c64cb748c1
patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33618
diff
changeset
|
3706 cl->class_name); |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3707 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3708 else |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3709 { |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3710 if (object_member_idx(cl, name, len) >= 0) |
33343
41b50abddeea
patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents:
33326
diff
changeset
|
3711 semsg(_(e_object_variable_str_accessible_only_using_object_str), |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3712 varname, cl->class_name); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3713 else |
34676
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3714 { |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3715 if (IS_ENUM(cl)) |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3716 semsg(_(e_enum_value_str_not_found_in_enum_str), |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3717 varname, cl->class_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3718 else |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3719 semsg(_(e_class_variable_str_not_found_in_class_str), |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3720 varname, cl->class_name); |
5b25ec43f208
patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents:
34508
diff
changeset
|
3721 } |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3722 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3723 vim_free(varname); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3724 } |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3725 |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33246
diff
changeset
|
3726 /* |
34112
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3727 * Compile all the class and object methods in "cl". |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3728 */ |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3729 void |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3730 defcompile_class(class_T *cl) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3731 { |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3732 for (int loop = 1; loop <= 2; ++loop) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3733 { |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3734 int func_count = loop == 1 ? cl->class_class_function_count |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3735 : cl->class_obj_method_count; |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3736 for (int i = 0; i < func_count; i++) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3737 { |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3738 ufunc_T *ufunc = loop == 1 ? cl->class_class_functions[i] |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3739 : cl->class_obj_methods[i]; |
34834
d3127b18fe1e
patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
34769
diff
changeset
|
3740 // Don't compile abstract methods |
d3127b18fe1e
patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
34769
diff
changeset
|
3741 if (!IS_ABSTRACT_METHOD(ufunc)) |
d3127b18fe1e
patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents:
34769
diff
changeset
|
3742 defcompile_function(ufunc, cl); |
34112
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3743 } |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3744 } |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3745 } |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3746 |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3747 /* |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3748 * Compile all the classes defined in the current script |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3749 */ |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3750 void |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3751 defcompile_classes_in_script(void) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3752 { |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3753 for (class_T *cl = first_class; cl != NULL; cl = cl->class_next_used) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3754 { |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3755 if (eval_variable(cl->class_name, 0, 0, NULL, NULL, |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3756 EVAL_VAR_NOAUTOLOAD | EVAL_VAR_NO_FUNC) != FAIL) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3757 defcompile_class(cl); |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3758 } |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3759 } |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3760 |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3761 /* |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3762 * Returns TRUE if "name" is the name of a class. The typval for the class is |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3763 * returned in "rettv". |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3764 */ |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3765 int |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3766 is_class_name(char_u *name, typval_T *rettv) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3767 { |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3768 rettv->v_type = VAR_UNKNOWN; |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3769 |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3770 if (eval_variable(name, 0, 0, rettv, NULL, EVAL_VAR_NOAUTOLOAD | |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3771 EVAL_VAR_NO_FUNC) != FAIL) |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3772 return rettv->v_type == VAR_CLASS; |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3773 return FALSE; |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3774 } |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3775 |
0f2632b04cde
patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents:
33996
diff
changeset
|
3776 /* |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3777 * Calls the object builtin method "name" with arguments "argv". The value |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3778 * returned by the builtin method is in "rettv". Returns OK or FAIL. |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3779 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3780 static int |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3781 object_call_builtin_method( |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3782 object_T *obj, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3783 class_builtin_T builtin_method, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3784 int argc, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3785 typval_T *argv, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3786 typval_T *rettv) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3787 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3788 ufunc_T *uf; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3789 int midx; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3790 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3791 if (obj == NULL) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3792 return FAIL; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3793 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3794 uf = class_get_builtin_method(obj->obj_class, builtin_method, &midx); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3795 if (uf == NULL) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3796 return FAIL; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3797 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3798 funccall_T *fc = create_funccal(uf, rettv); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3799 int r; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3800 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3801 if (fc == NULL) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3802 return FAIL; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3803 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3804 ++obj->obj_refcount; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3805 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3806 r = call_def_function(uf, argc, argv, 0, NULL, obj, fc, rettv); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3807 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3808 remove_funccal(); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3809 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3810 return r; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3811 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3812 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3813 /* |
34678
75f7b311ee25
patch 9.1.0220: Few typos in source and test files
Christian Brabandt <cb@256bit.org>
parents:
34676
diff
changeset
|
3814 * Calls the object "empty()" method and returns the method return value. In |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3815 * case of an error, returns TRUE. |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3816 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3817 int |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3818 object_empty(object_T *obj) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3819 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3820 typval_T rettv; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3821 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3822 if (object_call_builtin_method(obj, CLASS_BUILTIN_EMPTY, 0, NULL, &rettv) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3823 == FAIL) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3824 return TRUE; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3825 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3826 return tv_get_bool(&rettv); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3827 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3828 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3829 /* |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3830 * Use the object "len()" method to get an object length. Returns 0 if the |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3831 * method is not found or there is an error. |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3832 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3833 int |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3834 object_len(object_T *obj) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3835 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3836 typval_T rettv; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3837 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3838 if (object_call_builtin_method(obj, CLASS_BUILTIN_LEN, 0, NULL, &rettv) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3839 == FAIL) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3840 return 0; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3841 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3842 return tv_to_number(&rettv); |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3843 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3844 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3845 /* |
35497
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3846 * Return TRUE when two objects have exactly the same values. |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3847 */ |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3848 int |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3849 object_equal( |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3850 object_T *o1, |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3851 object_T *o2, |
35527
b39982468366
patch 9.1.0524: the recursive parameter in the *_equal functions can be removed
Christian Brabandt <cb@256bit.org>
parents:
35522
diff
changeset
|
3852 int ic) // ignore case for strings |
35497
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3853 { |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3854 class_T *cl1, *cl2; |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3855 |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3856 if (o1 == o2) |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3857 return TRUE; |
35499
6aca169bebd6
patch 9.1.0515: Vim9: segfault in object_equal()
Christian Brabandt <cb@256bit.org>
parents:
35497
diff
changeset
|
3858 if (o1 == NULL || o2 == NULL) |
6aca169bebd6
patch 9.1.0515: Vim9: segfault in object_equal()
Christian Brabandt <cb@256bit.org>
parents:
35497
diff
changeset
|
3859 return FALSE; |
35497
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3860 |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3861 cl1 = o1->obj_class; |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3862 cl2 = o2->obj_class; |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3863 |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3864 if (cl1 != cl2 || cl1 == NULL || cl2 == NULL) |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3865 return FALSE; |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3866 |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3867 for (int i = 0; i < cl1->class_obj_member_count; ++i) |
35527
b39982468366
patch 9.1.0524: the recursive parameter in the *_equal functions can be removed
Christian Brabandt <cb@256bit.org>
parents:
35522
diff
changeset
|
3868 if (!tv_equal((typval_T *)(o1 + 1) + i, (typval_T *)(o2 + 1) + i, ic)) |
35497
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3869 return FALSE; |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3870 |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3871 return TRUE; |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3872 } |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3873 |
ae2cc753b57f
patch 9.1.0514: Vim9: issue with comparing objects recursively
Christian Brabandt <cb@256bit.org>
parents:
35212
diff
changeset
|
3874 /* |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3875 * Return a textual representation of object "obj". |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3876 * "obj" must not be NULL. |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3877 * May return NULL. |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3878 */ |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3879 char_u * |
35212
c10c6d293ef7
patch 9.1.0422: function echo_string_core() is too long
Christian Brabandt <cb@256bit.org>
parents:
35068
diff
changeset
|
3880 object2string( |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3881 object_T *obj, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3882 char_u *numbuf, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3883 int copyID, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3884 int echo_style, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3885 int restore_copyID, |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3886 int composite_val) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3887 { |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3888 typval_T rettv; |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3889 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3890 if (object_call_builtin_method(obj, CLASS_BUILTIN_STRING, 0, NULL, &rettv) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3891 == OK |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3892 && rettv.vval.v_string != NULL) |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3893 return rettv.vval.v_string; |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3894 |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3895 int ok = OK; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3896 class_T *cl = obj->obj_class; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3897 garray_T ga; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3898 ga_init2(&ga, 1, 50); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3899 |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3900 if (cl != NULL && IS_ENUM(cl)) |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3901 { |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3902 ga_concat(&ga, (char_u *)"enum "); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3903 ga_concat(&ga, cl->class_name); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3904 char_u *enum_name = ((typval_T *)(obj + 1))->vval.v_string; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3905 ga_concat(&ga, (char_u *)"."); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3906 ga_concat(&ga, enum_name); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3907 } |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3908 else |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3909 { |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3910 ga_concat(&ga, (char_u *)"object of "); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3911 ga_concat(&ga, cl == NULL ? (char_u *)"[unknown]" |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3912 : cl->class_name); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3913 } |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3914 if (cl != NULL) |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3915 { |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3916 ga_concat(&ga, (char_u *)" {"); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3917 for (int i = 0; i < cl->class_obj_member_count; ++i) |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3918 { |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3919 if (i > 0) |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3920 ga_concat(&ga, (char_u *)", "); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3921 ocmember_T *m = &cl->class_obj_members[i]; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3922 ga_concat(&ga, m->ocm_name); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3923 ga_concat(&ga, (char_u *)": "); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3924 char_u *tf = NULL; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3925 char_u *s = echo_string_core((typval_T *)(obj + 1) + i, |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3926 &tf, numbuf, copyID, echo_style, |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3927 restore_copyID, composite_val); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3928 if (s != NULL) |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3929 ga_concat(&ga, s); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3930 vim_free(tf); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3931 if (s == NULL || did_echo_string_emsg) |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3932 { |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3933 ok = FAIL; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3934 break; |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3935 } |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3936 line_breakcheck(); |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3937 } |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3938 ga_concat(&ga, (char_u *)"}"); |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3939 } |
35522
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3940 if (ok == FAIL) |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3941 { |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3942 vim_free(ga.ga_data); |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3943 return NULL; |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3944 } |
a75efb3ef1b5
patch 9.1.0522: Vim9: string(object) hangs for recursive references
Christian Brabandt <cb@256bit.org>
parents:
35518
diff
changeset
|
3945 return (char_u *)ga.ga_data; |
34472
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3946 } |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3947 |
5c1a025192ed
patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents:
34112
diff
changeset
|
3948 /* |
33006
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32972
diff
changeset
|
3949 * 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:
32972
diff
changeset
|
3950 * interfaces matches the class "other_cl". |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3951 */ |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3952 int |
33432
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3953 class_instance_of(class_T *cl, class_T *other_cl) |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3954 { |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3955 if (cl == other_cl) |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3956 return TRUE; |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3957 |
33432
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3958 // Recursively check the base classes. |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3959 for (; cl != NULL; cl = cl->class_extends) |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3960 { |
33432
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3961 if (cl == other_cl) |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3962 return TRUE; |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3963 // Check the implemented interfaces and the super interfaces |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3964 for (int i = cl->class_interface_count - 1; i >= 0; --i) |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
3965 { |
33432
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3966 class_T *intf = cl->class_interfaces_cl[i]; |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3967 while (intf != NULL) |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
3968 { |
33432
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3969 if (intf == other_cl) |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3970 return TRUE; |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3971 // check the super interfaces |
97ceabebaeaf
patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents:
33401
diff
changeset
|
3972 intf = intf->class_extends; |
33278
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
3973 } |
b5ed566262d3
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents:
33268
diff
changeset
|
3974 } |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3975 } |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3976 |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3977 return FALSE; |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3978 } |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3979 |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3980 /* |
33924
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
3981 * "instanceof(object, classinfo, ...)" function |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3982 */ |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3983 void |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3984 f_instanceof(typval_T *argvars, typval_T *rettv) |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3985 { |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3986 typval_T *object_tv = &argvars[0]; |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3987 typval_T *classinfo_tv = &argvars[1]; |
33682
f126ffc85f7c
patch 9.0.2078: several problems with type aliases
Christian Brabandt <cb@256bit.org>
parents:
33678
diff
changeset
|
3988 class_T *c; |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3989 |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3990 rettv->vval.v_number = VVAL_FALSE; |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3991 |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3992 if (check_for_object_arg(argvars, 0) == FAIL |
33924
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
3993 || check_for_class_or_typealias_args(argvars, 1) == FAIL) |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3994 return; |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
3995 |
33291
4cb421ba3385
patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents:
33286
diff
changeset
|
3996 if (object_tv->vval.v_object == NULL) |
4cb421ba3385
patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents:
33286
diff
changeset
|
3997 return; |
4cb421ba3385
patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents:
33286
diff
changeset
|
3998 |
33924
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
3999 for (; classinfo_tv->v_type != VAR_UNKNOWN; ++classinfo_tv) |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
4000 { |
33924
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4001 if (classinfo_tv->v_type == VAR_TYPEALIAS) |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4002 c = classinfo_tv->vval.v_typealias->ta_type->tt_class; |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4003 else |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4004 c = classinfo_tv->vval.v_class; |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4005 |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4006 if (class_instance_of(object_tv->vval.v_object->obj_class, c)) |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
4007 { |
33924
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4008 rettv->vval.v_number = VVAL_TRUE; |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33806
diff
changeset
|
4009 return; |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
4010 } |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
4011 } |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
32960
diff
changeset
|
4012 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4013 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4014 #endif // FEAT_EVAL |