forked from aniani/vim
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>
This commit is contained in:
committed by
Christian Brabandt
parent
02902b547b
commit
5a05d374d3
@@ -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);
|
||||
|
@@ -4,8 +4,8 @@ isn_T *generate_instr_drop(cctx_T *cctx, isntype_T isn_type, int drop);
|
||||
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);
|
||||
|
@@ -699,6 +699,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1952,
|
||||
/**/
|
||||
1951,
|
||||
/**/
|
||||
|
@@ -498,7 +498,6 @@ typedef struct {
|
||||
typedef struct {
|
||||
class_T *cm_class;
|
||||
int cm_idx;
|
||||
int cm_static;
|
||||
} classmember_T;
|
||||
// arguments to ISN_STOREINDEX
|
||||
typedef struct {
|
||||
|
@@ -220,12 +220,10 @@ add_members_to_class(
|
||||
* "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 @@ object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl,
|
||||
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 @@ object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl,
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -2249,9 +2249,8 @@ compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx)
|
||||
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);
|
||||
|
@@ -2318,7 +2318,7 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
|
||||
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 @@ exec_instructions(ectx_T *ectx)
|
||||
|
||||
// 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 @@ exec_instructions(ectx_T *ectx)
|
||||
|
||||
// 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 @@ exec_instructions(ectx_T *ectx)
|
||||
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 @@ exec_instructions(ectx_T *ectx)
|
||||
// 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 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
|
||||
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;
|
||||
|
@@ -413,9 +413,8 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
|
||||
|
||||
*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".
|
||||
|
@@ -136,7 +136,7 @@ generate_CONSTRUCT(cctx_T *cctx, class_T *cl)
|
||||
* 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 @@ generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type, int is_static)
|
||||
|
||||
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 @@ generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type, int is_static)
|
||||
* 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 @@ generate_GET_ITF_MEMBER(cctx_T *cctx, class_T *itf, int idx, type_T *type,
|
||||
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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user