Skip to content

Commit

Permalink
patch 9.0.1952: Vim9: unused static field
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yegappan authored and chrisbra committed Sep 29, 2023
1 parent 02902b5 commit 5a05d37
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/proto/vim9class.pro
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/proto/vim9instr.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1952,
/**/
1951,
/**/
Expand Down
1 change: 0 additions & 1 deletion src/vim9.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 8 additions & 26 deletions src/vim9class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -255,36 +253,20 @@ 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)
{
siemsg("class %s not found on interface %s",
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;
}

/*
Expand Down
5 changes: 2 additions & 3 deletions src/vim9compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 9 additions & 20 deletions src/vim9execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/vim9expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
7 changes: 2 additions & 5 deletions src/vim9instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}

Expand All @@ -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);

Expand All @@ -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);
}

Expand Down

0 comments on commit 5a05d37

Please sign in to comment.