This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Handle BINOP_INTDIV in valarith.c


>   I wrote the floatdiv version, which allows me to easily force the
>   conversion to double formats for left and right operand:

Right, but you are doing the conversion inside what I call "core-gdb",
which is a language-independent file. As a result, you ended up needing
a new operator.  But the creation of this new operator would not be
necessary if you handled BINOP_DIV in a pascal-specific way.

>    maybe 
>    || (op == BINOP_DIV && current_language = language_pascal))

That's not the proper way of doing this. What you need to do is to
setup your language to have a pascal-specific expression evaluator.
Right now, it's set to use the "standard" expression evaluator which
(IIRC) is the C evaluator.  Your pascal expression evaluator will
defer back to the standard expression evaluator most of the time,
except for the case when the binary operator is FLOAT_DIV.  In this
case, you'll do the division yourself.

You can have a look at ada-lang.c:ada_evaluate_subexp(). It's a large
routine because of a lot of stuff is special to Ada, but you'll also
see:

  op = exp->elts[pc].opcode;
  [...]
  switch (op)
    {
    default:
      *pos -= 1;
      arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
    [...]
    case BINOP_DIV:
      arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
      arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
      if (noside == EVAL_SKIP)
        goto nosideret;
      else if (noside == EVAL_AVOID_SIDE_EFFECTS
               && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
        return value_zero (value_type (arg1), not_lval);
      else
        {
          if (ada_is_fixed_point_type (value_type (arg1)))
            arg1 = cast_from_fixed_to_double (arg1);
          if (ada_is_fixed_point_type (value_type (arg2)))
            arg2 = cast_from_fixed_to_double (arg2);
          return ada_value_binop (arg1, arg2, op);
        }

If you look at the "default:" case, you'll see that we let
the standard evaluator do the work for us. But we treat the
BINOP_DIV case specially: First we evaluate each side of our
division, and then perform the division and return the result.

This ada_evaluate_subexp routine is setup in the language through
the exp_descriptor structure.

-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]