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]

[Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double


  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); }
        ;



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