From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24223 invoked by alias); 20 Jun 2005 04:14:28 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 24205 invoked by uid 22791); 20 Jun 2005 04:14:21 -0000 Received: from ausmtp01.au.ibm.com (HELO ausmtp01.au.ibm.com) (202.81.18.186) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Mon, 20 Jun 2005 04:14:21 +0000 Received: from sd0208e0.au.ibm.com (d23rh904.au.ibm.com [202.81.18.202]) by ausmtp01.au.ibm.com (8.12.10/8.12.10) with ESMTP id j5K4GZeU042976 for ; Mon, 20 Jun 2005 14:16:38 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.250.242]) by sd0208e0.au.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id j5K4H1xI129332 for ; Mon, 20 Jun 2005 14:17:01 +1000 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.12.11/8.13.3) with ESMTP id j5K4E7UP018566 for ; Mon, 20 Jun 2005 14:14:07 +1000 Received: from wks190384wss.cn.ibm.com (wks190384wss.cn.ibm.com [9.181.134.93] (may be forged)) by d23av01.au.ibm.com (8.12.11/8.12.11) with ESMTP id j5K4E4MT018497; Mon, 20 Jun 2005 14:14:05 +1000 Date: Mon, 20 Jun 2005 04:14:00 -0000 From: Wu Zhou To: Daniel Jacobowitz cc: gdb-patches@sources.redhat.com Subject: Re: [RFC] Add code to support evaluating Fortran exponentiation expression In-Reply-To: <20050617134139.GC23901@nevyn.them.org> Message-ID: References: <20050617134139.GC23901@nevyn.them.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2005-06/txt/msg00314.txt.bz2 On Fri, 17 Jun 2005, Daniel Jacobowitz wrote: > This will need a testcase, in addition to documentation. Doing those > separately is fine. The only other problem is that f-exp.y needs a > copyright year update: the last listed year is 2001, but I see it has > been modified in 2002, 2003, and 2004. So please add all of those > years (plus 2005). Daniel, The re-worked patch (copyright year updated) is included as follows. OK to commit? Thanks. 2005-06-20 Wu Zhou * f-exp.y (yyparse): Add code to support exponentiation expression. (yylex): Add code to scan exponentiation operator. * eval.c (evaluate_subexp_standard): Add support for BINOP_EXP. * valarith.c (value_binop): Reset errno to 0 before calling pow to do exponentiation operation. Index: f-exp.y =================================================================== RCS file: /cvs/src/src/gdb/f-exp.y,v retrieving revision 1.16 diff -c -p -r1.16 f-exp.y *** f-exp.y 12 Dec 2004 21:48:55 -0000 1.16 --- f-exp.y 20 Jun 2005 03:20:30 -0000 *************** *** 1,6 **** /* YACC parser for Fortran expressions, for GDB. ! Copyright 1986, 1989, 1990, 1991, 1993, 1994, 1995, 1996, 2000, 2001 ! Free Software Foundation, Inc. Contributed by Motorola. Adapted from the C parser by Farooq Butt (fmbutt@engage.sps.mot.com). --- 1,6 ---- /* YACC parser for Fortran expressions, for GDB. ! Copyright 1986, 1989, 1990, 1991, 1993, 1994, 1995, 1996, 2000, 2001, ! 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Contributed by Motorola. Adapted from the C parser by Farooq Butt (fmbutt@engage.sps.mot.com). *************** static int parse_number (char *, int, in *** 217,222 **** --- 217,223 ---- %left '@' %left '+' '-' %left '*' '/' '%' + %right STARSTAR %right UNARY %right '(' *************** exp : exp '@' exp *** 315,320 **** --- 316,325 ---- { write_exp_elt_opcode (BINOP_REPEAT); } ; + exp : exp STARSTAR exp + { write_exp_elt_opcode (BINOP_EXP); } + ; + exp : exp '*' exp { write_exp_elt_opcode (BINOP_MUL); } ; *************** yylex () *** 941,947 **** } } ! /* See if it is a special .foo. operator */ for (i = 0; dot_ops[i].operator != NULL; i++) if (strncmp (tokstart, dot_ops[i].operator, strlen (dot_ops[i].operator)) == 0) --- 946,952 ---- } } ! /* See if it is a special .foo. operator. */ for (i = 0; dot_ops[i].operator != NULL; i++) if (strncmp (tokstart, dot_ops[i].operator, strlen (dot_ops[i].operator)) == 0) *************** yylex () *** 951,956 **** --- 956,970 ---- return dot_ops[i].token; } + /* See if it is an exponentiation operator. */ + + if (strncmp (tokstart, "**", 2) == 0) + { + lexptr += 2; + yylval.opcode = BINOP_EXP; + return STARSTAR; + } + switch (c = *tokstart) { case 0: Index: eval.c =================================================================== RCS file: /cvs/src/src/gdb/eval.c,v retrieving revision 1.56 diff -c -p -r1.56 eval.c *** eval.c 13 Jun 2005 07:23:15 -0000 1.56 --- eval.c 20 Jun 2005 03:20:33 -0000 *************** evaluate_subexp_standard (struct type *e *** 1510,1515 **** --- 1510,1516 ---- else return value_sub (arg1, arg2); + case BINOP_EXP: case BINOP_MUL: case BINOP_DIV: case BINOP_REM: Index: valarith.c =================================================================== RCS file: /cvs/src/src/gdb/valarith.c,v retrieving revision 1.40 diff -c -p -r1.40 valarith.c *** valarith.c 9 May 2005 21:20:35 -0000 1.40 --- valarith.c 20 Jun 2005 03:20:33 -0000 *************** value_binop (struct value *arg1, struct *** 791,801 **** v = v1 / v2; break; ! case BINOP_EXP: ! v = pow (v1, v2); ! if (errno) ! error (_("Cannot perform exponentiation: %s"), safe_strerror (errno)); ! break; default: error (_("Integer-only operation on floating point number.")); --- 791,802 ---- v = v1 / v2; break; ! case BINOP_EXP: ! errno = 0; ! v = pow (v1, v2); ! if (errno) ! error (_("Cannot perform exponentiation: %s"), safe_strerror (errno)); ! break; default: error (_("Integer-only operation on floating point number.")); *************** value_binop (struct value *arg1, struct *** 929,939 **** v = v1 / v2; break; ! case BINOP_EXP: ! v = pow (v1, v2); ! if (errno) ! error (_("Cannot perform exponentiation: %s"), safe_strerror (errno)); ! break; case BINOP_REM: v = v1 % v2; --- 930,941 ---- v = v1 / v2; break; ! case BINOP_EXP: ! errno = 0; ! v = pow (v1, v2); ! if (errno) ! error (_("Cannot perform exponentiation: %s"), safe_strerror (errno)); ! break; case BINOP_REM: v = v1 % v2; *************** value_binop (struct value *arg1, struct *** 1050,1059 **** error (_("Division by zero")); break; ! case BINOP_EXP: ! v = pow (v1, v2); ! if (errno) ! error (_("Cannot perform exponentiation: %s"), safe_strerror (errno)); break; case BINOP_REM: --- 1052,1062 ---- error (_("Division by zero")); break; ! case BINOP_EXP: ! errno = 0; ! v = pow (v1, v2); ! if (errno) ! error (_("Cannot perform exponentiation: %s"), safe_strerror (errno)); break; case BINOP_REM: Cheers - Wu Zhou