Re: [PATCH v14 3/4] Add support for lookup, overload resolution and invocation of C++ debug methods

Doug Evans
2014-04-21T23:56:40Z

Siva Chandra writes:
> Attached is the v14 of this part of the patch series. This version
> addresses a concern raised by Doug during his v12/v13 review.

Hi.

I've been playing with the patch set a bit.

Another issue I have is this bit of code in, e.g., value_x_binop:

value_user_defined_op (&arg1, argvec + 1, tstr, &static_memfuncp, 2,
&argvec[0], &dm_worker);

if (argvec[0])
{
if (static_memfuncp)
{
argvec[1] = argvec[0];
argvec++;
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *return_type;

return_type
= TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
return value_zero (return_type, VALUE_LVAL (arg1));
}
return call_function_by_hand (argvec[0], 2 - static_memfuncp,
argvec + 1);
}
if (dm_worker != NULL)
{
struct cleanup *dm_worker_cleanup = make_cleanup (xfree, dm_worker);
struct value *ret_val = invoke_debug_method (dm_worker, arg1, &arg2, 1);

do_cleanups (dm_worker_cleanup);
return ret_val;
}

Does this mean we call the debug method (assuming it wins) for the
case of noside == EVAL_AVOID_SIDE_EFFECTS?

Here and elsewhere there's logic that the debug method code is not
being included in, and it makes me want to do things differently.

Fortunately, I think (though I haven't implemented it) it won't be hard.
Just like we have TYPE_CODE_INTERNAL_FUNCTION we could also have
TYPE_CODE_EXTERNAL_FUNCTION, and use that to make debug methods less
special case.
clone_debug_method_worker could return a struct value that is a
TYPE_CODE_EXTERNAL_FUNCTION, and then just before the call to
call_function_by_hand that would happen for normal methods,
we'd have a check for TYPE_CODE_EXTERNAL_FUNCTION and call
call_debug_method instead.

This would be akin to this code in eval.c:

if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_INTERNAL_FUNCTION)
return call_internal_function (exp->gdbarch, exp->language_defn,
argvec[0], nargs, argvec + 1);

return call_function_by_hand (argvec[0], nargs, argvec + 1);

[I know the function to do this is currently named invoke_debug_method
but Consistency Is Good makes me want to have:
call_function_by_hand, call_internal_function, and call_debug_method
instead of:
call_function_by_hand, call_internal_function, and invoke_debug_method.]

This might(!) then let us remove the dm_worker arg to find_overload_match.
If a debug method is found *valp is a TYPE_CODE_EXTERNAL_FUNCTION
instead of a TYPE_CODE_FUNC.

Thoughts?