@item @emph{Arguments}:
@multitable @columnfractions .15 .70
-@item @var{I} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
-@item @var{J} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
+@item @var{I} @tab The type shall be either a scalar @code{INTEGER(*)}
+type or a scalar @code{LOGICAL} type.
+@item @var{J} @tab The type shall be the same as the type of @var{I}.
@end multitable
@item @emph{Return value}:
-The return type is either @code{INTEGER(*)} or @code{LOGICAL} after
-cross-promotion of the arguments.
+The return type is either a scalar @code{INTEGER(*)} or a scalar
+@code{LOGICAL}. If the kind type parameters differ, then the
+smaller kind type is implicitly converted to larger kind, and the
+return has the larger kind.
@item @emph{Example}:
@smallexample
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
-@item @var{X} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
-@item @var{Y} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
+@item @var{X} @tab The type shall be either a scalar @code{INTEGER(*)}
+type or a scalar @code{LOGICAL} type.
+@item @var{Y} @tab The type shall be the same as the type of @var{X}.
@end multitable
@item @emph{Return value}:
-The return type is either @code{INTEGER(*)} or @code{LOGICAL}
-after cross-promotion of the arguments.
+The return type is either a scalar @code{INTEGER(*)} or a scalar
+@code{LOGICAL}. If the kind type parameters differ, then the
+smaller kind type is implicitly converted to larger kind, and the
+return has the larger kind.
@item @emph{Example}:
@smallexample
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
-@item @var{X} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
-@item @var{Y} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
+@item @var{X} @tab The type shall be either a scalar @code{INTEGER(*)}
+type or a scalar @code{LOGICAL} type.
+@item @var{Y} @tab The type shall be the same as the type of @var{I}.
@end multitable
@item @emph{Return value}:
-The return type is either @code{INTEGER(*)} or @code{LOGICAL}
-after cross-promotion of the arguments.
+The return type is either a scalar @code{INTEGER(*)} or a scalar
+@code{LOGICAL}. If the kind type parameters differ, then the
+smaller kind type is implicitly converted to larger kind, and the
+return has the larger kind.
@item @emph{Example}:
@smallexample
{
result = gfc_constant_result (BT_INTEGER, kind, &x->where);
mpz_and (result->value.integer, x->value.integer, y->value.integer);
+ return range_check (result, "AND");
}
else /* BT_LOGICAL */
{
result = gfc_constant_result (BT_LOGICAL, kind, &x->where);
result->value.logical = x->value.logical && y->value.logical;
+ return result;
}
- return range_check (result, "AND");
}
ts.kind = gfc_default_double_kind;
result = gfc_copy_expr (e);
if (!gfc_convert_boz (result, &ts))
- return &gfc_bad_expr;
+ {
+ gfc_free_expr (result);
+ return &gfc_bad_expr;
+ }
}
return range_check (result, "DBLE");
result = gfc_copy_expr (a);
if (!gfc_convert_boz (result, &ts))
- return &gfc_bad_expr;
+ {
+ gfc_free_expr (result);
+ return &gfc_bad_expr;
+ }
}
else
result = gfc_int2real (a, gfc_default_real_kind);
gfc_expr *
gfc_simplify_int (gfc_expr *e, gfc_expr *k)
{
- gfc_expr *rpart, *rtrunc, *result;
+ gfc_expr *result = NULL;
int kind;
kind = get_kind (BT_INTEGER, k, "INT", gfc_default_integer_kind);
if (e->expr_type != EXPR_CONSTANT)
return NULL;
- result = gfc_constant_result (BT_INTEGER, kind, &e->where);
-
switch (e->ts.type)
{
case BT_INTEGER:
- mpz_set (result->value.integer, e->value.integer);
+ result = gfc_int2int (e, kind);
break;
case BT_REAL:
- rtrunc = gfc_copy_expr (e);
- mpfr_trunc (rtrunc->value.real, e->value.real);
- gfc_mpfr_to_mpz (result->value.integer, rtrunc->value.real);
- gfc_free_expr (rtrunc);
+ result = gfc_real2int (e, kind);
break;
case BT_COMPLEX:
- rpart = gfc_complex2real (e, kind);
- rtrunc = gfc_copy_expr (rpart);
- mpfr_trunc (rtrunc->value.real, rpart->value.real);
- gfc_mpfr_to_mpz (result->value.integer, rtrunc->value.real);
- gfc_free_expr (rpart);
- gfc_free_expr (rtrunc);
+ result = gfc_complex2int (e, kind);
break;
default:
gfc_error ("Argument of INT at %L is not a valid type", &e->where);
- gfc_free_expr (result);
return &gfc_bad_expr;
}
static gfc_expr *
-gfc_simplify_intconv (gfc_expr *e, int kind, const char *name)
+simplify_intconv (gfc_expr *e, int kind, const char *name)
{
- gfc_expr *rpart, *rtrunc, *result;
+ gfc_expr *result = NULL;
if (e->expr_type != EXPR_CONSTANT)
return NULL;
- result = gfc_constant_result (BT_INTEGER, kind, &e->where);
-
switch (e->ts.type)
{
case BT_INTEGER:
- mpz_set (result->value.integer, e->value.integer);
+ result = gfc_int2int (e, kind);
break;
case BT_REAL:
- rtrunc = gfc_copy_expr (e);
- mpfr_trunc (rtrunc->value.real, e->value.real);
- gfc_mpfr_to_mpz (result->value.integer, rtrunc->value.real);
- gfc_free_expr (rtrunc);
+ result = gfc_real2int (e, kind);
break;
case BT_COMPLEX:
- rpart = gfc_complex2real (e, kind);
- rtrunc = gfc_copy_expr (rpart);
- mpfr_trunc (rtrunc->value.real, rpart->value.real);
- gfc_mpfr_to_mpz (result->value.integer, rtrunc->value.real);
- gfc_free_expr (rpart);
- gfc_free_expr (rtrunc);
+ result = gfc_complex2int (e, kind);
break;
default:
gfc_error ("Argument of %s at %L is not a valid type", name, &e->where);
- gfc_free_expr (result);
return &gfc_bad_expr;
}
gfc_expr *
gfc_simplify_int2 (gfc_expr *e)
{
- return gfc_simplify_intconv (e, 2, "INT2");
+ return simplify_intconv (e, 2, "INT2");
}
gfc_expr *
gfc_simplify_int8 (gfc_expr *e)
{
- return gfc_simplify_intconv (e, 8, "INT8");
+ return simplify_intconv (e, 8, "INT8");
}
gfc_expr *
gfc_simplify_long (gfc_expr *e)
{
- return gfc_simplify_intconv (e, 4, "LONG");
+ return simplify_intconv (e, 4, "LONG");
}
k = get_kind (BT_INTEGER, kind, upper ? "UBOUND" : "LBOUND",
gfc_default_integer_kind);
if (k == -1)
- return &gfc_bad_expr;
+ {
+ gfc_free_expr (e);
+ return &gfc_bad_expr;
+ }
e->ts.kind = k;
/* The result is a rank 1 array; its size is the rank of the first
if (mpfr_nan_p (result->value.real) && gfc_option.flag_range_check)
{
gfc_error ("Result of NEAREST is NaN at %L", &result->where);
+ gfc_free_expr (result);
return &gfc_bad_expr;
}
{
result = gfc_constant_result (BT_INTEGER, kind, &x->where);
mpz_ior (result->value.integer, x->value.integer, y->value.integer);
+ return range_check (result, "OR");
}
else /* BT_LOGICAL */
{
result = gfc_constant_result (BT_LOGICAL, kind, &x->where);
result->value.logical = x->value.logical || y->value.logical;
+ return result;
}
-
- return range_check (result, "OR");
}
ts.kind = kind;
result = gfc_copy_expr (e);
if (!gfc_convert_boz (result, &ts))
- return &gfc_bad_expr;
+ {
+ gfc_free_expr (result);
+ return &gfc_bad_expr;
+ }
}
+
return range_check (result, "REAL");
}
goto bad_reshape;
}
- gfc_free_expr (e);
-
if (rank >= GFC_MAX_DIMENSIONS)
{
gfc_error ("Too many dimensions in shape specification for RESHAPE "
"at %L", &e->where);
-
+ gfc_free_expr (e);
goto bad_reshape;
}
{
gfc_error ("Shape specification at %L cannot be negative",
&e->where);
+ gfc_free_expr (e);
goto bad_reshape;
}
+ gfc_free_expr (e);
rank++;
}
goto bad_reshape;
}
- gfc_free_expr (e);
-
if (order[i] < 1 || order[i] > rank)
{
gfc_error ("ORDER parameter of RESHAPE at %L is out of range",
&e->where);
+ gfc_free_expr (e);
goto bad_reshape;
}
{
gfc_error ("Invalid permutation in ORDER parameter at %L",
&e->where);
+ gfc_free_expr (e);
goto bad_reshape;
}
+ gfc_free_expr (e);
+
x[order[i]] = 1;
}
}
}
if (mpz_cmp_ui (index, INT_MAX) > 0)
- gfc_internal_error ("Reshaped array too large at %L", &e->where);
+ gfc_internal_error ("Reshaped array too large at %C");
j = mpz_get_ui (index);
|| mpz_cmp_si (i->value.integer, -exp_range - 2) < 0)
{
gfc_error ("Result of SCALE overflows its kind at %L", &result->where);
+ gfc_free_expr (result);
return &gfc_bad_expr;
}
{
result = gfc_constant_result (BT_INTEGER, kind, &x->where);
mpz_xor (result->value.integer, x->value.integer, y->value.integer);
+ return range_check (result, "XOR");
}
else /* BT_LOGICAL */
{
result = gfc_constant_result (BT_LOGICAL, kind, &x->where);
result->value.logical = (x->value.logical && !y->value.logical)
|| (!x->value.logical && y->value.logical);
+ return result;
}
- return range_check (result, "XOR");
}