annotate src/vim9class.c @ 33006:29b2193466e0 v9.0.1795

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