From: "Pierre Muller" <muller@ics.u-strasbg.fr>
To: "'Joel Brobecker'" <brobecker@adacore.com>
Cc: "'Eli Zaretskii'" <eliz@gnu.org>, <gdb-patches@sourceware.org>
Subject: RE: [RFA] Handle BINOP_INTDIV in valarith.c
Date: Wed, 23 Jan 2008 23:55:00 -0000 [thread overview]
Message-ID: <001d01c85e1b$5e280c70$1a782550$@u-strasbg.fr> (raw)
In-Reply-To: <20080123230929.GC3979@adacore.com>
OK, I get the idea,
but the problem is that this leads to
lots of code copy...
And errors are duplicated at several places:
See for instance my bug report:
http://sourceware.org/ml/gdb/2008-01/msg00209.html
'ptyp 3 / 2.0'
which returns 'int' type
while 'print 3 / 2.0' returns '1.5' which is not an int!
I suspect that the code in Ada shows the same bugs:
> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] On Behalf Of Joel Brobecker
> Sent: Thursday, January 24, 2008 12:09 AM
> To: Pierre Muller
> Cc: 'Eli Zaretskii'; gdb-patches@sourceware.org
> Subject: 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);
which means that 'ptyp' which sets noside to EVAL_AVOID_SIDE_EFFECTS
will not see the fixed to double conversions below
and will also return 'fixed', while the result of print will be
a 'double'.
Furthermore, you can clearly see that this code
was copied from the C evaluator without removing the
unnecessary parts:
the check
> && (op == BINOP_DIV || op == BINOP_REM || op ==
> BINOP_MOD))
is clearly redundant here as we are inside case BINOP_DIV.
The same unnecessary test is also done in the
BINOP_MOD-BINOP_REM case.
> 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.
I agree with you that writing a pascal specific
evaluate_subexp() function is better that
explicitly checking the language of the currently parsed expression,
but my idea was really to have on the contrary
something usable for other languages, and thus not inside
pascal specific code...
On the other hand, no one said that
another language has the same view on the '/' operator as pascal...
Whihch validates your view that a new BINOP is not necessary...
So I will probably try to write a pascal_evaluate_subexp function
as you suggested.
Thanks for the feedback.
Pierre Muller
next prev parent reply other threads:[~2008-01-23 23:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-16 14:14 Pierre Muller
2008-01-16 19:11 ` Eli Zaretskii
2008-01-21 10:45 ` Pierre Muller
2008-01-23 18:25 ` Joel Brobecker
2008-01-23 22:36 ` Pierre Muller
2008-01-23 23:09 ` Joel Brobecker
2008-01-23 23:55 ` Pierre Muller [this message]
2008-01-24 1:30 ` Joel Brobecker
2008-01-23 19:07 ` Tom Tromey
2008-01-23 23:00 ` Pierre Muller
2008-01-24 0:27 ` Tom Tromey
2008-01-17 11:58 ` Joel Brobecker
2008-01-17 12:04 ` Joel Brobecker
2008-01-18 16:27 ` Eli Zaretskii
2008-01-21 15:04 ` Pierre Muller
2008-01-25 13:07 ` [RFA] Handle BINOP_INTDIV in eval.c Pierre Muller
2008-01-30 1:01 ` Daniel Jacobowitz
2008-01-30 7:35 ` Pierre Muller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='001d01c85e1b$5e280c70$1a782550$@u-strasbg.fr' \
--to=muller@ics.u-strasbg.fr \
--cc=brobecker@adacore.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox