[PATCH,gfortran] constify a function

Steve Kargl sgk@troutmask.apl.washington.edu
Thu Dec 30 21:50:00 GMT 2004


On Wed, Dec 29, 2004 at 07:30:44PM -0800, Steve Kargl wrote:
> The attached patch constifies the arguments to compare_case,
> and then removes the unneeded pointer assignment and local
> variables.
> 
> bubblestrapped and regression tested on i386-*-freebsd6.0
> 
> 2004-12-29  Steven G. Kargl  <kargls@comcast.net>
>         * resolve.c (compare_case): Constify

After reading and understanding what compare_case() does,
I decide to clean up because several of the if statements
could be collpased.

2004-12-30  Steven G. Kargl  <kargls@comcast.net>
         * resolve.c (compare_case): Constify and cleanup

-- 
Steve
-------------- next part --------------
Index: resolve.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/resolve.c,v
retrieving revision 1.24
diff -u -b -u -r1.24 resolve.c
--- resolve.c	15 Dec 2004 03:56:05 -0000	1.24
+++ resolve.c	30 Dec 2004 19:51:20 -0000
@@ -2491,89 +2491,52 @@
 
 /* Callback function for our mergesort variant.  Determines interval
    overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
-   op1 > op2.  Assumes we're not dealing with the default case.  */
+   op1 > op2.  Assumes we're not dealing with the default case.  
+   We have op1 = (:L), (K:L), or (K:) and op2 = (:N), (M:N), and (M:).
+   There are nine situations to check.  */
 
 static int
-compare_cases (const void * _op1, const void * _op2)
+compare_cases (const gfc_case * op1, const gfc_case * op2)
 {
-  const gfc_case *op1, *op2;
+  int retval;
 
-  op1 = (const gfc_case *) _op1;
-  op2 = (const gfc_case *) _op2;
-
-  if (op1->low == NULL) /* op1 = (:N) */
+  if (op1->low == NULL) /* op1 = (:L)  */
     {
-      if (op2->low == NULL) /* op2 = (:M), so overlap.  */
-        return 0;
-
-      else if (op2->high == NULL) /* op2 = (M:) */
+      /* op2 = (:N), so overlap.  */
+      retval = 0;
+      /* op2 = (M:) or (M:N),  L < M  */
+      if (op2->low != NULL
+	  && gfc_compare_expr (op1->high, op2->low) < 0)
+	retval = -1;
+    }
+  else if (op1->high == NULL) /* op1 = (K:)  */
+    {
+      /* op2 = (M:), so overlap.  */
+      retval = 0;
+      /* op2 = (:N) or (M:N), K > N  */
+      if (op2->high != NULL
+	  && gfc_compare_expr (op1->low, op2->high) > 0)
+	retval = 1;
+    }
+  else /* op1 = (K:L)  */
+    {
+      if (op2->low == NULL)       /* op2 = (:N), K > N  */
+	retval = (gfc_compare_expr (op1->low, op2->high) > 0) ? 1 : 0;
+      else if (op2->high == NULL) /* op2 = (M:), L < M  */
+	retval = (gfc_compare_expr (op1->high, op2->low) < 0) ? -1 : 0;
+      else                        /* op2 = (M:N)  */
         {
+	  retval =  0;
+          /* L < M  */
 	  if (gfc_compare_expr (op1->high, op2->low) < 0)
-	    return -1;  /* N < M */
-	  else
-	    return 0;
-	}
-
-      else /* op2 = (L:M) */
-        {
-	  if (gfc_compare_expr (op1->high, op2->low) < 0)
-	    return -1; /* N < L */
-	  else
-	    return 0;
-	}
-    }
-
-  else if (op1->high == NULL) /* op1 = (N:) */
-    {
-      if (op2->low == NULL) /* op2 = (:M)  */
-        {
-	  if (gfc_compare_expr (op1->low, op2->high) > 0)
-	    return 1; /* N > M */
-	  else
-	    return 0;
-	}
-
-      else if (op2->high == NULL) /* op2 = (M:), so overlap.  */
-        return 0;
-
-      else /* op2 = (L:M) */
-        {
-	  if (gfc_compare_expr (op1->low, op2->high) > 0)
-	    return 1; /* N > M */
-	  else
-	    return 0;
+	    retval =  -1;
+          /* K > N  */
+	  else if (gfc_compare_expr (op1->low, op2->high) > 0)
+	    retval =  1;
 	}
     }
 
-  else /* op1 = (N:P) */
-    {
-      if (op2->low == NULL) /* op2 = (:M)  */
-        {
-	  if (gfc_compare_expr (op1->low, op2->high) > 0)
-	    return 1; /* N > M */
-	  else
-	    return 0;
-	}
-
-      else if (op2->high == NULL) /* op2 = (M:)  */
-        {
-	  if (gfc_compare_expr (op1->high, op2->low) < 0)
-	    return -1; /* P < M */
-	  else
-	    return 0;
-	}
-
-      else /* op2 = (L:M) */
-        {
-	  if (gfc_compare_expr (op1->high, op2->low) < 0)
-	    return -1; /* P < L */
-
-	  if (gfc_compare_expr (op1->low, op2->high) > 0)
-	    return 1; /* N > M */
-
-	  return 0;
-	}
-    }
+  return retval;
 }
 
 


More information about the Fortran mailing list