patch 9.0.1952: Vim9: unused static field
Problem: Vim9: unused static field
Solution: remove it and simplify code
closes: #13220
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
diff --git a/src/proto/vim9class.pro b/src/proto/vim9class.pro
index d09f654..9edf354 100644
--- a/src/proto/vim9class.pro
+++ b/src/proto/vim9class.pro
@@ -1,5 +1,5 @@
/* vim9class.c */
-int object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl, int is_static);
+int object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl);
void ex_class(exarg_T *eap);
type_T *class_member_type(class_T *cl, int is_object, char_u *name, char_u *name_end, int *member_idx);
void ex_enum(exarg_T *eap);
diff --git a/src/proto/vim9instr.pro b/src/proto/vim9instr.pro
index 44e6b98..7c13f93 100644
--- a/src/proto/vim9instr.pro
+++ b/src/proto/vim9instr.pro
@@ -4,8 +4,8 @@
isn_T *generate_instr_type(cctx_T *cctx, isntype_T isn_type, type_T *type);
isn_T *generate_instr_debug(cctx_T *cctx);
int generate_CONSTRUCT(cctx_T *cctx, class_T *cl);
-int generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type, int is_static);
-int generate_GET_ITF_MEMBER(cctx_T *cctx, class_T *itf, int idx, type_T *type, int is_static);
+int generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type);
+int generate_GET_ITF_MEMBER(cctx_T *cctx, class_T *itf, int idx, type_T *type);
int generate_STORE_THIS(cctx_T *cctx, int idx);
int may_generate_2STRING(int offset, int tolerant, cctx_T *cctx);
int generate_add_instr(cctx_T *cctx, vartype_T vartype, type_T *type1, type_T *type2, exprtype_T expr_type);
diff --git a/src/version.c b/src/version.c
index 5aca53a..ad696de 100644
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1952,
+/**/
1951,
/**/
1950,
diff --git a/src/vim9.h b/src/vim9.h
index bafff94..03f6dad 100644
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -498,7 +498,6 @@
typedef struct {
class_T *cm_class;
int cm_idx;
- int cm_static;
} classmember_T;
// arguments to ISN_STOREINDEX
typedef struct {
diff --git a/src/vim9class.c b/src/vim9class.c
index 29ed6d1..885ac03 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -220,12 +220,10 @@
* "cl" implementing that interface.
*/
int
-object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl,
- int is_static)
+object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl)
{
if (idx >= (is_method ? itf->class_obj_method_count
- : is_static ? itf->class_class_member_count
- : itf->class_obj_member_count))
+ : itf->class_obj_member_count))
{
siemsg("index %d out of range for interface %s", idx, itf->class_name);
return 0;
@@ -255,9 +253,7 @@
if (searching && is_method)
// The parent class methods are stored after the current class
// methods.
- method_offset += is_static
- ? super->class_class_function_count_child
- : super->class_obj_method_count_child;
+ method_offset += super->class_obj_method_count_child;
}
if (i2c == NULL)
{
@@ -265,26 +261,12 @@
cl->class_name, itf->class_name);
return 0;
}
- if (is_static)
- {
- // TODO: Need a table for fast lookup?
- char_u *name = itf->class_class_members[idx].ocm_name;
- int m_idx = class_member_idx(i2c->i2c_class, name, 0);
- if (m_idx >= 0)
- return m_idx;
- siemsg("class %s, interface %s, static %s not found",
- cl->class_name, itf->class_name, name);
- return 0;
- }
- else
- {
- // A table follows the i2c for the class
- int *table = (int *)(i2c + 1);
- // "method_offset" is 0, if method is in the current class. If method
- // is in a parent class, then it is non-zero.
- return table[idx] + method_offset;
- }
+ // A table follows the i2c for the class
+ int *table = (int *)(i2c + 1);
+ // "method_offset" is 0, if method is in the current class. If method
+ // is in a parent class, then it is non-zero.
+ return table[idx] + method_offset;
}
/*
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 40fdc4b..086a322 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2249,9 +2249,8 @@
return FAIL;
}
if (cl->class_flags & CLASS_INTERFACE)
- return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type,
- FALSE);
- return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type, FALSE);
+ return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type);
+ return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type);
}
compile_load_lhs(lhs, var_start, NULL, cctx);
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 0700eb7..d005deb 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2318,7 +2318,7 @@
if (itf != NULL)
// convert interface member index to class member index
lidx = object_index_from_itf_index(itf, FALSE, lidx,
- obj->obj_class, FALSE);
+ obj->obj_class);
}
else
{
@@ -4262,8 +4262,7 @@
// convert the interface index to the object index
int idx = object_index_from_itf_index(mfunc->cmf_itf,
- TRUE, mfunc->cmf_idx, cl,
- FALSE);
+ TRUE, mfunc->cmf_idx, cl);
if (call_ufunc(cl->class_obj_methods[idx], NULL,
mfunc->cmf_argcount, ectx, NULL, NULL) == FAIL)
@@ -4412,8 +4411,7 @@
// convert the interface index to the object index
int idx = object_index_from_itf_index(extra->fre_class,
- TRUE, extra->fre_method_idx, cl,
- FALSE);
+ TRUE, extra->fre_method_idx, cl);
ufunc = cl->class_obj_methods[idx];
}
else if (extra == NULL || extra->fre_func_name == NULL)
@@ -5392,7 +5390,6 @@
goto on_error;
}
- int is_static = iptr->isn_arg.classmember.cm_static;
int idx;
if (iptr->isn_type == ISN_GET_OBJ_MEMBER)
idx = iptr->isn_arg.classmember.cm_idx;
@@ -5402,15 +5399,11 @@
// convert the interface index to the object index
idx = object_index_from_itf_index(
iptr->isn_arg.classmember.cm_class,
- FALSE, idx, obj->obj_class, is_static);
+ FALSE, idx, obj->obj_class);
}
// The members are located right after the object struct.
- typval_T *mtv;
- if (is_static)
- mtv = &obj->obj_class->class_members_tv[idx];
- else
- mtv = ((typval_T *)(obj + 1)) + idx;
+ typval_T *mtv = ((typval_T *)(obj + 1)) + idx;
copy_tv(mtv, tv);
// Unreference the object after getting the member, it may
@@ -7157,17 +7150,13 @@
case ISN_MEMBER: smsg("%s%4d MEMBER", pfx, current); break;
case ISN_STRINGMEMBER: smsg("%s%4d MEMBER %s", pfx, current,
iptr->isn_arg.string); break;
- case ISN_GET_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d%s", pfx, current,
- (int)iptr->isn_arg.classmember.cm_idx,
- iptr->isn_arg.classmember.cm_static
- ? " [STATIC]" : "");
+ case ISN_GET_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d", pfx, current,
+ (int)iptr->isn_arg.classmember.cm_idx);
break;
- case ISN_GET_ITF_MEMBER: smsg("%s%4d ITF_MEMBER %d on %s%s",
+ case ISN_GET_ITF_MEMBER: smsg("%s%4d ITF_MEMBER %d on %s",
pfx, current,
(int)iptr->isn_arg.classmember.cm_idx,
- iptr->isn_arg.classmember.cm_class->class_name,
- iptr->isn_arg.classmember.cm_static
- ? " [STATIC]" : "");
+ iptr->isn_arg.classmember.cm_class->class_name);
break;
case ISN_STORE_THIS: smsg("%s%4d STORE_THIS %d", pfx, current,
(int)iptr->isn_arg.number); break;
diff --git a/src/vim9expr.c b/src/vim9expr.c
index 7abd0a4..5a302d6 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -413,9 +413,8 @@
*arg = name_end;
if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED))
- return generate_GET_ITF_MEMBER(cctx, cl, m_idx, m->ocm_type,
- FALSE);
- return generate_GET_OBJ_MEMBER(cctx, m_idx, m->ocm_type, FALSE);
+ return generate_GET_ITF_MEMBER(cctx, cl, m_idx, m->ocm_type);
+ return generate_GET_OBJ_MEMBER(cctx, m_idx, m->ocm_type);
}
// Could be a function reference: "obj.Func".
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 48b4ea4..b229d4a 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -136,7 +136,7 @@
* index.
*/
int
-generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type, int is_static)
+generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type)
{
RETURN_OK_IF_SKIP(cctx);
@@ -147,7 +147,6 @@
isn->isn_arg.classmember.cm_class = NULL;
isn->isn_arg.classmember.cm_idx = idx;
- isn->isn_arg.classmember.cm_static = is_static;
return push_type_stack2(cctx, type, &t_any);
}
@@ -156,8 +155,7 @@
* by index.
*/
int
-generate_GET_ITF_MEMBER(cctx_T *cctx, class_T *itf, int idx, type_T *type,
- int is_static)
+generate_GET_ITF_MEMBER(cctx_T *cctx, class_T *itf, int idx, type_T *type)
{
RETURN_OK_IF_SKIP(cctx);
@@ -169,7 +167,6 @@
isn->isn_arg.classmember.cm_class = itf;
++itf->class_refcount;
isn->isn_arg.classmember.cm_idx = idx;
- isn->isn_arg.classmember.cm_static = is_static;
return push_type_stack2(cctx, type, &t_any);
}