Mercurial > vim
annotate src/proto/vim9class.pro @ 33260:aba1fa2b7d1e v9.0.1898
patch 9.0.1898: Vim9: restrict access to static vars
Commit: https://github.com/vim/vim/commit/c30a90d9b2c029f794cea502f6b824f71e4876dd
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Sep 15 20:14:55 2023 +0200
patch 9.0.1898: Vim9: restrict access to static vars
Problem: Vim9: restrict access to static vars and methods
Solution: Class members are accesible only from the class where they are
defined.
Based on the #13004 discussion, the following changes are made:
1) Static variables and methods are accessible only using the class
name and inside the class where they are defined.
2) Static variables and methods can be used without the class name in
the class where they are defined.
3) Static variables of a super class are not copied to the sub class.
4) A sub class can declare a class variable with the same name as the
super class.
5) When a method or member is found during compilation, use more
specific error messages.
This aligns the Vim9 class variable/method implementation with the Dart
implementation.
Also while at it, ignore duplicate class and object methods.
The access level of an object method can however be changed in a
subclass.
For the tests, use the new CheckSourceFailure() function instead of the
CheckScriptFailure() function in the tests.
closes: #13086
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 15 Sep 2023 20:30:05 +0200 |
parents | 108d890d887f |
children | 0c3553cfe22e |
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 /* vim9class.c */ |
33173
9efd99a717c1
patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents:
33160
diff
changeset
|
2 int object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl, int is_static); |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 void ex_class(exarg_T *eap); |
33109
2b5cc29b0a0e
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents:
33106
diff
changeset
|
4 type_T *class_member_type(class_T *cl, int is_object, char_u *name, char_u *name_end, int *member_idx, ocmember_T **m); |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 void ex_enum(exarg_T *eap); |
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 void ex_type(exarg_T *eap); |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
7 int class_object_index(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int verbose); |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31404
diff
changeset
|
8 ufunc_T *find_class_func(char_u **arg); |
33233
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
9 int class_member_idx(class_T *cl, char_u *name, size_t namelen); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
10 ocmember_T *class_member_lookup(class_T *cl, char_u *name, size_t namelen, int *idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
11 int class_method_idx(class_T *cl, char_u *name, size_t namelen); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
12 ufunc_T *class_method_lookup(class_T *cl, char_u *name, size_t namelen, int *idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
13 int object_member_idx(class_T *cl, char_u *name, size_t namelen); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
14 ocmember_T *object_member_lookup(class_T *cl, char_u *name, size_t namelen, int *idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
15 int object_method_idx(class_T *cl, char_u *name, size_t namelen); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
16 ufunc_T *object_method_lookup(class_T *cl, char_u *name, size_t namelen, int *idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
17 ocmember_T *member_lookup(class_T *cl, vartype_T v_type, char_u *name, size_t namelen, int *idx); |
108d890d887f
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Christian Brabandt <cb@256bit.org>
parents:
33227
diff
changeset
|
18 ufunc_T *method_lookup(class_T *cl, vartype_T v_type, char_u *name, size_t namelen, int *idx); |
31815
64f03e860c91
patch 9.0.1240: cannot access a private object member in a lambda
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
19 int inside_class(cctx_T *cctx_arg, class_T *cl); |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31335
diff
changeset
|
20 void 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
|
21 void 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
|
22 void copy_class(typval_T *from, typval_T *to); |
31404
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
23 void class_unref(class_T *cl); |
33160
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33109
diff
changeset
|
24 int class_free_nonref(int copyID); |
4ecf54d709b3
patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents:
33109
diff
changeset
|
25 int set_ref_in_classes(int copyID); |
31404
60b1d266548d
patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
26 void 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
|
27 void 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
|
28 int object_free_nonref(int copyID); |
33260
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
29 void method_not_found_msg(class_T *cl, vartype_T v_type, char_u *name, size_t len); |
aba1fa2b7d1e
patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents:
33233
diff
changeset
|
30 void member_not_found_msg(class_T *cl, vartype_T v_type, char_u *name, size_t len); |
32972
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
31843
diff
changeset
|
31 void f_instanceof(typval_T *argvars, typval_T *rettv); |
e4851934751a
patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents:
31843
diff
changeset
|
32 int class_instance_of(class_T *cl, class_T *other_cl); |
31335
5acc0d2cf4f7
patch 9.0.1001: classes are not documented or implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 /* vim: set ft=c : */ |