This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Add code to support evaluating Fortran exponentiationexpression


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  <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	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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]