This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[patch, fortran-exp] constructor cleanup


Hi all,

attached patch removes two functions that were implemented for constructors in 
list-style. The changes are simple and mainly straight forward find-and-
replace.

Regression tested on i686-pc-linux-gnu; there are no actual regressions, but a 
failure in initialization_20.f90. That testcase checks for an error message on 
constructors that are too big to be expanded. I'd like to keep the failure for 
now as a reminder to put that check back later on (there's a TODO in the 
appropriate place in the code).

Ok for fortran-exp?

Cheers

	Daniel


2010-01-08  Daniel Franke  <franke.daniel@gmail.com>

	* gfortran.h (gfc_start_constructor): Removed.
	(gfc_get_array_element): Removed.
	* array.c (gfc_start_constructor): Removed, use gfc_get_array_expr 
	instead. Updated all callers.
	(extract_element): Removed.
	(gfc_expand_constructor): Temporarily removed check for
	max-array-constructor. Will be re-introduced later if still required.
	(gfc_get_array_element): Removed, use gfc_constructor_lookup_expr
	instead. Updated all callers.
	* expr.c (find_array_section): Replaced manual lookup of elements
	by gfc_constructor_lookup.
Index: gfortran.h
===================================================================
--- gfortran.h	(revision 155723)
+++ gfortran.h	(working copy)
@@ -2677,7 +2677,6 @@ gfc_try gfc_resolve_array_spec (gfc_arra
 
 int gfc_compare_array_spec (gfc_array_spec *, gfc_array_spec *);
 
-gfc_expr *gfc_start_constructor (bt, int, locus *);
 void gfc_simplify_iterator_var (gfc_expr *);
 gfc_try gfc_expand_constructor (gfc_expr *);
 int gfc_constant_ac (gfc_expr *);
@@ -2687,7 +2686,6 @@ gfc_try gfc_resolve_array_constructor (g
 gfc_try gfc_check_constructor_type (gfc_expr *);
 gfc_try gfc_check_iter_variable (gfc_expr *);
 gfc_try gfc_check_constructor (gfc_expr *, gfc_try (*)(gfc_expr *));
-gfc_expr *gfc_get_array_element (gfc_expr *, int);
 gfc_try gfc_array_size (gfc_expr *, mpz_t *);
 gfc_try gfc_array_dimen_size (gfc_expr *, int, mpz_t *);
 gfc_try gfc_array_ref_shape (gfc_array_ref *, mpz_t *);
Index: array.c
===================================================================
--- array.c	(revision 155723)
+++ array.c	(working copy)
@@ -566,26 +566,6 @@ gfc_compare_array_spec (gfc_array_spec *
 
 /****************** Array constructor functions ******************/
 
-/* Start an array constructor.  The constructor starts with zero
-   elements and should be appended to by gfc_append_constructor().  */
-
-gfc_expr *
-gfc_start_constructor (bt type, int kind, locus *where)
-{
-  gfc_expr *result;
-
-  result = gfc_get_expr ();
-
-  result->expr_type = EXPR_ARRAY;
-  result->rank = 1;
-
-  result->ts.type = type;
-  result->ts.kind = kind;
-  result->where = *where;
-  return result;
-}
-
-
 
 /* Given an expression node that might be an array constructor and a
    symbol, make sure that no iterators in this or child constructors
@@ -1083,29 +1063,6 @@ count_elements (gfc_expr *e)
 }
 
 
-/* Work function that extracts a particular element from an array
-   constructor, freeing the rest.  */
-
-static gfc_try
-extract_element (gfc_expr *e)
-{
-
-  if (e->rank != 0)
-    {                          /* Something unextractable */
-      gfc_free_expr (e);
-      return FAILURE;
-    }
-
-  if (current_expand.extract_count == current_expand.extract_n)
-    current_expand.extracted = e;
-  else
-    gfc_free_expr (e);
-
-  current_expand.extract_count++;
-  return SUCCESS;
-}
-
-
 /* Work function that constructs a new constructor out of the old one,
    stringing new elements together.  */
 
@@ -1296,15 +1253,10 @@ gfc_try
 gfc_expand_constructor (gfc_expr *e)
 {
   expand_info expand_save;
-  gfc_expr *f;
   gfc_try rc;
 
-  f = gfc_get_array_element (e, gfc_option.flag_max_array_constructor);
-  if (f != NULL)
-    {
-      gfc_free_expr (f);
-      return SUCCESS;
-    }
+  /* TODO: Removed check against flag_max_array_constructor.
+     Might be necessary to re-introduce it later?!  */
 
   expand_save = current_expand;
   current_expand.base = NULL;
@@ -1592,38 +1544,6 @@ gfc_copy_iterator (gfc_iterator *src)
   return dest;
 }
 
-/* Given an array expression and an element number (starting at zero),
-   return a pointer to the array element.  NULL is returned if the
-   size of the array has been exceeded.  The expression node returned
-   remains a part of the array and should not be freed.  Access is not
-   efficient at all, but this is another place where things do not
-   have to be particularly fast.  */
-
-gfc_expr *
-gfc_get_array_element (gfc_expr *array, int element)
-{
-  expand_info expand_save;
-  gfc_expr *e;
-  gfc_try rc;
-
-  expand_save = current_expand;
-  current_expand.extract_n = element;
-  current_expand.expand_work_function = extract_element;
-  current_expand.extracted = NULL;
-  current_expand.extract_count = 0;
-
-  iter_stack = NULL;
-
-  rc = expand_constructor (array->value.constructor);
-  e = current_expand.extracted;
-  current_expand = expand_save;
-
-  if (rc == FAILURE)
-    return NULL;
-
-  return e;
-}
-
 
 /********* Subroutines for determining the size of an array *********/
 
Index: check.c
===================================================================
--- check.c	(revision 155723)
+++ check.c	(working copy)
@@ -2510,12 +2510,9 @@ gfc_check_reshape (gfc_expr *source, gfc
       int i, extent;
       for (i = 0; i < shape_size; ++i)
 	{
-	  e = gfc_get_array_element (shape, i);
+	  e = gfc_constructor_lookup_expr (shape->value.constructor, i);
 	  if (e->expr_type != EXPR_CONSTANT)
-	    {
-	      gfc_free_expr (e);
-	      continue;
-	    }
+	    continue;
 
 	  gfc_extract_int (e, &extent);
 	  if (extent < 0)
@@ -2525,8 +2522,6 @@ gfc_check_reshape (gfc_expr *source, gfc
 			 gfc_current_intrinsic, &e->where, extent);
 	      return FAILURE;
 	    }
-
-	  gfc_free_expr (e);
 	}
     }
 
@@ -2571,12 +2566,9 @@ gfc_check_reshape (gfc_expr *source, gfc
 
 	  for (i = 1; i <= order_size; ++i)
 	    {
-	      e = gfc_get_array_element (order, i-1);
+	      e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
 	      if (e->expr_type != EXPR_CONSTANT)
-		{
-		  gfc_free_expr (e);
-		  continue;
-		}
+		continue;
 
 	      gfc_extract_int (e, &dim);
 
@@ -2599,7 +2591,6 @@ gfc_check_reshape (gfc_expr *source, gfc
 		}
 
 	      perm[dim-1] = 1;
-	      gfc_free_expr (e);
 	    }
 	}
     }
Index: expr.c
===================================================================
--- expr.c	(revision 155723)
+++ expr.c	(working copy)
@@ -1335,7 +1335,6 @@ find_array_section (gfc_expr *expr, gfc_
   mpz_t tmp_mpz;
   mpz_t nelts;
   mpz_t ptr;
-  mpz_t index;
   gfc_constructor_base base;
   gfc_constructor *cons, *vecsub[GFC_MAX_DIMENSIONS];
   gfc_expr *begin;
@@ -1491,7 +1490,6 @@ find_array_section (gfc_expr *expr, gfc_
       mpz_mul (delta_mpz, delta_mpz, tmp_mpz);
     }
 
-  mpz_init (index);
   mpz_init (ptr);
   cons = gfc_constructor_first (base);
 
@@ -1541,27 +1539,13 @@ find_array_section (gfc_expr *expr, gfc_
 	    }
 	}
 
-      /* There must be a better way of dealing with negative strides
-	 than resetting the index and the constructor pointer!  */ 
-      if (mpz_cmp (ptr, index) < 0)
-	{
-	  mpz_set_ui (index, 0);
-	  cons = gfc_constructor_first (base);
-	}
-
-      while (cons && gfc_constructor_next (cons)
-	     && mpz_cmp (ptr, index) > 0)
-        {
-	  cons = gfc_constructor_next (cons);
-	  mpz_add_ui (index, index, one);
-	}
-
+      cons = gfc_constructor_lookup (base, mpz_get_ui (ptr));
+      gcc_assert (cons);
       gfc_constructor_append_expr (&expr->value.constructor,
 				   gfc_copy_expr (cons->expr), NULL);
     }
 
   mpz_clear (ptr);
-  mpz_clear (index);
 
 cleanup:
 
Index: simplify.c
===================================================================
--- simplify.c	(revision 155723)
+++ simplify.c	(working copy)
@@ -369,7 +369,7 @@ transformational_result (gfc_expr *array
   if (!dim || array->rank == 1)
     return gfc_get_constant_expr (type, kind, where);
 
-  result = gfc_start_constructor (type, kind, where);
+  result = gfc_get_array_expr (type, kind, where);
   result->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
   result->rank = array->rank - 1;
 
@@ -3296,9 +3296,9 @@ gfc_simplify_matmul (gfc_expr *matrix_a,
     return NULL;
 
   gcc_assert (gfc_compare_types (&matrix_a->ts, &matrix_b->ts));
-  result = gfc_start_constructor (matrix_a->ts.type,
-				  matrix_a->ts.kind,
-				  &matrix_a->where);
+  result = gfc_get_array_expr (matrix_a->ts.type,
+			       matrix_a->ts.kind,
+			       &matrix_a->where);
 
   if (matrix_a->rank == 1 && matrix_b->rank == 2)
     {
@@ -3886,9 +3886,7 @@ gfc_simplify_pack (gfc_expr *array, gfc_
           && !is_constant_array_expr(mask)))
     return NULL;
 
-  result = gfc_start_constructor (array->ts.type, 
-				  array->ts.kind,
-				  &array->where);
+  result = gfc_get_array_expr (array->ts.type, array->ts.kind, &array->where);
 
   array_ctor = gfc_constructor_first (array->value.constructor);
   vector_ctor = vector
@@ -4248,7 +4246,7 @@ gfc_simplify_reshape (gfc_expr *source, 
 
   for (;;)
     {
-      e = gfc_get_array_element (shape_exp, rank);
+      e = gfc_constructor_lookup_expr (shape_exp->value.constructor, rank);
       if (e == NULL)
 	break;
 
@@ -4257,7 +4255,6 @@ gfc_simplify_reshape (gfc_expr *source, 
       gcc_assert (rank >= 0 && rank < GFC_MAX_DIMENSIONS);
       gcc_assert (shape[rank] >= 0);
 
-      gfc_free_expr (e);
       rank++;
     }
 
@@ -4276,11 +4273,10 @@ gfc_simplify_reshape (gfc_expr *source, 
 
       for (i = 0; i < rank; i++)
 	{
-	  e = gfc_get_array_element (order_exp, i);
+	  e = gfc_constructor_lookup_expr (order_exp->value.constructor, i);
 	  gcc_assert (e);
 
 	  gfc_extract_int (e, &order[i]);
-	  gfc_free_expr (e);
 
 	  gcc_assert (order[i] >= 1 && order[i] <= rank);
 	  order[i]--;
@@ -4336,19 +4332,19 @@ gfc_simplify_reshape (gfc_expr *source, 
       j = mpz_get_ui (index);
 
       if (j < nsource)
-	e = gfc_get_array_element (source, j);
+	e = gfc_constructor_lookup_expr (source->value.constructor, j);
       else
 	{
 	  gcc_assert (npad > 0);
 
 	  j = j - nsource;
 	  j = j % npad;
-	  e = gfc_get_array_element (pad, j);
+	  e = gfc_constructor_lookup_expr (pad->value.constructor, j);
 	}
       gcc_assert (e);
 
       gfc_constructor_append_expr (&result->value.constructor,
-				   e, &e->where);
+				   gfc_copy_expr (e), &e->where);
 
       /* Calculate the next element.  */
       i = 0;
@@ -4726,14 +4722,14 @@ gfc_simplify_shape (gfc_expr *source)
   gfc_try t;
 
   if (source->rank == 0)
-    return gfc_start_constructor (BT_INTEGER, gfc_default_integer_kind,
-				  &source->where);
+    return gfc_get_array_expr (BT_INTEGER, gfc_default_integer_kind,
+			       &source->where);
 
   if (source->expr_type != EXPR_VARIABLE)
     return NULL;
 
-  result = gfc_start_constructor (BT_INTEGER, gfc_default_integer_kind,
-				  &source->where);
+  result = gfc_get_array_expr (BT_INTEGER, gfc_default_integer_kind,
+			       &source->where);
 
   ar = gfc_find_array_ref (source);
 
@@ -4980,9 +4976,8 @@ gfc_simplify_spread (gfc_expr *source, g
     {
       gcc_assert (dim == 0);
 
-      result = gfc_start_constructor (source->ts.type,
-				      source->ts.kind,
-				      &source->where);
+      result = gfc_get_array_expr (source->ts.type, source->ts.kind,
+				   &source->where);
       result->rank = 1;
       result->shape = gfc_get_shape (result->rank);
       mpz_init_set_si (result->shape[0], ncopies);
@@ -4999,9 +4994,8 @@ gfc_simplify_spread (gfc_expr *source, g
       gcc_assert (source->rank < GFC_MAX_DIMENSIONS);
       gcc_assert (dim >= 0 && dim <= source->rank);
 
-      result = gfc_start_constructor (source->ts.type,
-				      source->ts.kind,
-				      &source->where);
+      result = gfc_get_array_expr (source->ts.type, source->ts.kind,
+				   &source->where);
       result->rank = source->rank + 1;
       result->shape = gfc_get_shape (result->rank);
 
@@ -5296,7 +5290,8 @@ gfc_simplify_transpose (gfc_expr *matrix
 
   gcc_assert (matrix->rank == 2);
 
-  result = gfc_start_constructor (matrix->ts.type, matrix->ts.kind, &matrix->where);
+  result = gfc_get_array_expr (matrix->ts.type, matrix->ts.kind,
+			       &matrix->where);
   result->rank = 2;
   result->shape = gfc_get_shape (result->rank);
   mpz_set (result->shape[0], matrix->shape[1]);
@@ -5373,9 +5368,8 @@ gfc_simplify_unpack (gfc_expr *vector, g
 	  && !is_constant_array_expr(field)))
     return NULL;
 
-  result = gfc_start_constructor (vector->ts.type,
-				  vector->ts.kind,
-				  &vector->where);
+  result = gfc_get_array_expr (vector->ts.type, vector->ts.kind,
+			       &vector->where);
   result->rank = mask->rank;
   result->shape = gfc_copy_shape (mask->shape, mask->rank);
 

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