vim-patch:8.0.1511: some code for the debugger watch expression is clumsy

Problem:    Some code for the debugger watch expression is clumsy.
Solution:   Clean up the code.
3198870137
This commit is contained in:
Jan Edmund Lazo
2021-04-07 09:37:54 -04:00
parent 1a1fe58f7e
commit 69bab7e35d
2 changed files with 152 additions and 170 deletions

View File

@@ -3484,8 +3484,12 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
tv_clear(rettv); tv_clear(rettv);
return FAIL; return FAIL;
} }
if (evaluate) {
const int ret = typval_compare(rettv, &var2, type, type_is, ic);
return typval_compare(rettv, &var2, type, type_is, ic, evaluate); tv_clear(&var2);
return ret;
}
} }
return OK; return OK;
@@ -10573,19 +10577,18 @@ bool invoke_prompt_interrupt(void)
return true; return true;
} }
// Compare "typ1" and "typ2". Put the result in "typ1".
int typval_compare( int typval_compare(
typval_T *typ1, // first operand typval_T *typ1, // first operand
typval_T *typ2, // second operand typval_T *typ2, // second operand
exptype_T type, // operator exptype_T type, // operator
bool type_is, // true for "is" and "isnot" bool type_is, // true for "is" and "isnot"
bool ic, // ignore case bool ic // ignore case
bool evaluate
) )
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
varnumber_T n1, n2; varnumber_T n1, n2;
if (evaluate) {
if (type_is && typ1->v_type != typ2->v_type) { if (type_is && typ1->v_type != typ2->v_type) {
// For "is" a different type always means false, for "notis" // For "is" a different type always means false, for "notis"
// it means true. // it means true.
@@ -10605,7 +10608,6 @@ int typval_compare(
EMSG(_("E692: Invalid operation for List")); EMSG(_("E692: Invalid operation for List"));
} }
tv_clear(typ1); tv_clear(typ1);
tv_clear(typ2);
return FAIL; return FAIL;
} else { } else {
// Compare two Lists for being equal or unequal. // Compare two Lists for being equal or unequal.
@@ -10629,7 +10631,6 @@ int typval_compare(
EMSG(_("E736: Invalid operation for Dictionary")); EMSG(_("E736: Invalid operation for Dictionary"));
} }
tv_clear(typ1); tv_clear(typ1);
tv_clear(typ2);
return FAIL; return FAIL;
} else { } else {
// Compare two Dictionaries for being equal or unequal. // Compare two Dictionaries for being equal or unequal.
@@ -10642,7 +10643,6 @@ int typval_compare(
if (type != TYPE_EQUAL && type != TYPE_NEQUAL) { if (type != TYPE_EQUAL && type != TYPE_NEQUAL) {
EMSG(_("E694: Invalid operation for Funcrefs")); EMSG(_("E694: Invalid operation for Funcrefs"));
tv_clear(typ1); tv_clear(typ1);
tv_clear(typ2);
return FAIL; return FAIL;
} }
if ((typ1->v_type == VAR_PARTIAL && typ1->vval.v_partial == NULL) if ((typ1->v_type == VAR_PARTIAL && typ1->vval.v_partial == NULL)
@@ -10654,8 +10654,7 @@ int typval_compare(
// strings are considered the same if their value is // strings are considered the same if their value is
// the same // the same
n1 = tv_equal(typ1, typ2, ic, false); n1 = tv_equal(typ1, typ2, ic, false);
} else if (typ1->v_type == VAR_PARTIAL } else if (typ1->v_type == VAR_PARTIAL && typ2->v_type == VAR_PARTIAL) {
&& typ2->v_type == VAR_PARTIAL) {
n1 = typ1->vval.v_partial == typ2->vval.v_partial; n1 = typ1->vval.v_partial == typ2->vval.v_partial;
} else { } else {
n1 = false; n1 = false;
@@ -10732,25 +10731,11 @@ int typval_compare(
} }
} }
tv_clear(typ1); tv_clear(typ1);
tv_clear(typ2);
typ1->v_type = VAR_NUMBER; typ1->v_type = VAR_NUMBER;
typ1->vval.v_number = n1; typ1->vval.v_number = n1;
}
return OK; return OK;
} }
int typval_copy(typval_T *typ1, typval_T *typ2)
{
if (typ2 == NULL) {
tv_list_alloc_ret(typ2, kListLenUnknown);
}
if (typ1 != NULL && typ2 != NULL) {
return var_item_copy(NULL, typ1, typ2, true, 0);
}
return FAIL;
}
char *typval_tostring(typval_T *arg) char *typval_tostring(typval_T *arg)
{ {
if (arg == NULL) { if (arg == NULL) {

View File

@@ -876,19 +876,16 @@ debuggy_find(
debug_newval = typval_tostring(bp->dbg_val); debug_newval = typval_tostring(bp->dbg_val);
line = true; line = true;
} else { } else {
typval_T val3; if (typval_compare(tv, bp->dbg_val, TYPE_EQUAL, true, false) == OK
if (typval_copy(bp->dbg_val, &val3) == OK) {
if (typval_compare(tv, &val3, TYPE_EQUAL, true, false, true) == OK
&& tv->vval.v_number == false) { && tv->vval.v_number == false) {
line = true; line = true;
debug_oldval = typval_tostring(bp->dbg_val); debug_oldval = typval_tostring(bp->dbg_val);
// Need to evaluate again, typval_compare() overwrites "tv".
typval_T *v = eval_expr(bp->dbg_name); typval_T *v = eval_expr(bp->dbg_name);
debug_newval = typval_tostring(v); debug_newval = typval_tostring(v);
tv_free(bp->dbg_val); tv_free(bp->dbg_val);
bp->dbg_val = v; bp->dbg_val = v;
} }
}
tv_free(tv); tv_free(tv);
} }
} else if (bp->dbg_val != NULL) { } else if (bp->dbg_val != NULL) {