annotate src/vim9class.c @ 31487:df58407c97f3 v9.0.1076

patch 9.0.1076: ASAN complains about NULL argument Commit: https://github.com/vim/vim/commit/8efdcee02ed02cf9e51e1757441715c2479757ee Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 19 12:18:09 2022 +0000 patch 9.0.1076: ASAN complains about NULL argument Problem: ASAN complains about NULL argument. Solution: Skip memmove() when there is nothing to move.
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Dec 2022 13:30:08 +0100
parents 1bebc2093e6b
children 560ba934725f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * vim9class.c: Vim9 script class support
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #define USING_FLOAT_STUFF
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 // When not generating protos this is included in proto.h
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 #ifdef PROTO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 # include "vim9.h"
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 #endif
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 /*
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
25 * Parse a member declaration, both object and class member.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
26 * Returns OK or FAIL. When OK then "varname_end" is set to just after the
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
27 * variable name and "type_ret" is set to the decleared or detected type.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
28 * "init_expr" is set to the initialisation expression (allocated), if there is
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
29 * one.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
30 */
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
31 static int
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
32 parse_member(
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
33 exarg_T *eap,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
34 char_u *line,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
35 char_u *varname,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
36 int has_public, // TRUE if "public" seen before "varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
37 char_u **varname_end,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
38 garray_T *type_list,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
39 type_T **type_ret,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
40 char_u **init_expr)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
41 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
42 *varname_end = to_name_end(varname, FALSE);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
43 if (*varname == '_' && has_public)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
44 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
45 semsg(_(e_public_member_name_cannot_start_with_underscore_str), line);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
46 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
47 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
48
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
49 char_u *colon = skipwhite(*varname_end);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
50 char_u *type_arg = colon;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
51 type_T *type = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
52 if (*colon == ':')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
53 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
54 if (VIM_ISWHITE(**varname_end))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
55 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
56 semsg(_(e_no_white_space_allowed_before_colon_str), varname);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
57 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
58 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
59 if (!VIM_ISWHITE(colon[1]))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
60 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
61 semsg(_(e_white_space_required_after_str_str), ":", varname);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
62 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
63 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
64 type_arg = skipwhite(colon + 1);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
65 type = parse_type(&type_arg, type_list, TRUE);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
66 if (type == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
67 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
68 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
69
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
70 char_u *expr_start = skipwhite(type_arg);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
71 char_u *expr_end = expr_start;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
72 if (type == NULL && *expr_start != '=')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
73 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
74 emsg(_(e_type_or_initialization_required));
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
75 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
76 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
77
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
78 if (*expr_start == '=')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
79 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
80 if (!VIM_ISWHITE(expr_start[-1]) || !VIM_ISWHITE(expr_start[1]))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
81 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
82 semsg(_(e_white_space_required_before_and_after_str_at_str),
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
83 "=", type_arg);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
84 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
85 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
86 expr_start = skipwhite(expr_start + 1);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
87
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
88 expr_end = expr_start;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
89 evalarg_T evalarg;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
90 fill_evalarg_from_eap(&evalarg, eap, FALSE);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
91 skip_expr(&expr_end, NULL);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
92
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
93 if (type == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
94 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
95 // No type specified, use the type of the initializer.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
96 typval_T tv;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
97 tv.v_type = VAR_UNKNOWN;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
98 char_u *expr = expr_start;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
99 int res = eval0(expr, &tv, eap, &evalarg);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
100
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
101 if (res == OK)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
102 type = typval2type(&tv, get_copyID(), type_list,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
103 TVTT_DO_MEMBER);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
104 if (type == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
105 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
106 semsg(_(e_cannot_get_object_member_type_from_initializer_str),
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
107 expr_start);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
108 clear_evalarg(&evalarg, NULL);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
109 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
110 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
111 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
112 clear_evalarg(&evalarg, NULL);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
113 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
114 if (!valid_declaration_type(type))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
115 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
116
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
117 *type_ret = type;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
118 if (expr_end > expr_start)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
119 *init_expr = vim_strnsave(expr_start, expr_end - expr_start);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
120 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
121 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
122
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
123 /*
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
124 * Add a member to an object or a class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
125 * Returns OK when successful, "init_expr" will be consumed then.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
126 * Returns FAIL otherwise, caller might need to free "init_expr".
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
127 */
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
128 static int
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
129 add_member(
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
130 garray_T *gap,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
131 char_u *varname,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
132 char_u *varname_end,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
133 int has_public,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
134 type_T *type,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
135 char_u *init_expr)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
136 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
137 if (ga_grow(gap, 1) == FAIL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
138 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
139 ocmember_T *m = ((ocmember_T *)gap->ga_data) + gap->ga_len;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
140 m->ocm_name = vim_strnsave(varname, varname_end - varname);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
141 m->ocm_access = has_public ? ACCESS_ALL
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
142 : *varname == '_' ? ACCESS_PRIVATE : ACCESS_READ;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
143 m->ocm_type = type;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
144 if (init_expr != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
145 m->ocm_init = init_expr;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
146 ++gap->ga_len;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
147 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
148 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
149
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
150 /*
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
151 * Move the class or object members found while parsing a class into the class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
152 * "gap" contains the found members.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
153 * "members" will be set to the newly allocated array of members and
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
154 * "member_count" set to the number of members.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
155 * Returns OK or FAIL.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
156 */
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
157 static int
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
158 add_members_to_class(
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
159 garray_T *gap,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
160 ocmember_T **members,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
161 int *member_count)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
162 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
163 *member_count = gap->ga_len;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
164 *members = gap->ga_len == 0 ? NULL : ALLOC_MULT(ocmember_T, gap->ga_len);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
165 if (gap->ga_len > 0 && *members == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
166 return FAIL;
31487
df58407c97f3 patch 9.0.1076: ASAN complains about NULL argument
Bram Moolenaar <Bram@vim.org>
parents: 31483
diff changeset
167 if (gap->ga_len > 0)
df58407c97f3 patch 9.0.1076: ASAN complains about NULL argument
Bram Moolenaar <Bram@vim.org>
parents: 31483
diff changeset
168 mch_memmove(*members, gap->ga_data, sizeof(ocmember_T) * gap->ga_len);
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
169 VIM_CLEAR(gap->ga_data);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
170 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
171 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
172
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
173 /*
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 * Handle ":class" and ":abstract class" up to ":endclass".
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 ex_class(exarg_T *eap)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 {
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
179 if (!current_script_is_vim9()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
180 || (cmdmod.cmod_flags & CMOD_LEGACY)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
181 || !getline_equal(eap->getline, eap->cookie, getsourceline))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
182 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
183 emsg(_(e_class_can_only_be_defined_in_vim9_script));
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
184 return;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
185 }
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 char_u *arg = eap->arg;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
188 int is_abstract = eap->cmdidx == CMD_abstract;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 if (is_abstract)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 if (STRNCMP(arg, "class", 5) != 0 || !VIM_ISWHITE(arg[5]))
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 semsg(_(e_invalid_argument_str), arg);
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 return;
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 arg = skipwhite(arg + 5);
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 if (!ASCII_ISUPPER(*arg))
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 semsg(_(e_class_name_must_start_with_uppercase_letter_str), arg);
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 return;
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
204 char_u *name_end = find_name_end(arg, NULL, NULL, FNE_CHECK_START);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
205 if (!IS_WHITE_OR_NUL(*name_end))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
206 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
207 semsg(_(e_white_space_required_after_class_name_str), arg);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
208 return;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
209 }
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 // TODO:
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
212 // generics: <Tkey, Tentry>
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 // extends SomeClass
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 // implements SomeInterface
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 // specifies SomeInterface
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
216 // check that nothing follows
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
217 // handle "is_export" if it is set
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
218
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
219 garray_T type_list; // list of pointers to allocated types
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
220 ga_init2(&type_list, sizeof(type_T *), 10);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
221
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
222 // Growarray with class members declared in the class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
223 garray_T classmembers;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
224 ga_init2(&classmembers, sizeof(ocmember_T), 10);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
225
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
226 // Growarray with object methods declared in the class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
227 garray_T classmethods;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
228 ga_init2(&classmethods, sizeof(ufunc_T *), 10);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
229
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
230 // Growarray with object members declared in the class.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
231 garray_T objmembers;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
232 ga_init2(&objmembers, sizeof(ocmember_T), 10);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
233
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
234 // Growarray with object methods declared in the class.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
235 garray_T objmethods;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
236 ga_init2(&objmethods, sizeof(ufunc_T *), 10);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
237
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
238 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
239 * Go over the body of the class until "endclass" is found.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
240 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
241 char_u *theline = NULL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
242 int success = FALSE;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
243 for (;;)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
244 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
245 vim_free(theline);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
246 theline = eap->getline(':', eap->cookie, 0, GETLINE_CONCAT_ALL);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
247 if (theline == NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
248 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
249 char_u *line = skipwhite(theline);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
250
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
251 char_u *p = line;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
252 if (checkforcmd(&p, "endclass", 4))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
253 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
254 if (STRNCMP(line, "endclass", 8) != 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
255 semsg(_(e_command_cannot_be_shortened_str), line);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
256 else if (*p == '|' || !ends_excmd2(line, p))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
257 semsg(_(e_trailing_characters_str), p);
31408
c82cb53474ee patch 9.0.1037: lalloc(0) error for a class without members
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
258 else
c82cb53474ee patch 9.0.1037: lalloc(0) error for a class without members
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
259 success = TRUE;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
260 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
261 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
262
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
263 int has_public = FALSE;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
264 if (checkforcmd(&p, "public", 3))
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
265 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
266 if (STRNCMP(line, "public", 6) != 0)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
267 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
268 semsg(_(e_command_cannot_be_shortened_str), line);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
269 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
270 }
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
271 has_public = TRUE;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
272 p = skipwhite(line + 6);
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
273
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
274 if (STRNCMP(p, "this", 4) != 0 && STRNCMP(p, "static", 6) != 0)
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
275 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
276 emsg(_(e_public_must_be_followed_by_this_or_static));
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
277 break;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
278 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
279 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
280
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
281 // object members (public, read access, private):
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
282 // "this._varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
283 // "this.varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
284 // "public this.varname"
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
285 if (STRNCMP(p, "this", 4) == 0)
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
286 {
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
287 if (p[4] != '.' || !eval_isnamec1(p[5]))
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
288 {
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
289 semsg(_(e_invalid_object_member_declaration_str), p);
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
290 break;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
291 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
292 char_u *varname = p + 5;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
293 char_u *varname_end = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
294 type_T *type = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
295 char_u *init_expr = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
296 if (parse_member(eap, line, varname, has_public,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
297 &varname_end, &type_list, &type, &init_expr) == FAIL)
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
298 break;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
299 if (add_member(&objmembers, varname, varname_end,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
300 has_public, type, init_expr) == FAIL)
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
301 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
302 vim_free(init_expr);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
303 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
304 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
305 }
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
306
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
307 // class members and methods
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
308 else if (checkforcmd(&p, "static", 6))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
309 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
310 p = skipwhite(p);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
311 if (checkforcmd(&p, "def", 3))
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
312 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
313 // TODO: class method
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
314 // static def someMethod()
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
315 // enddef
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
316 // static def <Tval> someMethod()
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
317 // enddef
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
318 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
319 else
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
320 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
321 // class members (public, read access, private):
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
322 // "static _varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
323 // "static varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
324 // "public static varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
325 char_u *varname = p;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
326 char_u *varname_end = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
327 type_T *type = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
328 char_u *init_expr = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
329 if (parse_member(eap, line, varname, has_public,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
330 &varname_end, &type_list, &type, &init_expr) == FAIL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
331 break;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
332 if (add_member(&classmembers, varname, varname_end,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
333 has_public, type, init_expr) == FAIL)
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
334 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
335 vim_free(init_expr);
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
336 break;
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
337 }
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
338 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
339 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
340
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
341 // constructors:
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
342 // def new()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
343 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
344 // def newOther()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
345 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
346 // methods:
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
347 // def someMethod()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
348 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
349 // TODO:
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
350 // def <Tval> someMethod()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
351 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
352 else if (checkforcmd(&p, "def", 3))
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
353 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
354 exarg_T ea;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
355 garray_T lines_to_free;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
356
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
357 CLEAR_FIELD(ea);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
358 ea.cmd = line;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
359 ea.arg = p;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
360 ea.cmdidx = CMD_def;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
361 ea.getline = eap->getline;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
362 ea.cookie = eap->cookie;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
363
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
364 ga_init2(&lines_to_free, sizeof(char_u *), 50);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
365 ufunc_T *uf = define_function(&ea, NULL, &lines_to_free, TRUE);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
366 ga_clear_strings(&lines_to_free);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
367
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
368 // TODO: how about errors?
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
369 if (uf != NULL && ga_grow(&objmethods, 1) == OK)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
370 {
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
371 if (STRNCMP(uf->uf_name, "new", 3) == 0)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
372 uf->uf_flags |= FC_NEW;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
373
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
374 ((ufunc_T **)objmethods.ga_data)[objmethods.ga_len] = uf;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
375 ++objmethods.ga_len;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
376 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
377 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
378
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
379 else
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
380 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
381 semsg(_(e_not_valid_command_in_class_str), line);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
382 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
383 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
384 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
385 vim_free(theline);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
386
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
387 class_T *cl = NULL;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
388 if (success)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
389 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
390 // "endclass" encountered without failures: Create the class.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
391
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
392 cl = ALLOC_CLEAR_ONE(class_T);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
393 if (cl == NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
394 goto cleanup;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
395 cl->class_refcount = 1;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
396 cl->class_name = vim_strnsave(arg, name_end - arg);
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
397 if (cl->class_name == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
398 goto cleanup;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
400 // Add class and object members to "cl".
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
401 if (add_members_to_class(&classmembers,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
402 &cl->class_class_members,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
403 &cl->class_class_member_count) == FAIL
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
404 || add_members_to_class(&objmembers,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
405 &cl->class_obj_members,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
406 &cl->class_obj_member_count) == FAIL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
407 goto cleanup;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
408
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
409 if (cl->class_class_member_count > 0)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
410 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
411 // Allocate a typval for each class member and initialize it.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
412 cl->class_members_tv = ALLOC_CLEAR_MULT(typval_T,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
413 cl->class_class_member_count);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
414 if (cl->class_members_tv != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
415 for (int i = 0; i < cl->class_class_member_count; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
416 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
417 ocmember_T *m = &cl->class_class_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
418 typval_T *tv = &cl->class_members_tv[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
419 if (m->ocm_init != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
420 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
421 typval_T *etv = eval_expr(m->ocm_init, eap);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
422 if (etv != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
423 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
424 *tv = *etv;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
425 vim_free(etv);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
426 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
427 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
428 else
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
429 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
430 // TODO: proper default value
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
431 tv->v_type = m->ocm_type->tt_type;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
432 tv->vval.v_string = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
433 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
434 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
435 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
436
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
437 int have_new = FALSE;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
438 for (int i = 0; i < objmethods.ga_len; ++i)
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
439 if (STRCMP(((ufunc_T **)objmethods.ga_data)[i]->uf_name,
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
440 "new") == 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
441 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
442 have_new = TRUE;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
443 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
444 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
445 if (!have_new)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
446 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
447 // No new() method was defined, add the default constructor.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
448 garray_T fga;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
449 ga_init2(&fga, 1, 1000);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
450 ga_concat(&fga, (char_u *)"new(");
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
451 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
452 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
453 if (i > 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
454 ga_concat(&fga, (char_u *)", ");
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
455 ga_concat(&fga, (char_u *)"this.");
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
456 ocmember_T *m = cl->class_obj_members + i;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
457 ga_concat(&fga, (char_u *)m->ocm_name);
31441
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31424
diff changeset
458 ga_concat(&fga, (char_u *)" = v:none");
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
459 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
460 ga_concat(&fga, (char_u *)")\nenddef\n");
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
461 ga_append(&fga, NUL);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
462
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
463 exarg_T fea;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
464 CLEAR_FIELD(fea);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
465 fea.cmdidx = CMD_def;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
466 fea.cmd = fea.arg = fga.ga_data;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
467
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
468 garray_T lines_to_free;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
469 ga_init2(&lines_to_free, sizeof(char_u *), 50);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
470
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
471 ufunc_T *nf = define_function(&fea, NULL, &lines_to_free, TRUE);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
472
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
473 ga_clear_strings(&lines_to_free);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
474 vim_free(fga.ga_data);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
475
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
476 if (nf != NULL && ga_grow(&objmethods, 1) == OK)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
477 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
478 ((ufunc_T **)objmethods.ga_data)[objmethods.ga_len] = nf;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
479 ++objmethods.ga_len;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
480
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
481 nf->uf_flags |= FC_NEW;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
482 nf->uf_ret_type = get_type_ptr(&type_list);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
483 if (nf->uf_ret_type != NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
484 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
485 nf->uf_ret_type->tt_type = VAR_OBJECT;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
486 nf->uf_ret_type->tt_member = (type_T *)cl;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
487 nf->uf_ret_type->tt_argcount = 0;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
488 nf->uf_ret_type->tt_args = NULL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
489 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
490 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
491 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
492
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
493 // TODO: class methods
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
494 cl->class_obj_method_count = objmethods.ga_len;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
495 cl->class_obj_methods = ALLOC_MULT(ufunc_T *, objmethods.ga_len);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
496 if (cl->class_obj_methods == NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
497 goto cleanup;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
498 mch_memmove(cl->class_obj_methods, objmethods.ga_data,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
499 sizeof(ufunc_T *) * objmethods.ga_len);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
500 vim_free(objmethods.ga_data);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
501
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
502 // Set the class pointer on all the object methods.
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
503 for (int i = 0; i < objmethods.ga_len; ++i)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
504 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
505 ufunc_T *fp = cl->class_obj_methods[i];
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
506 fp->uf_class = cl;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
507 fp->uf_flags |= FC_OBJECT; // TODO: not for class method
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
508 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
509
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
510 cl->class_type.tt_type = VAR_CLASS;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
511 cl->class_type.tt_member = (type_T *)cl;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
512 cl->class_object_type.tt_type = VAR_OBJECT;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
513 cl->class_object_type.tt_member = (type_T *)cl;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
514 cl->class_type_list = type_list;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
515
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
516 // TODO:
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
517 // - Fill hashtab with object members and methods ?
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
518
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
519 // Add the class to the script-local variables.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
520 typval_T tv;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
521 tv.v_type = VAR_CLASS;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
522 tv.vval.v_class = cl;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
523 set_var_const(cl->class_name, current_sctx.sc_sid,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
524 NULL, &tv, FALSE, ASSIGN_DECL, 0);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
525 return;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
526 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
527
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
528 cleanup:
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
529 if (cl != NULL)
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
530 {
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
531 vim_free(cl->class_name);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
532 vim_free(cl->class_obj_members);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
533 vim_free(cl->class_obj_methods);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
534 vim_free(cl);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
535 }
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
536
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
537 for (int round = 1; round <= 2; ++round)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
538 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
539 garray_T *gap = round == 1 ? &classmembers : &objmembers;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
540 if (gap->ga_len == 0 || gap->ga_data == NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
541 continue;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
542
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
543 for (int i = 0; i < gap->ga_len; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
544 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
545 ocmember_T *m = ((ocmember_T *)gap->ga_data) + i;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
546 vim_free(m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
547 vim_free(m->ocm_init);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
548 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
549 ga_clear(gap);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
550 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
551
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
552 for (int i = 0; i < objmethods.ga_len; ++i)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
553 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
554 ufunc_T *uf = ((ufunc_T **)objmethods.ga_data)[i];
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
555 func_clear_free(uf, FALSE);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
556 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
557 ga_clear(&objmethods);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
558 clear_type_list(&type_list);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
559 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
560
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
561 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
562 * Find member "name" in class "cl" and return its type.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
563 * When not found t_any is returned.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
564 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
565 type_T *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
566 class_member_type(
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
567 class_T *cl,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
568 char_u *name,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
569 char_u *name_end,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
570 int *member_idx)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
571 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
572 *member_idx = -1; // not found (yet)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
573 size_t len = name_end - name;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
574
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
575 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
576 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
577 ocmember_T *m = cl->class_obj_members + i;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
578 if (STRNCMP(m->ocm_name, name, len) == 0 && m->ocm_name[len] == NUL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
579 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
580 *member_idx = i;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
581 return m->ocm_type;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
582 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
583 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
584 return &t_any;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 * Handle ":interface" up to ":endinterface".
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 ex_interface(exarg_T *eap UNUSED)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 * Handle ":enum" up to ":endenum".
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 ex_enum(exarg_T *eap UNUSED)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 * Handle ":type".
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 ex_type(exarg_T *eap UNUSED)
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
614 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
615 * Evaluate what comes after a class:
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
616 * - class member: SomeClass.varname
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
617 * - class method: SomeClass.SomeMethod()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
618 * - class constructor: SomeClass.new()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
619 * - object member: someObject.varname
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
620 * - object method: someObject.SomeMethod()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
621 *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
622 * "*arg" points to the '.'.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
623 * "*arg" is advanced to after the member name or method call.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
624 *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
625 * Returns FAIL or OK.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
626 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
627 int
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
628 class_object_index(
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
629 char_u **arg,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
630 typval_T *rettv,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
631 evalarg_T *evalarg,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
632 int verbose UNUSED) // give error messages
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
633 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
634 // int evaluate = evalarg != NULL
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
635 // && (evalarg->eval_flags & EVAL_EVALUATE);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
636
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
637 if (VIM_ISWHITE((*arg)[1]))
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
638 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
639 semsg(_(e_no_white_space_allowed_after_str_str), ".", *arg);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
640 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
641 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
642
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
643 ++*arg;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
644 char_u *name = *arg;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
645 char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
646 if (name_end == name)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
647 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
648 size_t len = name_end - name;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
649
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
650 class_T *cl = rettv->v_type == VAR_CLASS ? rettv->vval.v_class
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
651 : rettv->vval.v_object->obj_class;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
652 if (*name_end == '(')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
653 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
654 for (int i = 0; i < cl->class_obj_method_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
655 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
656 ufunc_T *fp = cl->class_obj_methods[i];
31418
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
657 // Use a separate pointer to avoid that ASAN complains about
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
658 // uf_name[] only being 4 characters.
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
659 char_u *ufname = (char_u *)fp->uf_name;
462508d04341 patch 9.0.1042: ASAN gives false alarm about array access.
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
660 if (STRNCMP(name, ufname, len) == 0 && ufname[len] == NUL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
661 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
662 typval_T argvars[MAX_FUNC_ARGS + 1];
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
663 int argcount = 0;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
664
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
665 char_u *argp = name_end;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
666 int ret = get_func_arguments(&argp, evalarg, 0,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
667 argvars, &argcount);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
668 if (ret == FAIL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
669 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
670
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
671 funcexe_T funcexe;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
672 CLEAR_FIELD(funcexe);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
673 funcexe.fe_evaluate = TRUE;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
674 if (rettv->v_type == VAR_OBJECT)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
675 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
676 funcexe.fe_object = rettv->vval.v_object;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
677 ++funcexe.fe_object->obj_refcount;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
678 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
679
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
680 // Clear the class or object after calling the function, in
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
681 // case the refcount is one.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
682 typval_T tv_tofree = *rettv;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
683 rettv->v_type = VAR_UNKNOWN;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
684
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
685 // Call the user function. Result goes into rettv;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
686 int error = call_user_func_check(fp, argcount, argvars,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
687 rettv, &funcexe, NULL);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
688
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
689 // Clear the previous rettv and the arguments.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
690 clear_tv(&tv_tofree);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
691 for (int idx = 0; idx < argcount; ++idx)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
692 clear_tv(&argvars[idx]);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
693
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
694 if (error != FCERR_NONE)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
695 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
696 user_func_error(error, printable_func_name(fp),
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
697 funcexe.fe_found_var);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
698 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
699 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
700 *arg = argp;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
701 return OK;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
702 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
703 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
704
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
705 semsg(_(e_method_not_found_on_class_str_str), cl->class_name, name);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
706 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
707
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
708 else if (rettv->v_type == VAR_OBJECT)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
709 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
710 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
711 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
712 ocmember_T *m = &cl->class_obj_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
713 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
714 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
715 if (*name == '_')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
716 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
717 semsg(_(e_cannot_access_private_member_str), m->ocm_name);
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
718 return FAIL;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
719 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
720
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
721 // The object only contains a pointer to the class, the member
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
722 // values array follows right after that.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
723 object_T *obj = rettv->vval.v_object;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
724 typval_T *tv = (typval_T *)(obj + 1) + i;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
725 copy_tv(tv, rettv);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
726 object_unref(obj);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
727
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
728 *arg = name_end;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
729 return OK;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
730 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
731 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
732
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
733 semsg(_(e_member_not_found_on_object_str_str), cl->class_name, name);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
734 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
735
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
736 else if (rettv->v_type == VAR_CLASS)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
737 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
738 // class member
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
739 for (int i = 0; i < cl->class_class_member_count; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
740 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
741 ocmember_T *m = &cl->class_class_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
742 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
743 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
744 if (*name == '_')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
745 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
746 semsg(_(e_cannot_access_private_member_str), m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
747 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
748 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
749
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
750 typval_T *tv = &cl->class_members_tv[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
751 copy_tv(tv, rettv);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
752 class_unref(cl);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
753
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
754 *arg = name_end;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
755 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
756 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
757 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
758
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
759 semsg(_(e_member_not_found_on_class_str_str), cl->class_name, name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
760 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
761
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
762 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
763 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
764
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
765 /*
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
766 * If "arg" points to a class or object method, return it.
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
767 * Otherwise return NULL.
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
768 */
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
769 ufunc_T *
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
770 find_class_func(char_u **arg)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
771 {
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
772 char_u *name = *arg;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
773 char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START);
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
774 if (name_end == name || *name_end != '.')
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
775 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
776
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
777 size_t len = name_end - name;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
778 typval_T tv;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
779 tv.v_type = VAR_UNKNOWN;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
780 if (eval_variable(name, len, 0, &tv, NULL, EVAL_VAR_NOAUTOLOAD) == FAIL)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
781 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
782 if (tv.v_type != VAR_CLASS && tv.v_type != VAR_OBJECT)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
783 goto fail_after_eval;
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
784
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
785 class_T *cl = tv.v_type == VAR_CLASS ? tv.vval.v_class
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
786 : tv.vval.v_object->obj_class;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
787 if (cl == NULL)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
788 goto fail_after_eval;
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
789 char_u *fname = name_end + 1;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
790 char_u *fname_end = find_name_end(fname, NULL, NULL, FNE_CHECK_START);
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
791 if (fname_end == fname)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
792 goto fail_after_eval;
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
793 len = fname_end - fname;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
794
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
795 for (int i = 0; i < cl->class_obj_method_count; ++i)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
796 {
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
797 ufunc_T *fp = cl->class_obj_methods[i];
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
798 // Use a separate pointer to avoid that ASAN complains about
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
799 // uf_name[] only being 4 characters.
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
800 char_u *ufname = (char_u *)fp->uf_name;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
801 if (STRNCMP(fname, ufname, len) == 0 && ufname[len] == NUL)
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
802 {
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
803 clear_tv(&tv);
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
804 return fp;
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
805 }
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
806 }
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
807
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
808 fail_after_eval:
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
809 clear_tv(&tv);
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
810 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
811 }
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
812
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
813 /*
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
814 * Make a copy of an object.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
815 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
816 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
817 copy_object(typval_T *from, typval_T *to)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
818 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
819 *to = *from;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
820 if (to->vval.v_object != NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
821 ++to->vval.v_object->obj_refcount;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
822 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
823
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
824 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
825 * Free an object.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
826 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
827 static void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
828 object_clear(object_T *obj)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
829 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
830 class_T *cl = obj->obj_class;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
831
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
832 // the member values are just after the object structure
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
833 typval_T *tv = (typval_T *)(obj + 1);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
834 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
835 clear_tv(tv + i);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
836
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
837 // Remove from the list headed by "first_object".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
838 object_cleared(obj);
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
839
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
840 vim_free(obj);
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
841 class_unref(cl);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
842 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
843
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
844 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
845 * Unreference an object.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
846 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
847 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
848 object_unref(object_T *obj)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
849 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
850 if (obj != NULL && --obj->obj_refcount <= 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
851 object_clear(obj);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
852 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
853
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
854 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
855 * Make a copy of a class.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
856 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
857 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
858 copy_class(typval_T *from, typval_T *to)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
859 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
860 *to = *from;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
861 if (to->vval.v_class != NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
862 ++to->vval.v_class->class_refcount;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
863 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
864
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
865 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
866 * Unreference a class. Free it when the reference count goes down to zero.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
867 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
868 void
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
869 class_unref(class_T *cl)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
870 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
871 if (cl != NULL && --cl->class_refcount <= 0 && cl->class_name != NULL)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
872 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
873 // Freeing what the class contains may recursively come back here.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
874 // Clear "class_name" first, if it is NULL the class does not need to
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
875 // be freed.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
876 VIM_CLEAR(cl->class_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
877
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
878 for (int i = 0; i < cl->class_class_member_count; ++i)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
879 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
880 ocmember_T *m = &cl->class_class_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
881 vim_free(m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
882 vim_free(m->ocm_init);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
883 if (cl->class_members_tv != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
884 clear_tv(&cl->class_members_tv[i]);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
885 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
886 vim_free(cl->class_class_members);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
887 vim_free(cl->class_members_tv);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
888
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
889 for (int i = 0; i < cl->class_obj_member_count; ++i)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
890 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
891 ocmember_T *m = &cl->class_obj_members[i];
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
892 vim_free(m->ocm_name);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
893 vim_free(m->ocm_init);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
894 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
895 vim_free(cl->class_obj_members);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
896
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
897 for (int i = 0; i < cl->class_obj_method_count; ++i)
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
898 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
899 ufunc_T *uf = cl->class_obj_methods[i];
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
900 func_clear_free(uf, FALSE);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
901 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
902 vim_free(cl->class_obj_methods);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
903
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
904 clear_type_list(&cl->class_type_list);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
905
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
906 vim_free(cl);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
907 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
908 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
909
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
910 static object_T *first_object = NULL;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
911
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
912 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
913 * Call this function when an object has been created. It will be added to the
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
914 * list headed by "first_object".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
915 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
916 void
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
917 object_created(object_T *obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
918 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
919 if (first_object != NULL)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
920 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
921 obj->obj_next_used = first_object;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
922 first_object->obj_prev_used = obj;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
923 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
924 first_object = obj;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
925 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
926
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
927 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
928 * Call this function when an object has been cleared and is about to be freed.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
929 * It is removed from the list headed by "first_object".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
930 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
931 void
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
932 object_cleared(object_T *obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
933 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
934 if (obj->obj_next_used != NULL)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
935 obj->obj_next_used->obj_prev_used = obj->obj_prev_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
936 if (obj->obj_prev_used != NULL)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
937 obj->obj_prev_used->obj_next_used = obj->obj_next_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
938 else if (first_object == obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
939 first_object = obj->obj_next_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
940 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
941
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
942 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
943 * Go through the list of all objects and free items without "copyID".
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
944 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
945 int
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
946 object_free_nonref(int copyID)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
947 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
948 int did_free = FALSE;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
949 object_T *next_obj;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
950
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
951 for (object_T *obj = first_object; obj != NULL; obj = next_obj)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
952 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
953 next_obj = obj->obj_next_used;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
954 if ((obj->obj_copyID & COPYID_MASK) != (copyID & COPYID_MASK))
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
955 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
956 // Free the object and items it contains.
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
957 object_clear(obj);
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
958 did_free = TRUE;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
959 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
960 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
961
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
962 return did_free;
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
963 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
964
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 #endif // FEAT_EVAL