From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19408 invoked by alias); 28 Jan 2008 15:48:09 -0000 Received: (qmail 19396 invoked by uid 22791); 28 Jan 2008 15:48:08 -0000 X-Spam-Check-By: sourceware.org Received: from ics.u-strasbg.fr (HELO ics.u-strasbg.fr) (130.79.112.250) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 28 Jan 2008 15:47:19 +0000 Received: from ICSMULLER (laocoon.u-strasbg.fr [130.79.112.72]) by ics.u-strasbg.fr (Postfix) with ESMTP id 59C5C18701C for ; Mon, 28 Jan 2008 16:53:40 +0100 (CET) From: "Pierre Muller" To: Subject: [Patch] p-exp.y: Typecast left operand of BINOP_DIV to long double Date: Mon, 28 Jan 2008 17:08:00 -0000 Message-ID: <000c01c861c5$149352b0$3db9f810$@u-strasbg.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Content-Language: en-us Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00644.txt.bz2 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 * 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); } ;