This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFC] Add code to support evaluating Fortran exponentiation expression
- From: Wu Zhou <woodzltc at cn dot ibm dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Fri, 17 Jun 2005 13:22:26 +0800 (CST)
- Subject: [RFC] Add code to support evaluating Fortran exponentiation expression
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 <woodzltc@cn.ibm.com>
* 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