summaryrefslogtreecommitdiffstats
path: root/src/typval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/typval.c')
-rw-r--r--src/typval.c89
1 files changed, 33 insertions, 56 deletions
diff --git a/src/typval.c b/src/typval.c
index 6a73719..01ffef5 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -267,11 +267,16 @@ tv_get_bool_or_number_chk(
break;
case VAR_OBJECT:
{
- class_T *cl = varp->vval.v_object->obj_class;
- if (cl != NULL && IS_ENUM(cl))
- semsg(_(e_using_enum_str_as_number), cl->class_name);
+ if (varp->vval.v_object == NULL)
+ emsg(_(e_using_object_as_string));
else
- emsg(_(e_using_object_as_number));
+ {
+ class_T *cl = varp->vval.v_object->obj_class;
+ if (cl != NULL && IS_ENUM(cl))
+ semsg(_(e_using_enum_str_as_number), cl->class_name);
+ else
+ emsg(_(e_using_object_as_number));
+ }
}
break;
case VAR_VOID:
@@ -1146,11 +1151,16 @@ tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
break;
case VAR_OBJECT:
{
- class_T *cl = varp->vval.v_object->obj_class;
- if (cl != NULL && IS_ENUM(cl))
- semsg(_(e_using_enum_str_as_string), cl->class_name);
- else
+ if (varp->vval.v_object == NULL)
emsg(_(e_using_object_as_string));
+ else
+ {
+ class_T *cl = varp->vval.v_object->obj_class;
+ if (cl != NULL && IS_ENUM(cl))
+ semsg(_(e_using_enum_str_as_string), cl->class_name);
+ else
+ emsg(_(e_using_object_as_string));
+ }
}
break;
case VAR_JOB:
@@ -1605,8 +1615,7 @@ typval_compare_list(
}
else
{
- val = list_equal(tv1->vval.v_list, tv2->vval.v_list,
- ic, FALSE);
+ val = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic);
if (type == EXPR_NEQUAL)
val = !val;
}
@@ -1699,24 +1708,6 @@ typval_compare_blob(
}
/*
- * Compare "tv1" to "tv2" as classes according to "type".
- * Put the result, false or true, in "res".
- * Return FAIL and give an error message when the comparison can't be done.
- */
- int
-typval_compare_class(
- typval_T *tv1,
- typval_T *tv2,
- exprtype_T type UNUSED,
- int ic UNUSED,
- int *res)
-{
- // TODO: use "type"
- *res = tv1->vval.v_class == tv2->vval.v_class;
- return OK;
-}
-
-/*
* Compare "tv1" to "tv2" as objects according to "type".
* Put the result, false or true, in "res".
* Return FAIL and give an error message when the comparison can't be done.
@@ -1742,14 +1733,6 @@ typval_compare_object(
return OK;
}
- class_T *cl1 = tv1->vval.v_object->obj_class;
- class_T *cl2 = tv2->vval.v_object->obj_class;
- if (cl1 != cl2 || cl1 == NULL || cl2 == NULL)
- {
- *res = !res_match;
- return OK;
- }
-
object_T *obj1 = tv1->vval.v_object;
object_T *obj2 = tv2->vval.v_object;
if (type == EXPR_IS || type == EXPR_ISNOT)
@@ -1758,14 +1741,7 @@ typval_compare_object(
return OK;
}
- for (int i = 0; i < cl1->class_obj_member_count; ++i)
- if (!tv_equal((typval_T *)(obj1 + 1) + i,
- (typval_T *)(obj2 + 1) + i, ic, TRUE))
- {
- *res = !res_match;
- return OK;
- }
- *res = res_match;
+ *res = object_equal(obj1, obj2, ic) ? res_match : !res_match;
return OK;
}
@@ -1802,7 +1778,7 @@ typval_compare_dict(
}
else
{
- val = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, FALSE);
+ val = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic);
if (type == EXPR_NEQUAL)
val = !val;
}
@@ -1841,14 +1817,14 @@ typval_compare_func(
if (tv1->v_type == VAR_FUNC && tv2->v_type == VAR_FUNC)
// strings are considered the same if their value is
// the same
- val = tv_equal(tv1, tv2, ic, FALSE);
+ val = tv_equal(tv1, tv2, ic);
else if (tv1->v_type == VAR_PARTIAL && tv2->v_type == VAR_PARTIAL)
val = (tv1->vval.v_partial == tv2->vval.v_partial);
else
val = FALSE;
}
else
- val = tv_equal(tv1, tv2, ic, FALSE);
+ val = tv_equal(tv1, tv2, ic);
if (type == EXPR_NEQUAL || type == EXPR_ISNOT)
val = !val;
*res = val;
@@ -2003,7 +1979,7 @@ func_equal(
if (d1 != d2)
return FALSE;
}
- else if (!dict_equal(d1, d2, ic, TRUE))
+ else if (!dict_equal(d1, d2, ic))
return FALSE;
// empty list and no list considered the same
@@ -2013,7 +1989,7 @@ func_equal(
return FALSE;
for (i = 0; i < a1; ++i)
if (!tv_equal(tv1->vval.v_partial->pt_argv + i,
- tv2->vval.v_partial->pt_argv + i, ic, TRUE))
+ tv2->vval.v_partial->pt_argv + i, ic))
return FALSE;
return TRUE;
@@ -2028,8 +2004,7 @@ func_equal(
tv_equal(
typval_T *tv1,
typval_T *tv2,
- int ic, // ignore case
- int recursive) // TRUE when used recursively
+ int ic) // ignore case
{
char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
char_u *s1, *s2;
@@ -2043,7 +2018,7 @@ tv_equal(
// Reduce the limit every time running into it. That should work fine for
// deeply linked structures that are not recursively linked and catch
// recursiveness quickly.
- if (!recursive)
+ if (recursive_cnt == 0)
tv_equal_recurse_limit = 1000;
if (recursive_cnt >= tv_equal_recurse_limit)
{
@@ -2073,13 +2048,13 @@ tv_equal(
{
case VAR_LIST:
++recursive_cnt;
- r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE);
+ r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic);
--recursive_cnt;
return r;
case VAR_DICT:
++recursive_cnt;
- r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE);
+ r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic);
--recursive_cnt;
return r;
@@ -2114,7 +2089,9 @@ tv_equal(
return tv1->vval.v_class == tv2->vval.v_class;
case VAR_OBJECT:
- (void)typval_compare_object(tv1, tv2, EXPR_EQUAL, ic, &r);
+ ++recursive_cnt;
+ r = object_equal(tv1->vval.v_object, tv2->vval.v_object, ic);
+ --recursive_cnt;
return r;
case VAR_PARTIAL:
@@ -2237,7 +2214,7 @@ eval_number(
char_u **arg,
typval_T *rettv,
int evaluate,
- int want_string UNUSED)
+ int want_string)
{
int len;
int skip_quotes = !in_old_script(4);