* [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double
@ 2008-01-28 17:08 Pierre Muller
2008-01-31 22:43 ` Daniel Jacobowitz
0 siblings, 1 reply; 7+ messages in thread
From: Pierre Muller @ 2008-01-28 17:08 UTC (permalink / raw)
To: gdb-patches
Hi all,
I finally found a much easier way to
fix the problem for ptyp ' 1 / 3'
for pascal language:
I just added an explicit typecast to
builtin_type_long_double to the left operand.
The right operator is then also typecasted
to the same by the common code, and this also
allows to get the right answer for 'ptyp 1 / 3'
The only problem is that operators can also
be overloaded in pascal.
Thus we should only typecast if the result is
of integer type... And this is where it began to
become more tricky...
The variable current_type, that should
always represent the return value of the current expression, was
not set correctly for several sub-expressions.
This patch also tries to fix those problems.
As pascal language maintainer, I need no formal
approval, but I am not that familiar with the
expression parser, as I really only distorted
the C expression parser to try to come close to pascal
language expectations.
The patch is now of course completely pascal specific,
but it seemed anyhow that there real ad-equation with
any of the other supported languages.
Could someone please confirm that the
way I inserted the implicit typecast in the parser is
correct?
All comments most welcome.
Pierre Muller
Pascal language maintainer
ChangeLog entry:
2008-01-28 Pierre Muller <muller@ics.u-strasbg.fr>
* p-exp.y (Expression parser): Add explicit
'long double' typecast to left operand of '/' operator.
Fix current_type on boolean and function call expressions.
Set current_type for constant boolean, integer and float
expressions.
Index: gdb/p-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/p-exp.y,v
retrieving revision 1.39
diff -u -p -r1.39 p-exp.y
--- gdb/p-exp.y 9 Jan 2008 19:27:15 -0000 1.39
+++ gdb/p-exp.y 28 Jan 2008 15:35:24 -0000
@@ -332,7 +332,10 @@ exp : exp '('
{ write_exp_elt_opcode (OP_FUNCALL);
write_exp_elt_longcst ((LONGEST) end_arglist ());
write_exp_elt_opcode (OP_FUNCALL);
- pop_current_type (); }
+ pop_current_type ();
+ if (current_type)
+ current_type = TYPE_TARGET_TYPE (current_type);
+ }
;
arglist :
@@ -367,7 +370,15 @@ exp : exp '*' exp
{ write_exp_elt_opcode (BINOP_MUL); }
;
-exp : exp '/' exp
+exp : exp '/' {
+ if (current_type && is_integral_type
(current_type))
+ {
+ write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_type (builtin_type_long_double);
+ write_exp_elt_opcode (UNOP_CAST);
+ }
+ }
+ exp
{ write_exp_elt_opcode (BINOP_DIV); }
;
@@ -396,27 +407,39 @@ exp : exp RSH exp
;
exp : exp '=' exp
- { write_exp_elt_opcode (BINOP_EQUAL); }
+ { write_exp_elt_opcode (BINOP_EQUAL);
+ current_type = builtin_type_bool;
+ }
;
exp : exp NOTEQUAL exp
- { write_exp_elt_opcode (BINOP_NOTEQUAL); }
+ { write_exp_elt_opcode (BINOP_NOTEQUAL);
+ current_type = builtin_type_bool;
+ }
;
exp : exp LEQ exp
- { write_exp_elt_opcode (BINOP_LEQ); }
+ { write_exp_elt_opcode (BINOP_LEQ);
+ current_type = builtin_type_bool;
+ }
;
exp : exp GEQ exp
- { write_exp_elt_opcode (BINOP_GEQ); }
+ { write_exp_elt_opcode (BINOP_GEQ);
+ current_type = builtin_type_bool;
+ }
;
exp : exp '<' exp
- { write_exp_elt_opcode (BINOP_LESS); }
+ { write_exp_elt_opcode (BINOP_LESS);
+ current_type = builtin_type_bool;
+ }
;
exp : exp '>' exp
- { write_exp_elt_opcode (BINOP_GTR); }
+ { write_exp_elt_opcode (BINOP_GTR);
+ current_type = builtin_type_bool;
+ }
;
exp : exp ANDAND exp
@@ -438,18 +461,21 @@ exp : exp ASSIGN exp
exp : TRUEKEYWORD
{ write_exp_elt_opcode (OP_BOOL);
write_exp_elt_longcst ((LONGEST) $1);
+ current_type = builtin_type_bool;
write_exp_elt_opcode (OP_BOOL); }
;
exp : FALSEKEYWORD
{ write_exp_elt_opcode (OP_BOOL);
write_exp_elt_longcst ((LONGEST) $1);
+ current_type = builtin_type_bool;
write_exp_elt_opcode (OP_BOOL); }
;
exp : INT
{ write_exp_elt_opcode (OP_LONG);
write_exp_elt_type ($1.type);
+ current_type = $1.type;
write_exp_elt_longcst ((LONGEST)($1.val));
write_exp_elt_opcode (OP_LONG); }
;
@@ -459,6 +485,7 @@ exp : NAME_OR_INT
parse_number ($1.stoken.ptr, $1.stoken.length, 0,
&val
);
write_exp_elt_opcode (OP_LONG);
write_exp_elt_type (val.typed_val_int.type);
+ current_type = val.typed_val_int.type;
write_exp_elt_longcst
((LONGEST)val.typed_val_int.val)
;
write_exp_elt_opcode (OP_LONG);
}
@@ -468,6 +495,7 @@ exp : NAME_OR_INT
exp : FLOAT
{ write_exp_elt_opcode (OP_DOUBLE);
write_exp_elt_type ($1.type);
+ current_type = $1.type;
write_exp_elt_dblcst ($1.dval);
write_exp_elt_opcode (OP_DOUBLE); }
;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double
2008-01-28 17:08 [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double Pierre Muller
@ 2008-01-31 22:43 ` Daniel Jacobowitz
2008-02-01 7:29 ` Pierre Muller
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Jacobowitz @ 2008-01-31 22:43 UTC (permalink / raw)
To: Pierre Muller; +Cc: gdb-patches
On Mon, Jan 28, 2008 at 04:47:26PM +0100, Pierre Muller wrote:
> Could someone please confirm that the
> way I inserted the implicit typecast in the parser is
> correct?
> All comments most welcome.
It looks OK to me. Does the type of the left operand completely
determine the type of the operation, or do you need to worry about the
type of the right-hand exp too before you cast?
> @@ -367,7 +370,15 @@ exp : exp '*' exp
> { write_exp_elt_opcode (BINOP_MUL); }
> ;
>
> -exp : exp '/' exp
> +exp : exp '/' {
> + if (current_type && is_integral_type
> (current_type))
> + {
> + write_exp_elt_opcode (UNOP_CAST);
> + write_exp_elt_type (builtin_type_long_double);
> + write_exp_elt_opcode (UNOP_CAST);
> + }
> + }
> + exp
> { write_exp_elt_opcode (BINOP_DIV); }
> ;
>
Won't current_type still be integral after this? Try 1 / 2 / 3.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 7+ messages in thread* RE: [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double
2008-01-31 22:43 ` Daniel Jacobowitz
@ 2008-02-01 7:29 ` Pierre Muller
2008-02-01 14:16 ` 'Daniel Jacobowitz'
0 siblings, 1 reply; 7+ messages in thread
From: Pierre Muller @ 2008-02-01 7:29 UTC (permalink / raw)
To: 'Daniel Jacobowitz'; +Cc: gdb-patches
> -----Original Message-----
> From: Daniel Jacobowitz [mailto:drow@false.org]
> Sent: Thursday, January 31, 2008 11:27 PM
> To: Pierre Muller
> Cc: gdb-patches@sourceware.org
> Subject: Re: [Patch] p-exp.y: Typecast left operand of BINOP_DIV to
> long double
>
> On Mon, Jan 28, 2008 at 04:47:26PM +0100, Pierre Muller wrote:
> > Could someone please confirm that the
> > way I inserted the implicit typecast in the parser is
> > correct?
> > All comments most welcome.
>
> It looks OK to me. Does the type of the left operand completely
> determine the type of the operation, or do you need to worry about the
> type of the right-hand exp too before you cast?
But how can I do this?
It is still not really clear to me how I can
insert a typecast to left operand, only after
right operand has been parsed.
It would indeed be better to only do the typecast if both are integral
types.
> > @@ -367,7 +370,15 @@ exp : exp '*' exp
> > { write_exp_elt_opcode (BINOP_MUL); }
> > ;
> >
> > -exp : exp '/' exp
> > +exp : exp '/' {
> > + if (current_type && is_integral_type
> > (current_type))
> > + {
> > + write_exp_elt_opcode (UNOP_CAST);
> > + write_exp_elt_type
> (builtin_type_long_double);
> > + write_exp_elt_opcode (UNOP_CAST);
> > + }
> > + }
> > + exp
> > { write_exp_elt_opcode (BINOP_DIV); }
> > ;
> >
>
> Won't current_type still be integral after this? Try 1 / 2 / 3.
Whoops, of course, this lacks a
current_type = builtin_type_long_double
assignment.
Thanks for the comments.
Pierre
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double
2008-02-01 7:29 ` Pierre Muller
@ 2008-02-01 14:16 ` 'Daniel Jacobowitz'
2008-02-01 15:55 ` Pierre Muller
0 siblings, 1 reply; 7+ messages in thread
From: 'Daniel Jacobowitz' @ 2008-02-01 14:16 UTC (permalink / raw)
To: Pierre Muller; +Cc: gdb-patches
On Fri, Feb 01, 2008 at 08:28:52AM +0100, Pierre Muller wrote:
> > It looks OK to me. Does the type of the left operand completely
> > determine the type of the operation, or do you need to worry about the
> > type of the right-hand exp too before you cast?
>
> But how can I do this?
> It is still not really clear to me how I can
> insert a typecast to left operand, only after
> right operand has been parsed.
> It would indeed be better to only do the typecast if both are integral
> types.
You could cast the right operand instead; wouldn't that work?
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double
2008-02-01 14:16 ` 'Daniel Jacobowitz'
@ 2008-02-01 15:55 ` Pierre Muller
2008-02-01 17:00 ` Doug Evans
0 siblings, 1 reply; 7+ messages in thread
From: Pierre Muller @ 2008-02-01 15:55 UTC (permalink / raw)
To: 'Daniel Jacobowitz'; +Cc: gdb-patches
> -----Original Message-----
> From: 'Daniel Jacobowitz' [mailto:drow@false.org]
> Sent: Friday, February 01, 2008 3:16 PM
> To: Pierre Muller
> Cc: gdb-patches@sourceware.org
> Subject: Re: [Patch] p-exp.y: Typecast left operand of BINOP_DIV to
> long double
>
> On Fri, Feb 01, 2008 at 08:28:52AM +0100, Pierre Muller wrote:
> > > It looks OK to me. Does the type of the left operand completely
> > > determine the type of the operation, or do you need to worry about
> the
> > > type of the right-hand exp too before you cast?
> >
> > But how can I do this?
> > It is still not really clear to me how I can
> > insert a typecast to left operand, only after
> > right operand has been parsed.
> > It would indeed be better to only do the typecast if both are
> integral
> > types.
>
> You could cast the right operand instead; wouldn't that work?
Once the patch from Doug
http://sourceware.org/ml/gdb-patches/2008-01/msg00802.html
is committed, yes.
Until then the ptyp '34 / 3'
would still give the wrong type,
that is the reason why I chose to typecast
the left operand instead of the right one.
As that patch is likely not to be integrated
in 6.8, I thought that it would be better
to have also a correct output for ptype command.
Pierre Muller
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-02-01 17:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-28 17:08 [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double Pierre Muller
2008-01-31 22:43 ` Daniel Jacobowitz
2008-02-01 7:29 ` Pierre Muller
2008-02-01 14:16 ` 'Daniel Jacobowitz'
2008-02-01 15:55 ` Pierre Muller
2008-02-01 17:00 ` Doug Evans
2008-02-01 17:04 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox