From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23108 invoked by alias); 23 Jan 2008 23:09:52 -0000 Received: (qmail 23098 invoked by uid 22791); 23 Jan 2008 23:09:51 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 23 Jan 2008 23:09:34 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 23AC42A9659; Wed, 23 Jan 2008 18:09:32 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id UumbOPcg3dkD; Wed, 23 Jan 2008 18:09:32 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id BF8222A9657; Wed, 23 Jan 2008 18:09:31 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 759D4E7ACB; Wed, 23 Jan 2008 15:09:29 -0800 (PST) Date: Wed, 23 Jan 2008 23:09:00 -0000 From: Joel Brobecker To: Pierre Muller Cc: 'Eli Zaretskii' , gdb-patches@sourceware.org Subject: Re: [RFA] Handle BINOP_INTDIV in valarith.c Message-ID: <20080123230929.GC3979@adacore.com> References: <002d01c85849$ef420f80$cdc62e80$@u-strasbg.fr> <002401c85c1a$b1997b30$14cc7190$@u-strasbg.fr> <20080123182514.GB3979@adacore.com> <001b01c85e10$48a8aa40$d9f9fec0$@u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001b01c85e10$48a8aa40$d9f9fec0$@u-strasbg.fr> User-Agent: Mutt/1.4.2.2i 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/msg00570.txt.bz2 > 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