annotate src/vim9class.c @ 33343:41b50abddeea v9.0.1935

patch 9.0.1935: Vim9: not consistent error messages Commit: https://github.com/vim/vim/commit/7fe8f43f49f4fa6f024d0e0ea76d3df5b62a0879 Author: RestorerZ <restorer@mail2k.ru> Date: Sun Sep 24 23:21:24 2023 +0200 patch 9.0.1935: Vim9: not consistent error messages Problem: Vim9: not consistent error messages Solution: Make error messages more consistent. Use "variable" for (object/class) member closes: #13155 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: RestorerZ <restorer@mail2k.ru>
author Christian Brabandt <cb@256bit.org>
date Sun, 24 Sep 2023 23:30:06 +0200
parents 4e531adb3fac
children 3e9a91624b40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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,
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33106
diff changeset
75 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
76 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
77 char_u **init_expr)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
78 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
79 *varname_end = to_name_end(varname, FALSE);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
80 if (*varname == '_' && has_public)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
81 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
82 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
83 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
84 }
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 char_u *colon = skipwhite(*varname_end);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
87 char_u *type_arg = colon;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
88 type_T *type = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
89 if (*colon == ':')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
90 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
91 if (VIM_ISWHITE(**varname_end))
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 semsg(_(e_no_white_space_allowed_before_colon_str), varname);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
94 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
95 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
96 if (!VIM_ISWHITE(colon[1]))
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 semsg(_(e_white_space_required_after_str_str), ":", varname);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
99 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
100 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
101 type_arg = skipwhite(colon + 1);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
102 type = parse_type(&type_arg, type_list, TRUE);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
103 if (type == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
104 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
105 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
106
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
107 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
108 if (type == NULL && *init_arg != '=')
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
109 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
110 emsg(_(e_type_or_initialization_required));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
111 return FAIL;
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
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
114 if (init_expr == NULL && *init_arg == '=')
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
115 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
116 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
117 return FAIL;
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
118 }
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
119
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
120 if (*init_arg == '=')
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 evalarg_T evalarg;
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
123 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
124
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
125 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
126 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
127 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
128 "=", type_arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
129 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
130 }
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
131 init_arg = skipwhite(init_arg + 1);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
132
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
133 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
134 (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
135
33006
29b2193466e0 patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
136 // 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
137 // 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
138 if (type == NULL)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
139 type = &t_any;
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
140
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
141 *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
142 // Free the memory pointed by expr_start.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
143 clear_evalarg(&evalarg, NULL);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
144 }
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
145 else if (!valid_declaration_type(type))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
146 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
147
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
148 *type_ret = type;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
149 return OK;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
150 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
151
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
152 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
153 * Add a member to an object or a class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
154 * Returns OK when successful, "init_expr" will be consumed then.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
155 * Returns FAIL otherwise, caller might need to free "init_expr".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
156 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
157 static int
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
158 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
159 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
160 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
161 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
162 int has_public,
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33106
diff changeset
163 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
164 char_u *init_expr)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
165 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
166 if (ga_grow(gap, 1) == FAIL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
167 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
168 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
169 m->ocm_name = vim_strnsave(varname, varname_end - varname);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
170 m->ocm_access = has_public ? VIM_ACCESS_ALL
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
171 : *varname == '_' ? VIM_ACCESS_PRIVATE : VIM_ACCESS_READ;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
172 m->ocm_type = type;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
173 if (init_expr != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
174 m->ocm_init = init_expr;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
175 ++gap->ga_len;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
176 return OK;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
177 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
178
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
179 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
180 * 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
181 * "gap" contains the found members.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
182 * "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
183 * "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
184 * "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
185 * "member_count" set to the number of members.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
186 * Returns OK or FAIL.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
187 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
188 static int
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
189 add_members_to_class(
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
190 garray_T *gap,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
191 ocmember_T *parent_members,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
192 int parent_count,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
193 ocmember_T **members,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
194 int *member_count)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
195 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
196 *member_count = parent_count + gap->ga_len;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
197 *members = *member_count == 0 ? NULL
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
198 : ALLOC_MULT(ocmember_T, *member_count);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
199 if (*member_count > 0 && *members == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
200 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
201 for (int i = 0; i < parent_count; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
202 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
203 // parent members need to be copied
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
204 ocmember_T *m = *members + i;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
205 *m = parent_members[i];
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
206 m->ocm_name = vim_strsave(m->ocm_name);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
207 if (m->ocm_init != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
208 m->ocm_init = vim_strsave(m->ocm_init);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
209 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
210 if (gap->ga_len > 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
211 // new members are moved
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
212 mch_memmove(*members + parent_count,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
213 gap->ga_data, sizeof(ocmember_T) * gap->ga_len);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
214 VIM_CLEAR(gap->ga_data);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
215 return OK;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
216 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
217
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
218 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
219 * 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
220 * "cl" implementing that interface.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
221 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
222 int
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
223 object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl,
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
224 int is_static)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
225 {
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
226 if (idx >= (is_method ? itf->class_obj_method_count
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
227 : is_static ? itf->class_class_member_count
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
228 : itf->class_obj_member_count))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
229 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
230 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
231 return 0;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
232 }
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
233
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
234 // 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
235 // 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
236 // 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
237 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
238 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
239
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
240 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
241 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
242 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
243
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
244 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
245 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
246 {
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
247 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
248 {
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
249 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
250 {
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
251 searching = FALSE;
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
252 break;
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
253 }
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
254 }
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
255 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
256 // 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
257 // methods.
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
258 method_offset += is_static
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
259 ? super->class_class_function_count_child
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
260 : super->class_obj_method_count_child;
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
261 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
262 if (i2c == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
263 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
264 siemsg("class %s not found on interface %s",
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
265 cl->class_name, itf->class_name);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
266 return 0;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
267 }
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
268 if (is_static)
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
269 {
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
270 // TODO: Need a table for fast lookup?
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
271 char_u *name = itf->class_class_members[idx].ocm_name;
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
272 int m_idx = class_member_idx(i2c->i2c_class, name, 0);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
273 if (m_idx >= 0)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
274 return m_idx;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
275
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
276 siemsg("class %s, interface %s, static %s not found",
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
277 cl->class_name, itf->class_name, name);
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
278 return 0;
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
279 }
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
280 else
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
281 {
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
282 // A table follows the i2c for the class
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
283 int *table = (int *)(i2c + 1);
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
284 // "method_offset" is 0, if method is in the current class. If 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
285 // is in a parent class, then it is non-zero.
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 return table[idx] + method_offset;
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
287 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
288 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
289
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
290 /*
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
291 * 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
292 * 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
293 * 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
294 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
295 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
296 validate_extends_class(
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
297 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
298 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
299 int is_class)
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
300 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
301 typval_T tv;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
302 int success = FALSE;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
303
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
304 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
305 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
306 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
307 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
308 return success;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
309 }
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
310
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 if (tv.v_type != VAR_CLASS || tv.vval.v_class == NULL
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
312 || (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
313 && (tv.vval.v_class->class_flags & CLASS_INTERFACE) != 0)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
314 || (!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
315 && (tv.vval.v_class->class_flags & CLASS_INTERFACE) == 0))
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
316 // a interface cannot extend a class and a class cannot extend an
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
317 // interface.
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
318 semsg(_(e_cannot_extend_str), extends_name);
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
319 else
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
320 {
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
321 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
322 ++extends_cl->class_refcount;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
323 *extends_clp = extends_cl;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
324 success = TRUE;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
325 }
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
326 clear_tv(&tv);
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
327
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
328 return success;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
329 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
330
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
331 /*
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
332 * 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
333 * 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
334 */
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
335 static int
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
336 validate_extends_methods(
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
337 garray_T *objmethods_gap,
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
338 class_T *extends_cl)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
339 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
340 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
341 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
342 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
343
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
344 while (super != NULL)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
345 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
346 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
347 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
348 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
349 super = super->class_extends;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
350 continue;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
351 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
352
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
353 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
354
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
355 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
356 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
357 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
358 int extends_private = (*pstr == '_');
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
359 if (extends_private)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
360 pstr++;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
361
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
362 // 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
363 // 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
364 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
365 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
366 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
367 int priv_method = (*qstr == '_');
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
368 if (priv_method)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
369 qstr++;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
370 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
371 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
372 // 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
373 // the subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
374 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
375 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
376 return FALSE;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
377 }
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 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
380 super = super->class_extends;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
381 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
382
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
383 return TRUE;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
384 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
385
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
386 /*
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
387 * 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
388 * 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
389 * 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
390 */
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
391 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
392 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
393 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
394 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
395 {
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
396 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
397 if (member_count == 0)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
398 return TRUE;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
399
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
400 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
401
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
402 // Validate each member variable
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
403 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
404 {
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
405 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
406 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
407 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
408 ? 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
409
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
410 // 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
411 while (p_cl != NULL)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
412 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
413 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
414 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
415 {
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
416 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
417 continue;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
418 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
419 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
420
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
421 // 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
422 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
423 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
424 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
425 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
426 ? 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
427 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
428 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
429 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
430 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
431 }
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
432 }
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
433
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
434 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
435 }
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
436 }
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
437
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
438 return TRUE;
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
439 }
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
440
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
441 /*
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
442 * 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
443 * 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
444 * 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
445 * 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
446 */
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
447 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
448 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
449 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
450 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
451 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
452 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
453 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
454 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
455
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
456 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
457
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
458 // 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
459 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
460 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
461 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
462 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
463 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
464
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
465 // 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
466 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
467 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
468 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
469 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
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 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
472 continue;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
473 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
474 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
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 // 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
477 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
478 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
479 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
480 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
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 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
483 continue;
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 // 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
486 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
487 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
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 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
490 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
491 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
492
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
493 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
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
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
496 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
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 }
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 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
501 }
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 /*
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
504 * 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
505 * 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
506 * implemented.
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
507 */
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
508 static int
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
509 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
510 garray_T *classmethods_gap,
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
511 garray_T *objmethods_gap,
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
512 class_T *extends_cl)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
513 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
514 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
515 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
516 // 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
517 // 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
518 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
519 ? 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
520 : 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
521 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
522 continue;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
523
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
524 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
525 ? 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
526 : 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
527
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
528 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
529 : objmethods_gap->ga_len;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
530 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
531 ? classmethods_gap->ga_data
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
532 : objmethods_gap->ga_data);
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
533
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
534 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
535 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
536 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
537 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
538 continue;
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 int method_found = FALSE;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
541
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
542 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
543 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
544 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
545 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
546 method_found = TRUE;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
547 break;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
548 }
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
549 }
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
550
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
551 if (!method_found)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
552 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
553 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
554 return FALSE;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
555 }
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
556 }
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
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
559 return TRUE;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
560 }
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
561
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
562 /*
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
563 * 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
564 * 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
565 * 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
566 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
567 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
568 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
569 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
570 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
571 int is_class_var,
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
572 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
573 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
574 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
575 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
576 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
577
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
578 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
579 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
580 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
581 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
582
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
583 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
584 continue;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
585
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
586 // 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
587 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
588 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
589 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
590 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
591 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
592 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
593
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
594 // 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
595 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
596 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
597 // 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
598 // interface.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
599 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
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 else
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 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
604 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
605 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
606 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
607 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
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
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
610 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
611 break;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
612 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
613
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
614 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
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 int ext_cl_count = is_class_var
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
617 ? extends_cl->class_class_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
618 : extends_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
619 ocmember_T *ext_cl_mt = is_class_var
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
620 ? extends_cl->class_class_members
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
621 : extends_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
622 return intf_variable_present(intf_class_name, 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
623 is_class_var, ext_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
624 ext_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
625 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
626 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
627
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
628 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
629 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
630
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 * Check the variables of the interface class "ifcl" match the class variables
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
633 * ("classmembers_gap") and object variables ("objmembers_gap") of a class.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
634 * Returns TRUE if the class and object variables names are valid.
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 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
637 validate_interface_variables(
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
638 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
639 class_T *ifcl,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
640 garray_T *classmembers_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
641 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
642 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
643 {
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
644 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
645 {
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
646 // loop == 1: check class variables
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
647 // loop == 2: check object variables
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
648 int is_class_var = (loop == 1);
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
649 int if_count = is_class_var ? ifcl->class_class_member_count
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
650 : ifcl->class_obj_member_count;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
651 if (if_count == 0)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
652 continue;
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 ocmember_T *if_ms = is_class_var ? ifcl->class_class_members
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
654 : ifcl->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
655 ocmember_T *cl_ms = (ocmember_T *)(is_class_var
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
656 ? classmembers_gap->ga_data
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
657 : objmembers_gap->ga_data);
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 int cl_count = is_class_var ? classmembers_gap->ga_len
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
659 : objmembers_gap->ga_len;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
660 for (int if_i = 0; if_i < if_count; ++if_i)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
661 {
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
662 if (!intf_variable_present(intf_class_name, &if_ms[if_i],
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
663 is_class_var, cl_ms, 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
664 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
665 semsg(_(e_variable_str_of_interface_str_not_implemented),
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
666 if_ms[if_i].ocm_name, intf_class_name);
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
667 return FALSE;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
668 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
669 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
670 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
671
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
672 return TRUE;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
673 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
674
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
675 /*
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
676 * 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
677 */
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
678 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
679 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
680 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
681 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
682
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
683 // 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
684 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
685 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
686 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
687 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
688 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
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 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
691 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
692
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
693 /*
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
694 * 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
695 * 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
696 * 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
697 */
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
698 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
699 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
700 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
701 int is_class_method,
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
702 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
703 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
704 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
705 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
706 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
707
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
708 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
709 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
710 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
711 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
712 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
713 // 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
714 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
715 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
716 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
717 break;
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 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
720
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
721 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
722 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
723 ufunc_T **ext_cl_fp = (ufunc_T **)(is_class_method
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
724 ? extends_cl->class_class_functions
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
725 : extends_cl->class_obj_methods);
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
726 int ext_cl_count = is_class_method
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
727 ? extends_cl->class_class_function_count
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
728 : extends_cl->class_obj_method_count;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
729 return intf_method_present(if_ufunc, is_class_method, ext_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
730 ext_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
731 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
732 }
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 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
735 }
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 * 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
739 * 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
740 * 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
741 * types.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
742 * 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
743 * the new class.
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
744 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
745 static int
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
746 validate_interface_methods(
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
747 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
748 class_T *ifcl,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
749 garray_T *classfunctions_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
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 {
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
753 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
754 {
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
755 // loop == 1: check class methods
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
756 // loop == 2: check object methods
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
757 int is_class_method = (loop == 1);
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
758 int if_count = is_class_method ? ifcl->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
759 : ifcl->class_obj_method_count;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
760 if (if_count == 0)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
761 continue;
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
762 ufunc_T **if_fp = is_class_method ? ifcl->class_class_functions
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
763 : ifcl->class_obj_methods;
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
764 ufunc_T **cl_fp = (ufunc_T **)(is_class_method
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
765 ? classfunctions_gap->ga_data
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
766 : objmethods_gap->ga_data);
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
767 int cl_count = is_class_method ? classfunctions_gap->ga_len
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
768 : objmethods_gap->ga_len;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
769 for (int if_i = 0; if_i < if_count; ++if_i)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
770 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
771 char_u *if_name = if_fp[if_i]->uf_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
772
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
773 if (!intf_method_present(if_fp[if_i], is_class_method, 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
774 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
775 {
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
776 semsg(_(e_method_str_of_interface_str_not_implemented),
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
777 if_name, intf_class_name);
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
778 return FALSE;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
779 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
780 }
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
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
783 return TRUE;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
784 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
785
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
786 /*
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
787 * 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
788 * 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
789 * 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
790 * "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
791 * "objmembers_gap" respectively.
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
792 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
793 static int
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
794 validate_implements_classes(
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
795 garray_T *impl_gap,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
796 class_T **intf_classes,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
797 garray_T *classfunctions_gap,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
798 garray_T *classmembers_gap,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
799 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
800 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
801 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
802 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
803 int success = TRUE;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
804
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
805 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
806 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
807 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
808 typval_T tv;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
809 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
810 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
811 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
812 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
813 success = FALSE;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
814 break;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
815 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
816
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
817 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
818 || tv.vval.v_class == NULL
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
819 || (tv.vval.v_class->class_flags & CLASS_INTERFACE) == 0)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
820 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
821 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
822 success = FALSE;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
823 clear_tv(&tv);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
824 break;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
825 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
826
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
827 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
828 intf_classes[i] = ifcl;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
829 ++ifcl->class_refcount;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
830
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
831 // check the variables of the interface match the members of the class
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
832 success = validate_interface_variables(impl, ifcl, classmembers_gap,
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
833 objmembers_gap, extends_cl);
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
834
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
835 // 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
836 // 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
837 if (success)
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
838 success = validate_interface_methods(impl, 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
839 classfunctions_gap, 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
840 extends_cl);
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
841 clear_tv(&tv);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
842 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
843
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
844 return success;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
845 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
846
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
847 /*
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
848 * 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
849 * (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
850 * to check them.)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
851 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
852 static int
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
853 check_func_arg_names(
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
854 garray_T *classfunctions_gap,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
855 garray_T *objmethods_gap,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
856 garray_T *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 // 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
859 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
860 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
861 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
862
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
863 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
864 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
865 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
866
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
867 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
868 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
869 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
870 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
871
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
872 // 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
873 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
874 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
875 char_u *mname =
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
876 ((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
877 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
878 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
879 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
880 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
881
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
882 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
883 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
884
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
885 return FALSE;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
886 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
887 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
888 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
889 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
890 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
891
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
892 return TRUE;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
893 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
894
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
895 /*
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
896 * Returns TRUE if the member "varname" is already defined.
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
897 */
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
898 static int
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
899 is_duplicate_member(garray_T *mgap, char_u *varname, char_u *varname_end)
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
900 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
901 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
902 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
903 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
904
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
905 for (int i = 0; i < mgap->ga_len; ++i)
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
906 {
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
907 ocmember_T *m = ((ocmember_T *)mgap->ga_data) + i;
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
908 char_u *qstr = *m->ocm_name == '_' ? m->ocm_name + 1 : m->ocm_name;
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
909 if (STRCMP(pstr, qstr) == 0)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
910 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
911 semsg(_(e_duplicate_variable_str), name);
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
912 dup = TRUE;
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
913 break;
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
914 }
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
915 }
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
916
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
917 vim_free(name);
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
918 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
919 }
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
920
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
921 /*
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
922 * 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
923 */
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
924 static int
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
925 is_duplicate_method(
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
926 garray_T *classmethods_gap,
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
927 garray_T *objmethods_gap,
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
928 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
929 {
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
930 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
931
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
932 // 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
933 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
934 {
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
935 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
936 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
937 {
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
938 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
939 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
940 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
941 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
942 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
943 return TRUE;
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
944 }
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
945 }
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
946 }
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
947
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
948 return FALSE;
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
949 }
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
950
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
951 /*
33068
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
952 * 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
953 */
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
954 static int
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
955 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
956 {
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
957 // 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
958 if (is_abstract)
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
959 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
960 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
961 return FALSE;
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
962 }
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
963 // 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
964 if (has_static)
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
965 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
966 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
967 return FALSE;
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
968 }
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
969 // 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
970 // constructor method.
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
971 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
972 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
973 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
974 return FALSE;
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
975 }
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
976 return TRUE;
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
977 }
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
978
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
979 /*
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
980 * 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
981 * 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
982 * 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
983 * 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
984 * 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
985 * 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
986 */
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
987 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
988 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
989 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
990 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
991 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
992 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
993 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
994 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
995 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
996
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
997 // 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
998 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
999 + 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
1000 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
1001 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
1002 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
1003 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
1004 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
1005 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
1006
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1007 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
1008 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
1009 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1010 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
1011 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
1012 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1013 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
1014 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
1015 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
1016 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1017 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1018
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1019 // 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
1020 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
1021 + 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
1022 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
1023 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
1024 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
1025 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
1026 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
1027 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
1028
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1029 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
1030 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1031 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
1032 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
1033 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1034 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
1035 ((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
1036 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1037 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
1038 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
1039 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
1040 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
1041 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1042 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1043
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1044 // 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
1045 // 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
1046 // 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
1047 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
1048 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1049 // 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
1050 // 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
1051 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
1052 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1053 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
1054 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
1055
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1056 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
1057 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1058
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1059 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
1060 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
1061 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1062 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
1063 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
1064 == 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
1065 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1066 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
1067 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
1068 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
1069 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
1070 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1071 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1072 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
1073 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
1074 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1075 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1076
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1077 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
1078 {
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1079 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
1080 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
1081 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1082 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1083 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1084
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1085 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
1086 }
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1087
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 /*
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1089 * 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
1090 * interface class.
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1091 * 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
1092 * 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
1093 * 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
1094 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1095 static int
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1096 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
1097 {
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1098 // 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
1099 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
1100 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1101 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
1102
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1103 // 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
1104 // interfaces.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1105 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
1106 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1107 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
1108 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
1109 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
1110 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
1111 }
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1112 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1113
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
1114 // 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
1115 if (extends_cl != NULL)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1116 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1117 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
1118 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
1119
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1120 // 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
1121 while (pclass != NULL)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1122 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1123 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
1124 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
1125 return FAIL;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1126
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1127 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
1128 pclass = pclass->class_extends;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1129 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1130 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1131
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1132 return OK;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1133 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1134
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1135 /*
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1136 * 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
1137 * and initialize it.
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1138 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1139 static void
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1140 add_class_members(class_T *cl, exarg_T *eap)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1141 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1142 // 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
1143 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
1144 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
1145 if (cl->class_members_tv == NULL)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1146 return;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1147
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1148 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
1149 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1150 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
1151 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
1152 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
1153 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1154 typval_T *etv = eval_expr(m->ocm_init, eap);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1155 if (etv != NULL)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1156 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1157 *tv = *etv;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1158 vim_free(etv);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1159 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1160 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1161 else
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1162 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1163 // TODO: proper default value
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1164 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
1165 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
1166 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1167 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1168 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1169
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1170 /*
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1171 * 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
1172 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1173 static void
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1174 add_default_constructor(
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1175 class_T *cl,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1176 garray_T *classfunctions_gap,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1177 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
1178 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1179 garray_T fga;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1180
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1181 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
1182 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
1183 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
1184 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1185 if (i > 0)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1186 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
1187 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
1188 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
1189 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
1190 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
1191 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1192 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
1193 ga_append(&fga, NUL);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1194
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1195 exarg_T fea;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1196 CLEAR_FIELD(fea);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1197 fea.cmdidx = CMD_def;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1198 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
1199
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1200 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
1201 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
1202
33326
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
1203 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
1204 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
1205
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1206 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
1207 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
1208
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1209 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
1210 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1211 ((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
1212 = nf;
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1213 ++classfunctions_gap->ga_len;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1214
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1215 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
1216 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
1217 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
1218 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1219 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
1220 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
1221 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
1222 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
1223 }
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 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1226
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1227 /*
33268
e231b9af0f44 patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1228 * 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
1229 * 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
1230 * parent class also.
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1231 */
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1232 static int
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1233 add_classfuncs_objmethods(
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1234 class_T *cl,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1235 class_T *extends_cl,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1236 garray_T *classfunctions_gap,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1237 garray_T *objmethods_gap)
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 // 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
1240 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
1241 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1242 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
1243 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
1244 : &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
1245 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
1246 : &cl->class_obj_methods;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1247
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1248 int parent_count = 0;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1249 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
1250 // 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
1251 // 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
1252 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
1253 ? 0
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1254 : 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
1255
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1256 *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
1257 if (*fcount == 0)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1258 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1259 *fup = NULL;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1260 continue;
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 *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
1263 if (*fup == NULL)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1264 return FAIL;
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1265
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1266 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
1267 mch_memmove(*fup, gap->ga_data, sizeof(ufunc_T *) * gap->ga_len);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1268 vim_free(gap->ga_data);
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1269 if (loop == 1)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1270 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
1271 else
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1272 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
1273
33268
e231b9af0f44 patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1274 if (loop == 2)
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1275 {
33268
e231b9af0f44 patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1276 // 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
1277
e231b9af0f44 patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1278 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
1279 {
33268
e231b9af0f44 patch 9.0.1902: Vim9: Coverity complains about dead code
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1280 // 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
1281 // 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
1282 // 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
1283 // 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
1284 // 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
1285 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
1286 (*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
1287
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1288 // 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
1289 // 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
1290 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
1291 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
1292 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1293 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
1294 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
1295 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
1296 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1297 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
1298 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
1299 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
1300 (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
1301 TRUE, where);
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 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1304 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1305 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1306
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1307 // 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
1308 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
1309 {
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1310 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
1311 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
1312 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
1313 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
1314 if (loop == 2)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1315 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
1316 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1317 }
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1318
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1319 return OK;
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
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1322 /*
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1323 * Handle ":class" and ":abstract class" up to ":endclass".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1324 * Handle ":interface" up to ":endinterface".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1325 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1326 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1327 ex_class(exarg_T *eap)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1328 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1329 int is_class = eap->cmdidx == CMD_class; // FALSE for :interface
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1330 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
1331 char_u *arg = eap->arg;
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1332 int is_abstract = eap->cmdidx == CMD_abstract;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1333
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1334 if (is_abstract)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1335 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1336 if (STRNCMP(arg, "class", 5) != 0 || !VIM_ISWHITE(arg[5]))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1337 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1338 semsg(_(e_invalid_argument_str), arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1339 return;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1340 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1341 arg = skipwhite(arg + 5);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1342 is_class = TRUE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1343 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1344
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1345 if (!current_script_is_vim9()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1346 || (cmdmod.cmod_flags & CMOD_LEGACY)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1347 || !getline_equal(eap->getline, eap->cookie, getsourceline))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1348 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1349 if (is_class)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1350 emsg(_(e_class_can_only_be_defined_in_vim9_script));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1351 else
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1352 emsg(_(e_interface_can_only_be_defined_in_vim9_script));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1353 return;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1354 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1355
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1356 if (!ASCII_ISUPPER(*arg))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1357 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1358 if (is_class)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1359 semsg(_(e_class_name_must_start_with_uppercase_letter_str), arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1360 else
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1361 semsg(_(e_interface_name_must_start_with_uppercase_letter_str),
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1362 arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1363 return;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1364 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1365 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
1366 if (!IS_WHITE_OR_NUL(*name_end))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1367 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1368 semsg(_(e_white_space_required_after_name_str), arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1369 return;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1370 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1371 char_u *name_start = arg;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1372
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1373 // "export class" gets used when creating the class, don't use "is_export"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1374 // for the items inside the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1375 int class_export = is_export;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1376 is_export = FALSE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1377
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1378 // TODO:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1379 // generics: <Tkey, Tentry>
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1380
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1381 // Name for "extends BaseClass"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1382 char_u *extends = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1383
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1384 // Names for "implements SomeInterface"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1385 garray_T ga_impl;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1386 ga_init2(&ga_impl, sizeof(char_u *), 5);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1387
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1388 arg = skipwhite(name_end);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1389 while (*arg != NUL && *arg != '#' && *arg != '\n')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1390 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1391 // TODO:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1392 // specifies SomeInterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1393 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
1394 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1395 if (extends != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1396 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1397 emsg(_(e_duplicate_extends));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1398 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1399 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1400 arg = skipwhite(arg + 7);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1401 char_u *end = find_name_end(arg, NULL, NULL, FNE_CHECK_START);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1402 if (!IS_WHITE_OR_NUL(*end))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1403 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1404 semsg(_(e_white_space_required_after_name_str), arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1405 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1406 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1407 extends = vim_strnsave(arg, end - arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1408 if (extends == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1409 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1410
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1411 arg = skipwhite(end + 1);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1412 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1413 else if (STRNCMP(arg, "implements", 10) == 0
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1414 && IS_WHITE_OR_NUL(arg[10]))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1415 {
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1416 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
1417 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1418 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
1419 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
1420 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1421
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1422 if (ga_impl.ga_len > 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1423 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1424 emsg(_(e_duplicate_implements));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1425 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1426 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1427 arg = skipwhite(arg + 10);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1428
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1429 for (;;)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1430 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1431 char_u *impl_end = find_name_end(arg, NULL, NULL,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1432 FNE_CHECK_START);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1433 if (!IS_WHITE_OR_NUL(*impl_end) && *impl_end != ',')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1434 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1435 semsg(_(e_white_space_required_after_name_str), arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1436 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1437 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1438 char_u *iname = vim_strnsave(arg, impl_end - arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1439 if (iname == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1440 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1441 for (int i = 0; i < ga_impl.ga_len; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1442 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
1443 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1444 semsg(_(e_duplicate_interface_after_implements_str),
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1445 iname);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1446 vim_free(iname);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1447 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1448 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1449 if (ga_add_string(&ga_impl, iname) == FAIL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1450 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1451 vim_free(iname);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1452 goto early_ret;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1453 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1454 if (*impl_end != ',')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1455 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1456 arg = skipwhite(impl_end);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1457 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1458 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1459 arg = skipwhite(impl_end + 1);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1460 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1461 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1462 else
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1463 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1464 semsg(_(e_trailing_characters_str), arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1465 early_ret:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1466 vim_free(extends);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1467 ga_clear_strings(&ga_impl);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1468 return;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1469 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1470 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1471
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1472 garray_T type_list; // list of pointers to allocated types
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1473 ga_init2(&type_list, sizeof(type_T *), 10);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1474
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1475 // Growarray with class members declared in the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1476 garray_T classmembers;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1477 ga_init2(&classmembers, sizeof(ocmember_T), 10);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1478
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1479 // Growarray with functions declared in the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1480 garray_T classfunctions;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1481 ga_init2(&classfunctions, sizeof(ufunc_T *), 10);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1482
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1483 // Growarray with object members declared in the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1484 garray_T objmembers;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1485 ga_init2(&objmembers, sizeof(ocmember_T), 10);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1486
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1487 // Growarray with object methods declared in the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1488 garray_T objmethods;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1489 ga_init2(&objmethods, sizeof(ufunc_T *), 10);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1490
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1491 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1492 * Go over the body of the class/interface until "endclass" or
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1493 * "endinterface" is found.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1494 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1495 char_u *theline = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1496 int success = FALSE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1497 for (;;)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1498 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1499 vim_free(theline);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1500 theline = eap->getline(':', eap->cookie, 0, GETLINE_CONCAT_ALL);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1501 if (theline == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1502 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1503 char_u *line = skipwhite(theline);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1504
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1505 // Skip empty and comment lines.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1506 if (*line == NUL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1507 continue;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1508 if (*line == '#')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1509 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1510 if (vim9_bad_comment(line))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1511 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1512 continue;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1513 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1514
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1515 char_u *p = line;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1516 char *end_name = is_class ? "endclass" : "endinterface";
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1517 if (checkforcmd(&p, end_name, is_class ? 4 : 5))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1518 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1519 if (STRNCMP(line, end_name, is_class ? 8 : 12) != 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1520 semsg(_(e_command_cannot_be_shortened_str), line);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1521 else if (*p == '|' || !ends_excmd2(line, p))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1522 semsg(_(e_trailing_characters_str), p);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1523 else
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1524 success = TRUE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1525 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1526 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1527 char *wrong_name = is_class ? "endinterface" : "endclass";
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1528 if (checkforcmd(&p, wrong_name, is_class ? 5 : 4))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1529 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1530 semsg(_(e_invalid_command_str_expected_str), line, end_name);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1531 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1532 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1533
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1534 int has_public = FALSE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1535 if (checkforcmd(&p, "public", 3))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1536 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1537 if (STRNCMP(line, "public", 6) != 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1538 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1539 semsg(_(e_command_cannot_be_shortened_str), line);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1540 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1541 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1542 has_public = TRUE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1543 p = skipwhite(line + 6);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1544
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1545 if (STRNCMP(p, "this", 4) != 0 && STRNCMP(p, "static", 6) != 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1546 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1547 emsg(_(e_public_must_be_followed_by_this_or_static));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1548 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1549 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1550 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1551
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1552 int abstract_method = FALSE;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1553 char_u *pa = p;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1554 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
1555 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1556 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
1557 {
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1558 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
1559 break;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1560 }
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1561
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1562 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
1563 // ignore "abstract" in an interface (as all the methods in an
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1564 // interface are abstract.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1565 p = skipwhite(pa + 8);
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1566 else
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1567 {
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1568 if (!is_abstract)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1569 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1570 semsg(_(e_abstract_method_in_concrete_class), pa);
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1571 break;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1572 }
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1573
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1574 abstract_method = TRUE;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1575 p = skipwhite(pa + 8);
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1576 if (STRNCMP(p, "def", 3) != 0 && STRNCMP(p, "static", 6) != 0)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1577 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1578 emsg(_(e_abstract_must_be_followed_by_def_or_static));
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1579 break;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1580 }
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1581 }
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1582 }
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1583
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1584 int has_static = FALSE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1585 char_u *ps = p;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1586 if (checkforcmd(&p, "static", 4))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1587 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1588 if (STRNCMP(ps, "static", 6) != 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1589 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1590 semsg(_(e_command_cannot_be_shortened_str), ps);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1591 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1592 }
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1593
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1594 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
1595 {
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1596 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
1597 break;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1598 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1599 has_static = TRUE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1600 p = skipwhite(ps + 6);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1601 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1602
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1603 // object members (public, read access, private):
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1604 // "this._varname"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1605 // "this.varname"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1606 // "public this.varname"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1607 if (STRNCMP(p, "this", 4) == 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1608 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1609 if (p[4] != '.' || !eval_isnamec1(p[5]))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1610 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
1611 semsg(_(e_invalid_object_variable_declaration_str), p);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1612 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1613 }
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1614 if (has_static)
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1615 {
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1616 emsg(_(e_static_cannot_be_followed_by_this));
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1617 break;
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1618 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1619 char_u *varname = p + 5;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1620 char_u *varname_end = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1621 type_T *type = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1622 char_u *init_expr = 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
1623
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1624 if (!is_class && *varname == '_')
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1625 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1626 // private variables are not supported in an interface
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1627 semsg(_(e_private_variable_not_supported_in_interface),
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1628 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
1629 break;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1630 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1631
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1632 if (parse_member(eap, line, varname, has_public,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1633 &varname_end, &type_list, &type,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1634 is_class ? &init_expr: NULL) == FAIL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1635 break;
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1636 if (is_duplicate_member(&objmembers, varname, varname_end))
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1637 {
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1638 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
1639 break;
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1640 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1641 if (add_member(&objmembers, varname, varname_end,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1642 has_public, type, init_expr) == FAIL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1643 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1644 vim_free(init_expr);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1645 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1646 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1647 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1648
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1649 // constructors:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1650 // def new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1651 // enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1652 // def newOther()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1653 // enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1654 // object methods and class functions:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1655 // def SomeMethod()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1656 // enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1657 // static def ClassFunction()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1658 // enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1659 // TODO:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1660 // def <Tval> someMethod()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1661 // enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1662 else if (checkforcmd(&p, "def", 3))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1663 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1664 exarg_T ea;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1665 garray_T lines_to_free;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1666
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1667 // TODO: error for "public static def Func()"?
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1668
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1669 CLEAR_FIELD(ea);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1670 ea.cmd = line;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1671 ea.arg = p;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1672 ea.cmdidx = CMD_def;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1673 ea.getline = eap->getline;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1674 ea.cookie = eap->cookie;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1675
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1676 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
1677 int class_flags;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1678 if (is_class)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1679 class_flags = abstract_method ? CF_ABSTRACT_METHOD : CF_CLASS;
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1680 else
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1681 class_flags = CF_INTERFACE;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1682 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
1683 class_flags, objmembers.ga_data, objmembers.ga_len);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1684 ga_clear_strings(&lines_to_free);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1685
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1686 if (uf != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1687 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1688 char_u *name = uf->uf_name;
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
1689 int is_new = STRNCMP(name, "new", 3) == 0;
33068
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
1690
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1691 if (!is_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
1692 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1693 // private variables are not supported in an interface
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1694 semsg(_(e_private_method_not_supported_in_interface),
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1695 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
1696 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
1697 break;
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1698 }
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1699 if (is_new && !is_valid_constructor(uf, is_abstract,
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1700 has_static))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1701 {
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
1702 func_clear_free(uf, FALSE);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1703 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1704 }
33068
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
1705
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1706 // 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
1707 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
1708 {
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
1709 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
1710 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
1711 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
1712 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1713
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
1714 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
1715 ? &classfunctions : &objmethods;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1716 if (ga_grow(fgap, 1) == OK)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1717 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1718 if (is_new)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1719 uf->uf_flags |= FC_NEW;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1720
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1721 if (abstract_method)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1722 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
1723
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1724 ((ufunc_T **)fgap->ga_data)[fgap->ga_len] = uf;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1725 ++fgap->ga_len;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1726 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1727 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1728 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1729
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1730 // class members
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1731 else if (has_static)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1732 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1733 // class members (public, read access, private):
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1734 // "static _varname"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1735 // "static varname"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1736 // "public static varname"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1737 char_u *varname = p;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1738 char_u *varname_end = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1739 type_T *type = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1740 char_u *init_expr = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1741 if (parse_member(eap, line, varname, has_public,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1742 &varname_end, &type_list, &type,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1743 is_class ? &init_expr : NULL) == FAIL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1744 break;
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1745 if (is_duplicate_member(&classmembers, varname, varname_end))
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1746 {
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1747 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
1748 break;
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
1749 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1750 if (add_member(&classmembers, varname, varname_end,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1751 has_public, type, init_expr) == FAIL)
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 vim_free(init_expr);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1754 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1755 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1756 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1757
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1758 else
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 if (is_class)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1761 semsg(_(e_not_valid_command_in_class_str), line);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1762 else
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1763 semsg(_(e_not_valid_command_in_interface_str), line);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1764 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1765 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1766 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1767 vim_free(theline);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1768
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1769 class_T *extends_cl = NULL; // class from "extends" argument
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1770
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1771 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1772 * Check a few things before defining the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1773 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1774
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1775 // Check the "extends" class is valid.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1776 if (success && extends != 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
1777 success = validate_extends_class(extends, &extends_cl, is_class);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1778 VIM_CLEAR(extends);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1779
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
1780 // 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
1781 // 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
1782 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
1783 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
1784
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
1785 // 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
1786 // 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
1787 // 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
1788 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
1789 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1790 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
1791 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
1792 else
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1793 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
1794 }
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
1795
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1796 // 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
1797 // 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
1798 // 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
1799 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
1800 && (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
1801 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
1802 &objmethods, extends_cl);
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1803
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1804 class_T **intf_classes = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1805
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1806 // Check all "implements" entries are valid.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1807 if (success && ga_impl.ga_len > 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1808 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1809 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
1810
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1811 success = validate_implements_classes(&ga_impl, intf_classes,
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1812 &classfunctions, &classmembers,
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1813 &objmethods, &objmembers,
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
1814 extends_cl);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1815 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1816
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1817 // 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
1818 if (success)
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1819 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
1820 &classmembers);
32670
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 class_T *cl = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1823 if (success)
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 // "endclass" encountered without failures: Create the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1826
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1827 cl = ALLOC_CLEAR_ONE(class_T);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1828 if (cl == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1829 goto cleanup;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1830 if (!is_class)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1831 cl->class_flags = CLASS_INTERFACE;
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1832 else if (is_abstract)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
1833 cl->class_flags = CLASS_ABSTRACT;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1834
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1835 cl->class_refcount = 1;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1836 cl->class_name = vim_strnsave(name_start, name_end - name_start);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1837 if (cl->class_name == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1838 goto cleanup;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1839
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1840 if (extends_cl != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1841 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1842 cl->class_extends = extends_cl;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1843 extends_cl->class_flags |= CLASS_EXTENDED;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1844 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1845
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
1846 // Add class and object variables to "cl".
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1847 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
1848 NULL,
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
1849 0,
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1850 &cl->class_class_members,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1851 &cl->class_class_member_count) == FAIL
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1852 || add_members_to_class(&objmembers,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1853 extends_cl == NULL ? NULL
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1854 : extends_cl->class_obj_members,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1855 extends_cl == NULL ? 0
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1856 : extends_cl->class_obj_member_count,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1857 &cl->class_obj_members,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1858 &cl->class_obj_member_count) == FAIL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1859 goto cleanup;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1860
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1861 if (ga_impl.ga_len > 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1862 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1863 // Move the "implements" names into the class.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1864 cl->class_interface_count = ga_impl.ga_len;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1865 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
1866 if (cl->class_interfaces == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1867 goto cleanup;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1868 for (int i = 0; i < ga_impl.ga_len; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1869 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
1870 VIM_CLEAR(ga_impl.ga_data);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1871 ga_impl.ga_len = 0;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1872
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1873 cl->class_interfaces_cl = intf_classes;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1874 intf_classes = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1875 }
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 if (cl->class_interface_count > 0 || extends_cl != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1878 {
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1879 // 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
1880 // classes.
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1881 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
1882 goto cleanup;
32670
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
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1885 // Allocate a typval for each class member and initialize it.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1886 if (is_class && cl->class_class_member_count > 0)
32896
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1887 add_class_members(cl, eap);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1888
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1889 int have_new = FALSE;
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1890 ufunc_T *class_func = NULL;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1891 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
1892 {
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1893 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
1894 if (STRCMP(class_func->uf_name, "new") == 0)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1895 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1896 have_new = TRUE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1897 break;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1898 }
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1899 }
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1900
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1901 if (have_new)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1902 // 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
1903 class_func->uf_ret_type->tt_class = cl;
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32896
diff changeset
1904 else if (is_class && !is_abstract && !have_new)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1905 // 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
1906 add_default_constructor(cl, &classfunctions, &type_list);
32670
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 // 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
1909 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
1910 &objmethods) == FAIL)
223765c87ea9 patch 9.0.1757: ex_class() function is too long
Christian Brabandt <cb@256bit.org>
parents: 32874
diff changeset
1911 goto cleanup;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1912
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1913 cl->class_type.tt_type = VAR_CLASS;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1914 cl->class_type.tt_class = cl;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1915 cl->class_object_type.tt_type = VAR_OBJECT;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1916 cl->class_object_type.tt_class = cl;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1917 cl->class_type_list = type_list;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1918
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
1919 class_created(cl);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
1920
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1921 // TODO:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1922 // - Fill hashtab with object members and methods ?
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1923
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1924 // Add the class to the script-local variables.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1925 // TODO: handle other context, e.g. in a function
33119
bede81965821 patch 9.0.1842: Need more accurate profiling
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
1926 // TODO: does uf_hash need to be cleared?
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1927 typval_T tv;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1928 tv.v_type = VAR_CLASS;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1929 tv.vval.v_class = cl;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1930 is_export = class_export;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1931 SOURCING_LNUM = start_lnum;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1932 set_var_const(cl->class_name, current_sctx.sc_sid,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1933 NULL, &tv, FALSE, 0, 0);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1934 return;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1935 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1936
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1937 cleanup:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1938 if (cl != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1939 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1940 vim_free(cl->class_name);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1941 vim_free(cl->class_class_functions);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1942 if (cl->class_interfaces != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1943 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1944 for (int i = 0; i < cl->class_interface_count; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1945 vim_free(cl->class_interfaces[i]);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1946 vim_free(cl->class_interfaces);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1947 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1948 if (cl->class_interfaces_cl != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1949 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1950 for (int i = 0; i < cl->class_interface_count; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1951 class_unref(cl->class_interfaces_cl[i]);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1952 vim_free(cl->class_interfaces_cl);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1953 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1954 vim_free(cl->class_obj_members);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1955 vim_free(cl->class_obj_methods);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1956 vim_free(cl);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1957 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1958
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1959 vim_free(extends);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1960 class_unref(extends_cl);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1961
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1962 if (intf_classes != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1963 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1964 for (int i = 0; i < ga_impl.ga_len; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1965 class_unref(intf_classes[i]);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1966 vim_free(intf_classes);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1967 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1968 ga_clear_strings(&ga_impl);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1969
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1970 for (int round = 1; round <= 2; ++round)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1971 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1972 garray_T *gap = round == 1 ? &classmembers : &objmembers;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1973 if (gap->ga_len == 0 || gap->ga_data == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1974 continue;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1975
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1976 for (int i = 0; i < gap->ga_len; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1977 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1978 ocmember_T *m = ((ocmember_T *)gap->ga_data) + i;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1979 vim_free(m->ocm_name);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1980 vim_free(m->ocm_init);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1981 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1982 ga_clear(gap);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1983 }
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 for (int i = 0; i < objmethods.ga_len; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1986 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1987 ufunc_T *uf = ((ufunc_T **)objmethods.ga_data)[i];
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1988 func_clear_free(uf, FALSE);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1989 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1990 ga_clear(&objmethods);
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 for (int i = 0; i < classfunctions.ga_len; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1993 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1994 ufunc_T *uf = ((ufunc_T **)classfunctions.ga_data)[i];
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1995 func_clear_free(uf, FALSE);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1996 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1997 ga_clear(&classfunctions);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1998
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1999 clear_type_list(&type_list);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2000 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2001
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2002 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2003 * 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
2004 * 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
2005 * 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
2006 * class members.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2007 * 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
2008 * Set *p_m ocmmember_T if not NULL
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2009 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2010 type_T *
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2011 class_member_type(
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
2012 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
2013 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
2014 char_u *name,
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
2015 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
2016 int *member_idx)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2017 {
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2018 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
2019 ocmember_T *m;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2020
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2021 *member_idx = -1; // not found (yet)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2022
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2023 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
2024 member_idx);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2025 if (m == NULL)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2026 {
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2027 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
2028 len);
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2029 return &t_any;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2030 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2031
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2032 return m->ocm_type;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2033 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2034
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2035 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2036 * Handle ":enum" up to ":endenum".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2037 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2038 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2039 ex_enum(exarg_T *eap UNUSED)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2040 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2041 // TODO
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2042 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2043
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2044 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2045 * Handle ":type".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2046 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2047 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2048 ex_type(exarg_T *eap UNUSED)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2049 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2050 // TODO
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2051 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2052
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2053 /*
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2054 * 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
2055 * 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
2056 * "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
2057 * 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
2058 */
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2059 static int
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2060 get_member_tv(
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2061 class_T *cl,
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2062 int is_object,
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2063 char_u *name,
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2064 size_t namelen,
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2065 typval_T *rettv)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2066 {
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2067 ocmember_T *m;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2068 int m_idx;
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2069
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2070 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
2071 &m_idx);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2072 if (m == NULL)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2073 return FAIL;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2074
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2075 if (*name == '_')
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2076 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
2077 semsg(_(e_cannot_access_private_variable_str), m->ocm_name);
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2078 return FAIL;
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2079 }
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2080
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2081 // The object only contains a pointer to the class, the member
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2082 // values array follows right after that.
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2083 object_T *obj = rettv->vval.v_object;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2084 if (is_object)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2085 {
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2086 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
2087 copy_tv(tv, rettv);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2088 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2089 else
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2090 copy_tv(&cl->class_members_tv[m_idx], rettv);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2091
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2092 object_unref(obj);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2093
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2094 return OK;
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2095 }
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2096
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2097 /*
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2098 * Evaluate what comes after a class:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2099 * - class member: SomeClass.varname
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2100 * - class function: SomeClass.SomeMethod()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2101 * - class constructor: SomeClass.new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2102 * - object member: someObject.varname
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2103 * - object method: someObject.SomeMethod()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2104 *
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2105 * "*arg" points to the '.'.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2106 * "*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
2107 *
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2108 * Returns FAIL or OK.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2109 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2110 int
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2111 class_object_index(
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2112 char_u **arg,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2113 typval_T *rettv,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2114 evalarg_T *evalarg,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2115 int verbose UNUSED) // give error messages
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2116 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2117 if (VIM_ISWHITE((*arg)[1]))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2118 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2119 semsg(_(e_no_white_space_allowed_after_str_str), ".", *arg);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2120 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2121 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2122
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2123 ++*arg;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2124 char_u *name = *arg;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2125 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
2126 if (name_end == name)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2127 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2128 size_t len = name_end - name;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2129
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2130 class_T *cl;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2131 if (rettv->v_type == VAR_CLASS)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2132 cl = rettv->vval.v_class;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2133 else // VAR_OBJECT
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2134 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2135 if (rettv->vval.v_object == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2136 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2137 emsg(_(e_using_null_object));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2138 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2139 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2140 cl = rettv->vval.v_object->obj_class;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2141 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2142
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2143 if (cl == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2144 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2145 emsg(_(e_incomplete_type));
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2146 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2147 }
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 (*name_end == '(')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2150 {
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2151 ufunc_T *fp;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2152
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2153 fp = method_lookup(cl, rettv->v_type, name, len, NULL);
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2154 if (fp == NULL)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2155 {
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2156 method_not_found_msg(cl, rettv->v_type, name, len);
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2157 return FAIL;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2158 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2159
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2160 typval_T argvars[MAX_FUNC_ARGS + 1];
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2161 int argcount = 0;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2162
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2163 if (*fp->uf_name == '_')
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2164 {
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2165 // Cannot access a private method outside of a class
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2166 semsg(_(e_cannot_access_private_method_str), name);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2167 return FAIL;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2168 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2169
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2170 char_u *argp = name_end;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2171 int ret = get_func_arguments(&argp, evalarg, 0,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2172 argvars, &argcount);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2173 if (ret == FAIL)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2174 return FAIL;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2175
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2176 funcexe_T funcexe;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2177 CLEAR_FIELD(funcexe);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2178 funcexe.fe_evaluate = TRUE;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2179 if (rettv->v_type == VAR_OBJECT)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2180 {
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2181 funcexe.fe_object = rettv->vval.v_object;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2182 ++funcexe.fe_object->obj_refcount;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2183 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2184
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2185 // Clear the class or object after calling the function, in
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2186 // case the refcount is one.
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2187 typval_T tv_tofree = *rettv;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2188 rettv->v_type = VAR_UNKNOWN;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2189
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2190 // Call the user function. Result goes into rettv;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2191 int error = call_user_func_check(fp, argcount, argvars,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2192 rettv, &funcexe, NULL);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2193
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2194 // Clear the previous rettv and the arguments.
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2195 clear_tv(&tv_tofree);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2196 for (int idx = 0; idx < argcount; ++idx)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2197 clear_tv(&argvars[idx]);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2198
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2199 if (error != FCERR_NONE)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2200 {
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2201 user_func_error(error, printable_func_name(fp),
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2202 funcexe.fe_found_var);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2203 return FAIL;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2204 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2205 *arg = argp;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2206 return OK;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2207 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2208
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2209 else if (rettv->v_type == VAR_OBJECT)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2210 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2211 // 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
2212 // variable table.
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33217
diff changeset
2213 if (get_member_tv(cl, TRUE, name, len, rettv) == OK)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2214 {
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2215 *arg = name_end;
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
2216 return OK;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2217 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2218
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2219 member_not_found_msg(cl, VAR_OBJECT, name, len);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2220 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2221
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2222 else if (rettv->v_type == VAR_CLASS)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2223 {
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2224 int m_idx;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2225
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2226 // class member
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2227 ocmember_T *m = class_member_lookup(cl, name, len, &m_idx);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2228 if (m == NULL)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2229 {
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2230 member_not_found_msg(cl, VAR_CLASS, name, len);
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2231 return FAIL;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2232 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2233
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2234 if (*name == '_')
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2235 {
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
2236 semsg(_(e_cannot_access_private_variable_str), m->ocm_name);
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2237 return FAIL;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2238 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2239
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2240 typval_T *tv = &cl->class_members_tv[m_idx];
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2241 copy_tv(tv, rettv);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2242 class_unref(cl);
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2243
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2244 *arg = name_end;
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2245 return OK;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2246 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2247
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2248 return FAIL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2249 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2250
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2251 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2252 * 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
2253 * Otherwise return NULL.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2254 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2255 ufunc_T *
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2256 find_class_func(char_u **arg)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2257 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2258 char_u *name = *arg;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2259 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
2260 if (name_end == name || *name_end != '.')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2261 return NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2262
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2263 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
2264 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
2265 typval_T tv;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2266 tv.v_type = VAR_UNKNOWN;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2267 if (eval_variable(name, (int)len,
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2268 0, &tv, NULL, EVAL_VAR_NOAUTOLOAD) == FAIL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2269 return NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2270 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
2271 goto fail_after_eval;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2272
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2273 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
2274 : tv.vval.v_object->obj_class;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2275 if (cl == NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2276 goto fail_after_eval;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2277 char_u *fname = name_end + 1;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2278 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
2279 if (fname_end == fname)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2280 goto fail_after_eval;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2281 len = fname_end - fname;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2282
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2283 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
2284
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2285 fail_after_eval:
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2286 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
2287 return fp;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2288 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2289
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2290 /*
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2291 * 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
2292 * 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
2293 * 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
2294 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2295 int
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2296 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
2297 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2298 int idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2299 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
2300 return idx;
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2301 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2302
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2303 /*
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2304 * 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
2305 * 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
2306 * 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
2307 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2308 ocmember_T *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2309 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
2310 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2311 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
2312 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
2313 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
2314 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2315 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
2316 if (namelen)
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2317 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2318 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
2319 && 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
2320 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2321 ret_m = m;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2322 ret_idx = i;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2323 break;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2324 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2325 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2326 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
2327 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2328 ret_m = m;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2329 ret_idx = i;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2330 break;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2331 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2332 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2333 if (idx != NULL)
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2334 *idx = ret_idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2335 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
2336 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2337
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2338 /*
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2339 * Returns the index of class method "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
2340 * Returns -1, 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
2341 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2342 int
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2343 class_method_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
2344 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2345 int idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2346 class_method_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
2347 return idx;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2348 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2349
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2350 /*
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2351 * 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
2352 * 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
2353 * 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
2354 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2355 ufunc_T *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2356 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
2357 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2358 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
2359 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
2360 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
2361 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2362 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
2363 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
2364 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
2365 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2366 ret_fp = fp;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2367 ret_idx = i;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2368 break;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2369 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2370 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2371 if (idx != NULL)
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2372 *idx = ret_idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2373 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
2374 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2375
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2376 /*
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2377 * 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
2378 * 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
2379 * 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
2380 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2381 int
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2382 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
2383 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2384 int idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2385 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
2386 return idx;
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2387 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2388
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2389 /*
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2390 * 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
2391 * 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
2392 * 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
2393 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2394 ocmember_T *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2395 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
2396 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2397 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
2398 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
2399 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
2400 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2401 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
2402 if (namelen)
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2403 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2404 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
2405 && 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
2406 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2407 ret_m = m;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2408 ret_idx = i;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2409 break;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2410 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2411 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2412 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
2413 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2414 ret_m = m;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2415 ret_idx = i;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2416 break;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2417 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2418 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2419 if (idx != NULL)
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2420 *idx = ret_idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2421 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
2422 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2423
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2424 /*
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2425 * Returns the index of object method "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
2426 * Returns -1, if the method is not found.
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
2427 */
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
2428 int
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2429 object_method_idx(class_T *cl, char_u *name, size_t namelen)
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
2430 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2431 int idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2432 object_method_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
2433 return idx;
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
2434 }
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
2435
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
2436 /*
33233
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2437 * 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
2438 * 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
2439 * 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
2440 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2441 ufunc_T *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2442 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
2443 {
33246
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2444 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
2445 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
2446 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
2447 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2448 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
2449 // 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
2450 // 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
2451 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
2452 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
2453 {
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2454 ret_fp = fp;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2455 ret_idx = i;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2456 break;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2457 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2458 }
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2459 if (idx != NULL)
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2460 *idx = ret_idx;
877dddec681f patch 9.0.1895: Vim9: finding object method/member is inefficient
Christian Brabandt <cb@256bit.org>
parents: 33233
diff changeset
2461 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
2462 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2463
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2464 /*
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2465 * 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
2466 * 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
2467 * object member variable.
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2468 *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2469 * 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
2470 * 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
2471 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2472 ocmember_T *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2473 member_lookup(
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2474 class_T *cl,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2475 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
2476 char_u *name,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2477 size_t namelen,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2478 int *idx)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2479 {
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2480 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
2481 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
2482 else
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2483 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
2484 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2485
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2486 /*
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2487 * 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
2488 * 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
2489 *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2490 * 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
2491 * 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
2492 */
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2493 ufunc_T *
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2494 method_lookup(
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2495 class_T *cl,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2496 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
2497 char_u *name,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2498 size_t namelen,
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2499 int *idx)
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2500 {
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2501 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
2502 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
2503 else
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2504 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
2505 }
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2506
108d890d887f patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2507 /*
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2508 * 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
2509 * Return FALSE if not.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2510 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2511 int
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2512 inside_class(cctx_T *cctx_arg, class_T *cl)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2513 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2514 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
2515 if (cctx->ctx_ufunc != NULL
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2516 && class_instance_of(cctx->ctx_ufunc->uf_class, cl))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2517 return TRUE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2518 return FALSE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2519 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2520
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2521 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2522 * Make a copy of an object.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2523 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2524 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2525 copy_object(typval_T *from, typval_T *to)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2526 {
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
2527 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
2528 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
2529 else
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
2530 {
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
2531 to->vval.v_object = from->vval.v_object;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2532 ++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
2533 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2534 }
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 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2537 * Free an object.
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 static void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2540 object_clear(object_T *obj)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2541 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2542 // Avoid a recursive call, it can happen if "obj" has a circular reference.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2543 obj->obj_refcount = INT_MAX;
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 class_T *cl = obj->obj_class;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2546
32792
ba5a67216596 patch 9.0.1712: missing null check in object_clear()
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
2547 if (!cl)
33006
29b2193466e0 patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
2548 return;
32792
ba5a67216596 patch 9.0.1712: missing null check in object_clear()
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
2549
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2550 // the member values are just after the object structure
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2551 typval_T *tv = (typval_T *)(obj + 1);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2552 for (int i = 0; i < cl->class_obj_member_count; ++i)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2553 clear_tv(tv + i);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2554
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2555 // Remove from the list headed by "first_object".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2556 object_cleared(obj);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2557
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2558 vim_free(obj);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2559 class_unref(cl);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2560 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2561
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 * Unreference an object.
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 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2566 object_unref(object_T *obj)
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 if (obj != NULL && --obj->obj_refcount <= 0)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2569 object_clear(obj);
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
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 * Make a copy of a class.
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 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2576 copy_class(typval_T *from, typval_T *to)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2577 {
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
2578 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
2579 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
2580 else
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
2581 {
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
2582 to->vval.v_class = from->vval.v_class;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2583 ++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
2584 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2585 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2586
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2587 /*
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2588 * 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
2589 */
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2590 static void
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2591 class_free(class_T *cl)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2592 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2593 // 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
2594 // 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
2595 // be freed.
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2596 VIM_CLEAR(cl->class_name);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2597
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2598 class_unref(cl->class_extends);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2599
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2600 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
2601 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2602 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
2603 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
2604 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
2605 }
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2606 vim_free(cl->class_interfaces);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2607 vim_free(cl->class_interfaces_cl);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2608
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2609 itf2class_T *next;
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2610 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
2611 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2612 next = i2c->i2c_next;
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2613 vim_free(i2c);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2614 }
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2615
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2616 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
2617 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2618 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
2619 vim_free(m->ocm_name);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2620 vim_free(m->ocm_init);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2621 if (cl->class_members_tv != NULL)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2622 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
2623 }
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2624 vim_free(cl->class_class_members);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2625 vim_free(cl->class_members_tv);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2626
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2627 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
2628 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2629 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
2630 vim_free(m->ocm_name);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2631 vim_free(m->ocm_init);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2632 }
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2633 vim_free(cl->class_obj_members);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2634
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2635 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
2636 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2637 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
2638 func_clear_free(uf, FALSE);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2639 }
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2640 vim_free(cl->class_class_functions);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2641
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2642 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
2643 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2644 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
2645 func_clear_free(uf, FALSE);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2646 }
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2647 vim_free(cl->class_obj_methods);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2648
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2649 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
2650
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2651 class_cleared(cl);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2652
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2653 vim_free(cl);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2654 }
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2655
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2656 /*
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2657 * 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
2658 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2659 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2660 class_unref(class_T *cl)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2661 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2662 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
2663 class_free(cl);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2664 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2665
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2666 /*
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2667 * 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
2668 */
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2669 int
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2670 class_free_nonref(int copyID)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2671 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2672 int did_free = FALSE;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2673
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2674 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
2675 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2676 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
2677 if ((cl->class_copyID & COPYID_MASK) != (copyID & COPYID_MASK))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2678 {
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2679 // 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
2680 class_free(cl);
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2681 did_free = TRUE;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2682 }
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2683 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2684
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2685 next_nonref_class = NULL;
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2686 return did_free;
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2687 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2688
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2689 int
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2690 set_ref_in_classes(int copyID)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2691 {
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2692 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
2693 set_ref_in_item_class(cl, copyID, NULL, NULL);
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2694
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33119
diff changeset
2695 return FALSE;
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2696 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2697
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2698 static object_T *first_object = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2699
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2700 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2701 * 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
2702 * list headed by "first_object".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2703 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2704 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2705 object_created(object_T *obj)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2706 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2707 if (first_object != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2708 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2709 obj->obj_next_used = first_object;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2710 first_object->obj_prev_used = obj;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2711 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2712 first_object = obj;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2713 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2714
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2715 static object_T *next_nonref_obj = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2716
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2717 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2718 * 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
2719 * It is removed from the list headed by "first_object".
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2720 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2721 void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2722 object_cleared(object_T *obj)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2723 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2724 if (obj->obj_next_used != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2725 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
2726 if (obj->obj_prev_used != NULL)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2727 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
2728 else if (first_object == obj)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2729 first_object = obj->obj_next_used;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2730
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2731 // update the next object to check if needed
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2732 if (obj == next_nonref_obj)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2733 next_nonref_obj = obj->obj_next_used;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2734 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2735
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2736 /*
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2737 * 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
2738 */
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2739 int
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2740 object_free_nonref(int copyID)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2741 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2742 int did_free = FALSE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2743
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2744 for (object_T *obj = first_object; obj != NULL; obj = next_nonref_obj)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2745 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2746 next_nonref_obj = obj->obj_next_used;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2747 if ((obj->obj_copyID & COPYID_MASK) != (copyID & COPYID_MASK))
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2748 {
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2749 // Free the object and items it contains.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2750 object_clear(obj);
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2751 did_free = TRUE;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2752 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2753 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2754
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2755 next_nonref_obj = NULL;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2756 return did_free;
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2757 }
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2758
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2759 /*
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2760 * 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
2761 */
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2762 void
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2763 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
2764 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2765 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
2766 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
2767 && (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
2768 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2769 // 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
2770 if (*name == '_')
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2771 semsg(_(e_cannot_access_private_method_str), method_name);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2772 else
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
2773 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
2774 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
2775 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2776 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
2777 && (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
2778 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2779 // 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
2780 if (*name == '_')
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2781 semsg(_(e_cannot_access_private_method_str), method_name);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2782 else
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
2783 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
2784 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
2785 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2786 else
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2787 semsg(_(e_method_not_found_on_class_str_str), cl->class_name,
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2788 method_name);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2789 vim_free(method_name);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2790 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2791
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2792 /*
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2793 * 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
2794 */
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2795 void
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2796 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
2797 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2798 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
2799
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2800 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
2801 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2802 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
2803 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
2804 varname, cl->class_name);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2805 else
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
2806 semsg(_(e_variable_not_found_on_object_str_str), cl->class_name,
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2807 varname);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2808 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2809 else
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2810 {
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2811 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
2812 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
2813 varname, cl->class_name);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2814 else
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
2815 semsg(_(e_class_variable_str_not_found_in_class_str),
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2816 varname, cl->class_name);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2817 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2818 vim_free(varname);
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2819 }
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2820
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33246
diff changeset
2821 /*
33006
29b2193466e0 patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
2822 * 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
2823 * 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
2824 */
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2825 int
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2826 class_instance_of(class_T *cl, class_T *other_cl)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2827 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2828 if (cl == other_cl)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2829 return TRUE;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2830
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2831 // Recursively check the base classes.
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2832 for (; cl != NULL; cl = cl->class_extends)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2833 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2834 if (cl == other_cl)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2835 return TRUE;
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
2836 // Check the implemented interfaces and the super interfaces
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2837 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
2838 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
2839 class_T *intf = cl->class_interfaces_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
2840 while (intf != NULL)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
2841 {
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
2842 if (intf == other_cl)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
2843 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
2844 // check the super interfaces
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
2845 intf = intf->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
2846 }
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33268
diff changeset
2847 }
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2848 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2849
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2850 return FALSE;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2851 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2852
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2853 /*
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2854 * "instanceof(object, classinfo)" function
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2855 */
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2856 void
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2857 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
2858 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2859 typval_T *object_tv = &argvars[0];
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2860 typval_T *classinfo_tv = &argvars[1];
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2861 listitem_T *li;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2862
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2863 rettv->vval.v_number = VVAL_FALSE;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2864
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2865 if (check_for_object_arg(argvars, 0) == FAIL
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2866 || check_for_class_or_list_arg(argvars, 1) == FAIL)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2867 return;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2868
33291
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
2869 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
2870 return;
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
2871
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2872 if (classinfo_tv->v_type == VAR_LIST)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2873 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2874 FOR_ALL_LIST_ITEMS(classinfo_tv->vval.v_list, li)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2875 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2876 if (li->li_tv.v_type != VAR_CLASS)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2877 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2878 emsg(_(e_class_required));
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2879 return;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2880 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2881
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2882 if (class_instance_of(object_tv->vval.v_object->obj_class,
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2883 li->li_tv.vval.v_class) == TRUE)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2884 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2885 rettv->vval.v_number = VVAL_TRUE;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2886 return;
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2887 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2888 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2889 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2890 else if (classinfo_tv->v_type == VAR_CLASS)
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2891 {
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2892 rettv->vval.v_number = class_instance_of(object_tv->vval.v_object->obj_class,
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2893 classinfo_tv->vval.v_class);
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2894 }
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
2895 }
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2896
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2897 #endif // FEAT_EVAL