+2004-08-08 Victor Leikehman <lei@il.ibm.com>
+
+ * simplify.c (gfc_simplify_shape): Bugfix.
+ * expr.c (gfc_copy_shape_excluding): New function.
+ * gfortran.h (gfc_get_shape): Bugfix.
+ (gfc_copy_shape_excluding): Added declaration.
+ * iresolve.c (gfc_resolve_all, gfc_resolve_any, gfc_resolve_count,
+ gfc_resolve_cshift, gfc_resolve_eoshift, gfc_resolve_lbound,
+ gfc_resolve_ubound, gfc_resolve_transpose): Added compile
+ time resolution of shape.
+
2004-08-06 Janne Blomqvist <jblomqvi@cc.hut.fi>
* intrinsic.c (add_subroutines): Add getenv and
}
+/* Copy a shape array excluding dimension N, where N is an integer
+ constant expression. Dimensions are numbered in fortran style --
+ starting with ONE.
+
+ So, if the original shape array contains R elements
+ { s1 ... sN-1 sN sN+1 ... sR-1 sR}
+ the result contains R-1 elements:
+ { s1 ... sN-1 sN+1 ... sR-1}
+
+ If anything goes wrong -- N is not a constant, its value is out
+ of range -- or anything else, just returns NULL.
+*/
+
+mpz_t *
+gfc_copy_shape_excluding (mpz_t * shape, int rank, gfc_expr * dim)
+{
+ mpz_t *new_shape, *s;
+ int i, n;
+
+ if (shape == NULL
+ || rank <= 1
+ || dim == NULL
+ || dim->expr_type != EXPR_CONSTANT
+ || dim->ts.type != BT_INTEGER)
+ return NULL;
+
+ n = mpz_get_si (dim->value.integer);
+ n--; /* Convert to zero based index */
+ if (n < 0 && n >= rank)
+ return NULL;
+
+ s = new_shape = gfc_get_shape (rank-1);
+
+ for (i = 0; i < rank; i++)
+ {
+ if (i == n)
+ continue;
+ mpz_init_set (*s, shape[i]);
+ s++;
+ }
+
+ return new_shape;
+}
+
/* Given an expression pointer, return a copy of the expression. This
subroutine is recursive. */
gfc_expr;
-#define gfc_get_shape(rank) ((mpz_t *) gfc_getmem(rank*sizeof(mpz_t)))
+#define gfc_get_shape(rank) ((mpz_t *) gfc_getmem((rank)*sizeof(mpz_t)))
/* Structures for information associated with different kinds of
numbers. The first set of integer parameters define all there is
gfc_expr *gfc_int_expr (int);
gfc_expr *gfc_logical_expr (int, locus *);
mpz_t *gfc_copy_shape (mpz_t *, int);
+mpz_t *gfc_copy_shape_excluding (mpz_t *, int, gfc_expr *);
gfc_expr *gfc_copy_expr (gfc_expr *);
try gfc_specification_expr (gfc_expr *);
#include "config.h"
#include <string.h>
#include <stdarg.h>
+#include <assert.h>
#include "gfortran.h"
#include "intrinsic.h"
{
gfc_resolve_index (dim, 1);
f->rank = mask->rank - 1;
+ f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
}
f->value.function.name =
{
gfc_resolve_index (dim, 1);
f->rank = mask->rank - 1;
+ f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
}
f->value.function.name =
{
f->rank = mask->rank - 1;
gfc_resolve_index (dim, 1);
+ f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
}
f->value.function.name =
f->ts = array->ts;
f->rank = array->rank;
+ f->shape = gfc_copy_shape (array->shape, array->rank);
if (shift->rank > 0)
n = 1;
f->ts = array->ts;
f->rank = array->rank;
+ f->shape = gfc_copy_shape (array->shape, array->rank);
n = 0;
if (shift->rank > 0)
void
-gfc_resolve_lbound (gfc_expr * f, gfc_expr * array ATTRIBUTE_UNUSED,
+gfc_resolve_lbound (gfc_expr * f, gfc_expr * array,
gfc_expr * dim)
{
static char lbound[] = "__lbound";
f->ts.type = BT_INTEGER;
f->ts.kind = gfc_default_integer_kind ();
- f->rank = (dim == NULL) ? 1 : 0;
+ if (dim == NULL)
+ {
+ f->rank = 1;
+ f->shape = gfc_get_shape (1);
+ mpz_init_set_ui (f->shape[0], array->rank);
+ }
+
f->value.function.name = lbound;
}
f->ts = matrix->ts;
f->rank = 2;
+ if (matrix->shape)
+ {
+ f->shape = gfc_get_shape (2);
+ mpz_init_set (f->shape[0], matrix->shape[1]);
+ mpz_init_set (f->shape[1], matrix->shape[0]);
+ }
switch (matrix->ts.type)
{
void
-gfc_resolve_ubound (gfc_expr * f, gfc_expr * array ATTRIBUTE_UNUSED,
+gfc_resolve_ubound (gfc_expr * f, gfc_expr * array,
gfc_expr * dim)
{
static char ubound[] = "__ubound";
f->ts.type = BT_INTEGER;
f->ts.kind = gfc_default_integer_kind ();
- f->rank = (dim == NULL) ? 1 : 0;
+ if (dim == NULL)
+ {
+ f->rank = 1;
+ f->shape = gfc_get_shape (1);
+ mpz_init_set_ui (f->shape[0], array->rank);
+ }
+
f->value.function.name = ubound;
}
int n;
try t;
+ if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
+ return NULL;
+
result = gfc_start_constructor (BT_INTEGER, gfc_default_integer_kind (),
&source->where);
- if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
- return result;
-
ar = gfc_find_array_ref (source);
t = gfc_array_ref_shape (ar, shape);