From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10129 invoked by alias); 17 Jun 2005 07:36:50 -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 10101 invoked by uid 22791); 17 Jun 2005 07:36:38 -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; Fri, 17 Jun 2005 07:36:38 +0000 Received: from sd0112e0.au.ibm.com (d23rh903.au.ibm.com [202.81.18.201]) by ausmtp01.au.ibm.com (8.12.10/8.12.10) with ESMTP id j5H72jkS169980 for ; Fri, 17 Jun 2005 17:03:20 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.250.243]) by sd0112e0.au.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id j5H6woCC083802 for ; Fri, 17 Jun 2005 17:03:00 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.12.11/8.13.3) with ESMTP id j5H6pj3W032460 for ; Fri, 17 Jun 2005 16:51:45 +1000 Received: from wks190384wss.cn.ibm.com (wks190384wss.cn.ibm.com [9.181.134.93]) by d23av02.au.ibm.com (8.12.11/8.12.11) with ESMTP id j5H6pdhB032310 for ; Fri, 17 Jun 2005 16:51:42 +1000 Date: Fri, 17 Jun 2005 07:36:00 -0000 From: Wu Zhou X-X-Sender: woodzltc@localhost.localdomain To: gdb-patches@sources.redhat.com Subject: [RFC] Add code to support evaluating Fortran exponentiation expression Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2005-06/txt/msg00246.txt.bz2 Hello all, There is no support for evaluating Fortran exponentiation expression in current GDB. I added some code (the patch is attached below) to do this. And had tested it with g77-3.2.3 and g77-3.3.3. Following is the related gdb session. Please review and comment. Thanks. [woodzltc@localhost build]$ ./gdb/gdb -q (gdb) set language fortran (gdb) p 2 ** 3 $1 = 8 (gdb) p 2 ** 2 ** 3 $2 = 256 (gdb) p (2 ** 2) ** 3 $3 = 64 (gdb) p 2 ** 0.5 $4 = 1.4142135623730951 (gdb) Here goes the patch: 2005-06-17 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 17 Jun 2005 06:30:52 -0000 *************** 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 17 Jun 2005 06:30:52 -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 17 Jun 2005 06:30:53 -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