annotate src/vim9class.c @ 31582:8bbc932fbd09 v9.0.1123

patch 9.0.1123: class function not implemented yet Commit: https://github.com/vim/vim/commit/6bafdd41cbf8c06bc00f19dcf4e1c8292460b4dd Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 1 12:58:33 2023 +0000 patch 9.0.1123: class function not implemented yet Problem: Class function not implemented yet. Solution: Implement defining and calling a class function.
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 Jan 2023 14:00:07 +0100
parents cd5247f4da06
children f36f920bad1a
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
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
226 // Growarray with functions declared in the class.
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
227 garray_T classfunctions;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
228 ga_init2(&classfunctions, sizeof(ufunc_T *), 10);
31483
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
31501
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
251 // Skip empty and comment lines.
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
252 if (*line == NUL)
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
253 continue;
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
254 if (*line == '#')
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
255 {
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
256 if (vim9_bad_comment(line))
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
257 break;
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
258 continue;
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
259 }
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31487
diff changeset
260
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
261 char_u *p = line;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
262 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
263 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
264 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
265 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
266 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
267 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
268 else
c82cb53474ee patch 9.0.1037: lalloc(0) error for a class without members
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
269 success = TRUE;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
270 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
271 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
272
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
273 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
274 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
275 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
276 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
277 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
278 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
279 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
280 }
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
281 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
282 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
283
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
284 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
285 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
286 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
287 break;
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 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
290
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
291 int has_static = FALSE;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
292 char_u *ps = p;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
293 if (checkforcmd(&p, "static", 4))
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
294 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
295 if (STRNCMP(ps, "static", 6) != 0)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
296 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
297 semsg(_(e_command_cannot_be_shortened_str), ps);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
298 break;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
299 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
300 has_static = TRUE;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
301 p = skipwhite(ps + 6);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
302 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
303
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
304 // 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
305 // "this._varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
306 // "this.varname"
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
307 // "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
308 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
309 {
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
310 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
311 {
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
312 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
313 break;
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
314 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
315 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
316 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
317 type_T *type = NULL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
318 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
319 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
320 &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
321 break;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
322 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
323 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
324 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
325 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
326 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
327 }
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
328 }
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
329
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
330 // constructors:
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
331 // def new()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
332 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
333 // def newOther()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
334 // enddef
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
335 // object methods and class functions:
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
336 // def SomeMethod()
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
337 // enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
338 // static def ClassFunction()
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
339 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
340 // TODO:
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
341 // def <Tval> someMethod()
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
342 // enddef
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
343 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
344 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
345 exarg_T ea;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
346 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
347
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
348 // TODO: error for "public static def Func()"?
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
349
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
350 CLEAR_FIELD(ea);
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
351 ea.cmd = line;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
352 ea.arg = p;
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
353 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
354 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
355 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
356
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
357 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
358 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
359 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
360
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
361 // TODO: how about errors?
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
362 int is_new = STRNCMP(uf->uf_name, "new", 3) == 0;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
363 garray_T *fgap = has_static || is_new
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
364 ? &classfunctions : &objmethods;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
365 if (uf != NULL && ga_grow(fgap, 1) == OK)
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
366 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
367 if (is_new)
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
368 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
369
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
370 ((ufunc_T **)fgap->ga_data)[fgap->ga_len] = uf;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
371 ++fgap->ga_len;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
372 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
373 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
374
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
375 // class members
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
376 else if (has_static)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
377 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
378 // class members (public, read access, private):
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
379 // "static _varname"
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
380 // "static varname"
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
381 // "public static varname"
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
382 char_u *varname = p;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
383 char_u *varname_end = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
384 type_T *type = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
385 char_u *init_expr = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
386 if (parse_member(eap, line, varname, has_public,
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
387 &varname_end, &type_list, &type, &init_expr) == FAIL)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
388 break;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
389 if (add_member(&classmembers, varname, varname_end,
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
390 has_public, type, init_expr) == FAIL)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
391 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
392 vim_free(init_expr);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
393 break;
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
394 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
395 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
396
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
397 else
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
398 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
399 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
400 break;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
401 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
402 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
403 vim_free(theline);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
404
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
405 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
406 if (success)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
407 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
408 // "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
409
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
410 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
411 if (cl == NULL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
412 goto cleanup;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
413 cl->class_refcount = 1;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
414 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
415 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
416 goto cleanup;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
418 // 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
419 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
420 &cl->class_class_members,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
421 &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
422 || 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
423 &cl->class_obj_members,
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
424 &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
425 goto cleanup;
31483
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 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
428 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
429 // 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
430 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
431 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
432 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
433 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
434 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
435 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
436 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
437 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
438 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
439 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
440 if (etv != NULL)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
441 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
442 *tv = *etv;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
443 vim_free(etv);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
444 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
445 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
446 else
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
447 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
448 // TODO: proper default value
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
449 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
450 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
451 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
452 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
453 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
454
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
455 int have_new = FALSE;
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
456 for (int i = 0; i < classfunctions.ga_len; ++i)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
457 if (STRCMP(((ufunc_T **)classfunctions.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
458 "new") == 0)
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 have_new = TRUE;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
461 break;
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 if (!have_new)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
464 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
465 // 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
466 garray_T fga;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
467 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
468 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
469 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
470 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
471 if (i > 0)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
472 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
473 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
474 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
475 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
476 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
477 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
478 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
479 ga_append(&fga, NUL);
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 exarg_T fea;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
482 CLEAR_FIELD(fea);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
483 fea.cmdidx = CMD_def;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
484 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
485
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
486 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
487 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
488
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
489 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
490
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
491 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
492 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
493
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
494 if (nf != NULL && ga_grow(&classfunctions, 1) == OK)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
495 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
496 ((ufunc_T **)classfunctions.ga_data)[classfunctions.ga_len] = nf;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
497 ++classfunctions.ga_len;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
498
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
499 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
500 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
501 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
502 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
503 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
504 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
505 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
506 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
507 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
508 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
509 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
510
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
511 // loop 1: class functions, loop 2: object methods
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
512 for (int loop = 1; loop <= 2; ++loop)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
513 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
514 garray_T *gap = loop == 1 ? &classfunctions : &objmethods;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
515 int *fcount = loop == 1 ? &cl->class_class_function_count
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
516 : &cl->class_obj_method_count;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
517 ufunc_T ***fup = loop == 1 ? &cl->class_class_functions
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
518 : &cl->class_obj_methods;
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
519
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
520 *fcount = gap->ga_len;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
521 if (gap->ga_len == 0)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
522 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
523 *fup = NULL;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
524 continue;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
525 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
526 *fup = ALLOC_MULT(ufunc_T *, gap->ga_len);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
527 if (*fup == NULL)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
528 goto cleanup;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
529 mch_memmove(*fup, gap->ga_data, sizeof(ufunc_T *) * gap->ga_len);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
530 vim_free(gap->ga_data);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
531
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
532 // Set the class pointer on all the object methods.
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
533 for (int i = 0; i < gap->ga_len; ++i)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
534 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
535 ufunc_T *fp = (*fup)[i];
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
536 fp->uf_class = cl;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
537 if (loop == 2)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
538 fp->uf_flags |= FC_OBJECT;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
539 }
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
540 }
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
541
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
542 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
543 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
544 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
545 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
546 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
547
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
548 // TODO:
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
549 // - 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
550
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
551 // 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
552 typval_T tv;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
553 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
554 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
555 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
556 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
557 return;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
558 }
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 cleanup:
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
561 if (cl != NULL)
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
562 {
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
563 vim_free(cl->class_name);
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
564 vim_free(cl->class_class_functions);
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
565 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
566 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
567 vim_free(cl);
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
568 }
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
569
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
570 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
571 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
572 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
573 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
574 continue;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
575
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
576 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
577 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
578 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
579 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
580 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
581 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
582 ga_clear(gap);
31396
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
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
585 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
586 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
587 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
588 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
589 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
590 ga_clear(&objmethods);
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
591
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
592 for (int i = 0; i < classfunctions.ga_len; ++i)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
593 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
594 ufunc_T *uf = ((ufunc_T **)classfunctions.ga_data)[i];
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
595 func_clear_free(uf, FALSE);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
596 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
597 ga_clear(&classfunctions);
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
598
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
599 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
600 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
601
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
602 /*
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
603 * Find member "name" in class "cl", set "member_idx" to the member index and
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
604 * return its type.
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
605 * When not found "member_idx" is set to -1 and t_any is returned.
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
606 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
607 type_T *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
608 class_member_type(
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
609 class_T *cl,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
610 char_u *name,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
611 char_u *name_end,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
612 int *member_idx)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
613 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
614 *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
615 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
616
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
617 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
618 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
619 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
620 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
621 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
622 *member_idx = i;
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
623 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
624 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
625 }
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
626
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
627 semsg(_(e_unknown_variable_str), name);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
628 return &t_any;
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 * 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
633 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 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
636 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 * 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
642 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 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
645 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 /*
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 * Handle ":type".
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 */
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 void
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 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
654 {
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 // TODO
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 }
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
658 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
659 * 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
660 * - class member: SomeClass.varname
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
661 * - class function: SomeClass.SomeMethod()
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
662 * - class constructor: SomeClass.new()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
663 * - object member: someObject.varname
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
664 * - object method: someObject.SomeMethod()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
665 *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
666 * "*arg" points to the '.'.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
667 * "*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
668 *
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
669 * Returns FAIL or OK.
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 int
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
672 class_object_index(
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
673 char_u **arg,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
674 typval_T *rettv,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
675 evalarg_T *evalarg,
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
676 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
677 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
678 // int evaluate = evalarg != NULL
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
679 // && (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
680
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
681 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
682 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
683 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
684 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
685 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
686
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
687 ++*arg;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
688 char_u *name = *arg;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
689 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
690 if (name_end == name)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
691 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
692 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
693
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
694 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
695 : 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
696 if (*name_end == '(')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
697 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
698 int on_class = rettv->v_type == VAR_CLASS;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
699 int count = on_class ? cl->class_class_function_count
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
700 : cl->class_obj_method_count;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
701 for (int i = 0; i < count; ++i)
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
702 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
703 ufunc_T *fp = on_class ? cl->class_class_functions[i]
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
704 : 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
705 // 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
706 // 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
707 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
708 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
709 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
710 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
711 int argcount = 0;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
712
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
713 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
714 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
715 argvars, &argcount);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
716 if (ret == FAIL)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
717 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
718
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
719 funcexe_T funcexe;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
720 CLEAR_FIELD(funcexe);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
721 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
722 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
723 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
724 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
725 ++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
726 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
727
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
728 // 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
729 // 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
730 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
731 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
732
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
733 // 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
734 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
735 rettv, &funcexe, NULL);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
736
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
737 // 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
738 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
739 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
740 clear_tv(&argvars[idx]);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
741
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
742 if (error != FCERR_NONE)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
743 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
744 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
745 funcexe.fe_found_var);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
746 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
747 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
748 *arg = argp;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
749 return OK;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
750 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
751 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
752
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
753 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
754 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
755
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
756 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
757 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
758 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
759 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
760 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
761 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
762 {
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
763 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
764 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
765 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
766 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
767 }
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31447
diff changeset
768
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
769 // 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
770 // 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
771 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
772 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
773 copy_tv(tv, rettv);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
774 object_unref(obj);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
775
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
776 *arg = name_end;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
777 return OK;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
778 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
779 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
780
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
781 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
782 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
783
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
784 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
785 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
786 // class member
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
787 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
788 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
789 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
790 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
791 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
792 if (*name == '_')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
793 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
794 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
795 return FAIL;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
796 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
797
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
798 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
799 copy_tv(tv, rettv);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
800 class_unref(cl);
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
801
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
802 *arg = name_end;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
803 return OK;
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
804 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
805 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
806
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
807 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
808 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
809
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
810 return FAIL;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
811 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
812
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
813 /*
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
814 * 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
815 * 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
816 */
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
817 ufunc_T *
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
818 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
819 {
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
820 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
821 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
822 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
823 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
824
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
825 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
826 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
827 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
828 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
829 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
830 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
831 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
832
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
833 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
834 : 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
835 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
836 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
837 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
838 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
839 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
840 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
841 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
842
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
843 int count = tv.v_type == VAR_CLASS ? cl->class_class_function_count
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
844 : cl->class_obj_method_count;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
845 ufunc_T **funcs = tv.v_type == VAR_CLASS ? cl->class_class_functions
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
846 : cl->class_obj_methods;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
847 for (int i = 0; i < count; ++i)
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
848 {
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
849 ufunc_T *fp = funcs[i];
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
850 // 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
851 // 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
852 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
853 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
854 {
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
855 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
856 return fp;
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
857 }
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
858 }
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
859
31447
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
860 fail_after_eval:
8cb31f7ac9e2 patch 9.0.1056: leaking memory when disassembling an object method
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
861 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
862 return NULL;
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
863 }
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
864
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31418
diff changeset
865 /*
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
866 * If "cctx->ctx_ufunc" indicates we are in a class, check if "name" is a class
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
867 * member. If it is then return TRUE and set "cl_ret" and "idx_ret".
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
868 */
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
869 int
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
870 class_member_exists(
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
871 char_u *name,
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
872 class_T **cl_ret,
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
873 int *idx_ret,
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
874 cctx_T *cctx)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
875 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
876 if (cctx->ctx_ufunc == NULL || cctx->ctx_ufunc->uf_class == NULL)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
877 return FALSE;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
878 class_T *cl = cctx->ctx_ufunc->uf_class;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
879
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
880 for (int idx = 0; idx < cl->class_class_member_count; ++idx)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
881 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
882 ocmember_T *m = &cl->class_class_members[idx];
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
883 if (STRCMP(m->ocm_name, name) == 0)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
884 {
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
885 *cl_ret = cl;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
886 *idx_ret = idx;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
887 return TRUE;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
888 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
889 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
890
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
891 return FALSE;
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
892 }
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
893
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
894 /*
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
895 * 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
896 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
897 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
898 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
899 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
900 *to = *from;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
901 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
902 ++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
903 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
904
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 * Free an object.
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 static void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
909 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
910 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
911 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
912
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
913 // 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
914 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
915 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
916 clear_tv(tv + i);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
917
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
918 // 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
919 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
920
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
921 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
922 class_unref(cl);
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
923 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
924
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
925 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
926 * Unreference an object.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
927 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
928 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
929 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
930 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
931 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
932 object_clear(obj);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
933 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
934
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
935 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
936 * 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
937 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
938 void
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
939 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
940 {
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
941 *to = *from;
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
942 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
943 ++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
944 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
945
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
946 /*
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
947 * 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
948 */
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
949 void
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
950 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
951 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
952 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
953 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
954 // 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
955 // 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
956 // be freed.
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
957 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
958
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
959 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
960 {
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
961 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
962 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
963 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
964 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
965 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
966 }
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
967 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
968 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
969
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
970 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
971 {
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
972 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
973 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
974 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
975 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
976 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
977
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
978 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
979 {
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31408
diff changeset
980 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
981 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
982 }
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
983 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
984
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
985 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
986
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
987 vim_free(cl);
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
988 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
989 }
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31335
diff changeset
990
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
991 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
992
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
993 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
994 * 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
995 * 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
996 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
997 void
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
998 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
999 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1000 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
1001 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1002 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
1003 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
1004 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1005 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
1006 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1007
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1008 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1009 * 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
1010 * 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
1011 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1012 void
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1013 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
1014 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1015 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
1016 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
1017 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
1018 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
1019 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
1020 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
1021 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1022
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1023 /*
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1024 * 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
1025 */
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1026 int
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1027 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
1028 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1029 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
1030 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
1031
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1032 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
1033 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1034 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
1035 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
1036 {
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1037 // 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
1038 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
1039 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
1040 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1041 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1042
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1043 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
1044 }
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
1045
31335
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046
5acc0d2cf4f7 patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 #endif // FEAT_EVAL