2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* These functions check to see if an argument list is compatible with
24 a particular intrinsic function or subroutine. Presence of
25 required arguments has already been established, the argument list
26 has been sorted into the right order and has NULL arguments in the
27 correct places for missing optional arguments. */
37 #include "intrinsic.h"
40 /* The fundamental complaint function of this source file. This
41 function can be called in all kinds of ways. */
44 must_be (gfc_expr
* e
, int n
, const char *thing
)
47 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
48 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
, &e
->where
,
53 /* Check the type of an expression. */
56 type_check (gfc_expr
* e
, int n
, bt type
)
59 if (e
->ts
.type
== type
)
62 must_be (e
, n
, gfc_basic_typename (type
));
68 /* Check that the expression is a numeric type. */
71 numeric_check (gfc_expr
* e
, int n
)
74 if (gfc_numeric_ts (&e
->ts
))
77 must_be (e
, n
, "a numeric type");
83 /* Check that an expression is integer or real. */
86 int_or_real_check (gfc_expr
* e
, int n
)
89 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
91 must_be (e
, n
, "INTEGER or REAL");
99 /* Check that the expression is an optional constant integer
100 and that it specifies a valid kind for that type. */
103 kind_check (gfc_expr
* k
, int n
, bt type
)
110 if (type_check (k
, n
, BT_INTEGER
) == FAILURE
)
113 if (k
->expr_type
!= EXPR_CONSTANT
)
115 must_be (k
, n
, "a constant");
119 if (gfc_extract_int (k
, &kind
) != NULL
120 || gfc_validate_kind (type
, kind
, true) < 0)
122 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
131 /* Make sure the expression is a double precision real. */
134 double_check (gfc_expr
* d
, int n
)
136 if (type_check (d
, n
, BT_REAL
) == FAILURE
)
139 if (d
->ts
.kind
!= gfc_default_double_kind
)
141 must_be (d
, n
, "double precision");
149 /* Make sure the expression is a logical array. */
152 logical_array_check (gfc_expr
* array
, int n
)
155 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
157 must_be (array
, n
, "a logical array");
165 /* Make sure an expression is an array. */
168 array_check (gfc_expr
* e
, int n
)
174 must_be (e
, n
, "an array");
180 /* Make sure an expression is a scalar. */
183 scalar_check (gfc_expr
* e
, int n
)
189 must_be (e
, n
, "a scalar");
195 /* Make sure two expression have the same type. */
198 same_type_check (gfc_expr
* e
, int n
, gfc_expr
* f
, int m
)
202 if (gfc_compare_types (&e
->ts
, &f
->ts
))
205 sprintf (message
, "the same type and kind as '%s'",
206 gfc_current_intrinsic_arg
[n
]);
208 must_be (f
, m
, message
);
214 /* Make sure that an expression has a certain (nonzero) rank. */
217 rank_check (gfc_expr
* e
, int n
, int rank
)
224 sprintf (message
, "of rank %d", rank
);
226 must_be (e
, n
, message
);
232 /* Make sure a variable expression is not an optional dummy argument. */
235 nonoptional_check (gfc_expr
* e
, int n
)
238 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
240 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
241 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
246 /* TODO: Recursive check on nonoptional variables? */
252 /* Check that an expression has a particular kind. */
255 kind_value_check (gfc_expr
* e
, int n
, int k
)
262 sprintf (message
, "of kind %d", k
);
264 must_be (e
, n
, message
);
269 /* Make sure an expression is a variable. */
272 variable_check (gfc_expr
* e
, int n
)
275 if ((e
->expr_type
== EXPR_VARIABLE
276 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
)
277 || (e
->expr_type
== EXPR_FUNCTION
278 && e
->symtree
->n
.sym
->result
== e
->symtree
->n
.sym
))
281 if (e
->expr_type
== EXPR_VARIABLE
282 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
284 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
285 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
290 must_be (e
, n
, "a variable");
296 /* Check the common DIM parameter for correctness. */
299 dim_check (gfc_expr
* dim
, int n
, int optional
)
307 if (nonoptional_check (dim
, n
) == FAILURE
)
315 gfc_error ("Missing DIM parameter in intrinsic '%s' at %L",
316 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
320 if (type_check (dim
, n
, BT_INTEGER
) == FAILURE
)
323 if (scalar_check (dim
, n
) == FAILURE
)
330 /* If a DIM parameter is a constant, make sure that it is greater than
331 zero and less than or equal to the rank of the given array. If
332 allow_assumed is zero then dim must be less than the rank of the array
333 for assumed size arrays. */
336 dim_rank_check (gfc_expr
* dim
, gfc_expr
* array
, int allow_assumed
)
341 if (dim
->expr_type
!= EXPR_CONSTANT
|| array
->expr_type
!= EXPR_VARIABLE
)
344 ar
= gfc_find_array_ref (array
);
346 if (ar
->as
->type
== AS_ASSUMED_SIZE
&& !allow_assumed
)
349 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
350 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
352 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
353 "dimension index", gfc_current_intrinsic
, &dim
->where
);
362 /***** Check functions *****/
364 /* Check subroutine suitable for intrinsics taking a real argument and
365 a kind argument for the result. */
368 check_a_kind (gfc_expr
* a
, gfc_expr
* kind
, bt type
)
371 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
373 if (kind_check (kind
, 1, type
) == FAILURE
)
379 /* Check subroutine suitable for ceiling, floor and nint. */
382 gfc_check_a_ikind (gfc_expr
* a
, gfc_expr
* kind
)
385 return check_a_kind (a
, kind
, BT_INTEGER
);
388 /* Check subroutine suitable for aint, anint. */
391 gfc_check_a_xkind (gfc_expr
* a
, gfc_expr
* kind
)
394 return check_a_kind (a
, kind
, BT_REAL
);
398 gfc_check_abs (gfc_expr
* a
)
401 if (numeric_check (a
, 0) == FAILURE
)
409 gfc_check_all_any (gfc_expr
* mask
, gfc_expr
* dim
)
412 if (logical_array_check (mask
, 0) == FAILURE
)
415 if (dim_check (dim
, 1, 1) == FAILURE
)
423 gfc_check_allocated (gfc_expr
* array
)
426 if (variable_check (array
, 0) == FAILURE
)
429 if (array_check (array
, 0) == FAILURE
)
432 if (!array
->symtree
->n
.sym
->attr
.allocatable
)
434 must_be (array
, 0, "ALLOCATABLE");
442 /* Common check function where the first argument must be real or
443 integer and the second argument must be the same as the first. */
446 gfc_check_a_p (gfc_expr
* a
, gfc_expr
* p
)
449 if (int_or_real_check (a
, 0) == FAILURE
)
452 if (same_type_check (a
, 0, p
, 1) == FAILURE
)
460 gfc_check_associated (gfc_expr
* pointer
, gfc_expr
* target
)
462 symbol_attribute attr
;
466 if (variable_check (pointer
, 0) == FAILURE
)
469 attr
= gfc_variable_attr (pointer
, NULL
);
472 must_be (pointer
, 0, "a POINTER");
479 /* Target argument is optional. */
480 if (target
->expr_type
== EXPR_NULL
)
482 gfc_error ("NULL pointer at %L is not permitted as actual argument "
483 "of '%s' intrinsic function",
484 &target
->where
, gfc_current_intrinsic
);
488 attr
= gfc_variable_attr (target
, NULL
);
489 if (!attr
.pointer
&& !attr
.target
)
491 must_be (target
, 1, "a POINTER or a TARGET");
496 if (same_type_check (pointer
, 0, target
, 1) == FAILURE
)
498 if (rank_check (target
, 0, pointer
->rank
) == FAILURE
)
500 if (target
->rank
> 0)
502 for (i
= 0; i
< target
->rank
; i
++)
503 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
505 gfc_error ("Array section with a vector subscript at %L shall not "
506 "be the target of an pointer",
517 gfc_check_atan2 (gfc_expr
* y
, gfc_expr
* x
)
519 if (type_check (y
, 0, BT_REAL
) == FAILURE
)
521 if (same_type_check (y
, 0, x
, 1) == FAILURE
)
528 /* BESJN and BESYN functions. */
531 gfc_check_besn (gfc_expr
* n
, gfc_expr
* x
)
534 if (scalar_check (n
, 0) == FAILURE
)
537 if (type_check (n
, 0, BT_INTEGER
) == FAILURE
)
540 if (scalar_check (x
, 1) == FAILURE
)
543 if (type_check (x
, 1, BT_REAL
) == FAILURE
)
551 gfc_check_btest (gfc_expr
* i
, gfc_expr
* pos
)
554 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
556 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
564 gfc_check_char (gfc_expr
* i
, gfc_expr
* kind
)
567 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
569 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
577 gfc_check_cmplx (gfc_expr
* x
, gfc_expr
* y
, gfc_expr
* kind
)
580 if (numeric_check (x
, 0) == FAILURE
)
585 if (numeric_check (y
, 1) == FAILURE
)
588 if (x
->ts
.type
== BT_COMPLEX
)
590 must_be (y
, 1, "not be present if 'x' is COMPLEX");
595 if (kind_check (kind
, 2, BT_COMPLEX
) == FAILURE
)
603 gfc_check_count (gfc_expr
* mask
, gfc_expr
* dim
)
606 if (logical_array_check (mask
, 0) == FAILURE
)
608 if (dim_check (dim
, 1, 1) == FAILURE
)
616 gfc_check_cshift (gfc_expr
* array
, gfc_expr
* shift
, gfc_expr
* dim
)
619 if (array_check (array
, 0) == FAILURE
)
622 if (array
->rank
== 1)
624 if (scalar_check (shift
, 1) == FAILURE
)
629 /* TODO: more requirements on shift parameter. */
632 if (dim_check (dim
, 2, 1) == FAILURE
)
640 gfc_check_dcmplx (gfc_expr
* x
, gfc_expr
* y
)
643 if (numeric_check (x
, 0) == FAILURE
)
648 if (numeric_check (y
, 1) == FAILURE
)
651 if (x
->ts
.type
== BT_COMPLEX
)
653 must_be (y
, 1, "not be present if 'x' is COMPLEX");
663 gfc_check_dble (gfc_expr
* x
)
666 if (numeric_check (x
, 0) == FAILURE
)
674 gfc_check_digits (gfc_expr
* x
)
677 if (int_or_real_check (x
, 0) == FAILURE
)
685 gfc_check_dot_product (gfc_expr
* vector_a
, gfc_expr
* vector_b
)
688 switch (vector_a
->ts
.type
)
691 if (type_check (vector_b
, 1, BT_LOGICAL
) == FAILURE
)
698 if (numeric_check (vector_b
, 1) == FAILURE
)
703 must_be (vector_a
, 0, "numeric or LOGICAL");
707 if (rank_check (vector_a
, 0, 1) == FAILURE
)
710 if (rank_check (vector_b
, 1, 1) == FAILURE
)
718 gfc_check_eoshift (gfc_expr
* array
, gfc_expr
* shift
, gfc_expr
* boundary
,
722 if (array_check (array
, 0) == FAILURE
)
725 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
728 if (array
->rank
== 1)
730 if (scalar_check (shift
, 2) == FAILURE
)
735 /* TODO: more weird restrictions on shift. */
738 if (boundary
!= NULL
)
740 if (same_type_check (array
, 0, boundary
, 2) == FAILURE
)
743 /* TODO: more restrictions on boundary. */
746 if (dim_check (dim
, 1, 1) == FAILURE
)
754 gfc_check_fnum (gfc_expr
* unit
)
757 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
760 if (scalar_check (unit
, 0) == FAILURE
)
767 /* This is used for the g77 one-argument Bessel functions, and the
771 gfc_check_g77_math1 (gfc_expr
* x
)
774 if (scalar_check (x
, 0) == FAILURE
)
777 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
785 gfc_check_huge (gfc_expr
* x
)
788 if (int_or_real_check (x
, 0) == FAILURE
)
795 /* Check that the single argument is an integer. */
798 gfc_check_i (gfc_expr
* i
)
801 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
809 gfc_check_iand (gfc_expr
* i
, gfc_expr
* j
)
812 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
813 || type_check (j
, 1, BT_INTEGER
) == FAILURE
)
816 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
824 gfc_check_ibclr (gfc_expr
* i
, gfc_expr
* pos
)
827 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
828 || type_check (pos
, 1, BT_INTEGER
) == FAILURE
829 || kind_value_check (pos
, 1, gfc_default_integer_kind
) == FAILURE
)
837 gfc_check_ibits (gfc_expr
* i
, gfc_expr
* pos
, gfc_expr
* len
)
840 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
841 || type_check (pos
, 1, BT_INTEGER
) == FAILURE
842 || kind_value_check (pos
, 1, gfc_default_integer_kind
) == FAILURE
843 || type_check (len
, 2, BT_INTEGER
) == FAILURE
)
851 gfc_check_ibset (gfc_expr
* i
, gfc_expr
* pos
)
854 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
855 || type_check (pos
, 1, BT_INTEGER
) == FAILURE
856 || kind_value_check (pos
, 1, gfc_default_integer_kind
) == FAILURE
)
864 gfc_check_idnint (gfc_expr
* a
)
867 if (double_check (a
, 0) == FAILURE
)
875 gfc_check_ieor (gfc_expr
* i
, gfc_expr
* j
)
878 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
879 || type_check (j
, 1, BT_INTEGER
) == FAILURE
)
882 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
890 gfc_check_index (gfc_expr
* string
, gfc_expr
* substring
, gfc_expr
* back
)
893 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
894 || type_check (substring
, 1, BT_CHARACTER
) == FAILURE
)
898 if (back
!= NULL
&& type_check (back
, 2, BT_LOGICAL
) == FAILURE
)
901 if (string
->ts
.kind
!= substring
->ts
.kind
)
903 must_be (substring
, 1, "the same kind as 'string'");
912 gfc_check_int (gfc_expr
* x
, gfc_expr
* kind
)
915 if (numeric_check (x
, 0) == FAILURE
916 || kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
924 gfc_check_ior (gfc_expr
* i
, gfc_expr
* j
)
927 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
928 || type_check (j
, 1, BT_INTEGER
) == FAILURE
)
931 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
939 gfc_check_ishft (gfc_expr
* i
, gfc_expr
* shift
)
942 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
943 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
951 gfc_check_ishftc (gfc_expr
* i
, gfc_expr
* shift
, gfc_expr
* size
)
954 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
955 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
958 if (size
!= NULL
&& type_check (size
, 2, BT_INTEGER
) == FAILURE
)
966 gfc_check_kind (gfc_expr
* x
)
969 if (x
->ts
.type
== BT_DERIVED
)
971 must_be (x
, 0, "a non-derived type");
980 gfc_check_lbound (gfc_expr
* array
, gfc_expr
* dim
)
983 if (array_check (array
, 0) == FAILURE
)
988 if (dim_check (dim
, 1, 1) == FAILURE
)
991 if (dim_rank_check (dim
, array
, 1) == FAILURE
)
999 gfc_check_logical (gfc_expr
* a
, gfc_expr
* kind
)
1002 if (type_check (a
, 0, BT_LOGICAL
) == FAILURE
)
1004 if (kind_check (kind
, 1, BT_LOGICAL
) == FAILURE
)
1011 /* Min/max family. */
1014 min_max_args (gfc_actual_arglist
* arg
)
1017 if (arg
== NULL
|| arg
->next
== NULL
)
1019 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1020 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
1029 check_rest (bt type
, int kind
, gfc_actual_arglist
* arg
)
1034 if (min_max_args (arg
) == FAILURE
)
1039 for (; arg
; arg
= arg
->next
, n
++)
1042 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
1044 if (x
->ts
.type
== type
)
1046 if (gfc_notify_std (GFC_STD_GNU
,
1047 "Extension: Different type kinds at %L", &x
->where
)
1053 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be %s(%d)",
1054 n
, gfc_current_intrinsic
, &x
->where
,
1055 gfc_basic_typename (type
), kind
);
1066 gfc_check_min_max (gfc_actual_arglist
* arg
)
1070 if (min_max_args (arg
) == FAILURE
)
1075 if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
1078 ("'a1' argument of '%s' intrinsic at %L must be INTEGER or REAL",
1079 gfc_current_intrinsic
, &x
->where
);
1083 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
1088 gfc_check_min_max_integer (gfc_actual_arglist
* arg
)
1091 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
1096 gfc_check_min_max_real (gfc_actual_arglist
* arg
)
1099 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
1104 gfc_check_min_max_double (gfc_actual_arglist
* arg
)
1107 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
1110 /* End of min/max family. */
1114 gfc_check_matmul (gfc_expr
* matrix_a
, gfc_expr
* matrix_b
)
1117 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
1119 must_be (matrix_a
, 0, "numeric or LOGICAL");
1123 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
1125 must_be (matrix_b
, 0, "numeric or LOGICAL");
1129 switch (matrix_a
->rank
)
1132 if (rank_check (matrix_b
, 1, 2) == FAILURE
)
1137 if (matrix_b
->rank
== 2)
1139 if (rank_check (matrix_b
, 1, 1) == FAILURE
)
1144 must_be (matrix_a
, 0, "of rank 1 or 2");
1152 /* Whoever came up with this interface was probably on something.
1153 The possibilities for the occupation of the second and third
1160 NULL MASK minloc(array, mask=m)
1163 I.e. in the case of minloc(array,mask), mask will be in the second
1164 position of the argument list and we'll have to fix that up. */
1167 gfc_check_minloc_maxloc (gfc_actual_arglist
* ap
)
1169 gfc_expr
*a
, *m
, *d
;
1172 if (int_or_real_check (a
, 0) == FAILURE
1173 || array_check (a
, 0) == FAILURE
)
1177 m
= ap
->next
->next
->expr
;
1179 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
1180 && ap
->next
->name
[0] == '\0')
1185 ap
->next
->expr
= NULL
;
1186 ap
->next
->next
->expr
= m
;
1190 && (scalar_check (d
, 1) == FAILURE
1191 || type_check (d
, 1, BT_INTEGER
) == FAILURE
))
1194 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
1201 /* Similar to minloc/maxloc, the argument list might need to be
1202 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1203 difference is that MINLOC/MAXLOC take an additional KIND argument.
1204 The possibilities are:
1210 NULL MASK minval(array, mask=m)
1213 I.e. in the case of minval(array,mask), mask will be in the second
1214 position of the argument list and we'll have to fix that up. */
1217 check_reduction (gfc_actual_arglist
* ap
)
1222 m
= ap
->next
->next
->expr
;
1224 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
1225 && ap
->next
->name
[0] == '\0')
1230 ap
->next
->expr
= NULL
;
1231 ap
->next
->next
->expr
= m
;
1235 && (scalar_check (d
, 1) == FAILURE
1236 || type_check (d
, 1, BT_INTEGER
) == FAILURE
))
1239 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
1247 gfc_check_minval_maxval (gfc_actual_arglist
* ap
)
1250 if (int_or_real_check (ap
->expr
, 0) == FAILURE
1251 || array_check (ap
->expr
, 0) == FAILURE
)
1254 return check_reduction (ap
);
1259 gfc_check_product_sum (gfc_actual_arglist
* ap
)
1262 if (numeric_check (ap
->expr
, 0) == FAILURE
1263 || array_check (ap
->expr
, 0) == FAILURE
)
1266 return check_reduction (ap
);
1271 gfc_check_merge (gfc_expr
* tsource
, gfc_expr
* fsource
, gfc_expr
* mask
)
1274 if (same_type_check (tsource
, 0, fsource
, 1) == FAILURE
)
1277 if (type_check (mask
, 2, BT_LOGICAL
) == FAILURE
)
1285 gfc_check_nearest (gfc_expr
* x
, gfc_expr
* s
)
1288 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1291 if (type_check (s
, 1, BT_REAL
) == FAILURE
)
1299 gfc_check_null (gfc_expr
* mold
)
1301 symbol_attribute attr
;
1306 if (variable_check (mold
, 0) == FAILURE
)
1309 attr
= gfc_variable_attr (mold
, NULL
);
1313 must_be (mold
, 0, "a POINTER");
1322 gfc_check_pack (gfc_expr
* array
, gfc_expr
* mask
, gfc_expr
* vector
)
1325 if (array_check (array
, 0) == FAILURE
)
1328 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
1331 if (mask
->rank
!= 0 && mask
->rank
!= array
->rank
)
1333 must_be (array
, 0, "conformable with 'mask' argument");
1339 if (same_type_check (array
, 0, vector
, 2) == FAILURE
)
1342 if (rank_check (vector
, 2, 1) == FAILURE
)
1345 /* TODO: More constraints here. */
1353 gfc_check_precision (gfc_expr
* x
)
1356 if (x
->ts
.type
!= BT_REAL
&& x
->ts
.type
!= BT_COMPLEX
)
1358 must_be (x
, 0, "of type REAL or COMPLEX");
1367 gfc_check_present (gfc_expr
* a
)
1371 if (variable_check (a
, 0) == FAILURE
)
1374 sym
= a
->symtree
->n
.sym
;
1375 if (!sym
->attr
.dummy
)
1377 must_be (a
, 0, "a dummy variable");
1381 if (!sym
->attr
.optional
)
1383 must_be (a
, 0, "an OPTIONAL dummy variable");
1392 gfc_check_radix (gfc_expr
* x
)
1395 if (int_or_real_check (x
, 0) == FAILURE
)
1403 gfc_check_range (gfc_expr
* x
)
1406 if (numeric_check (x
, 0) == FAILURE
)
1413 /* real, float, sngl. */
1415 gfc_check_real (gfc_expr
* a
, gfc_expr
* kind
)
1418 if (numeric_check (a
, 0) == FAILURE
)
1421 if (kind_check (kind
, 1, BT_REAL
) == FAILURE
)
1429 gfc_check_repeat (gfc_expr
* x
, gfc_expr
* y
)
1432 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
1435 if (scalar_check (x
, 0) == FAILURE
)
1438 if (type_check (y
, 0, BT_INTEGER
) == FAILURE
)
1441 if (scalar_check (y
, 1) == FAILURE
)
1449 gfc_check_reshape (gfc_expr
* source
, gfc_expr
* shape
,
1450 gfc_expr
* pad
, gfc_expr
* order
)
1455 if (array_check (source
, 0) == FAILURE
)
1458 if (rank_check (shape
, 1, 1) == FAILURE
)
1461 if (type_check (shape
, 1, BT_INTEGER
) == FAILURE
)
1464 if (gfc_array_size (shape
, &size
) != SUCCESS
)
1466 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
1467 "array of constant size", &shape
->where
);
1471 m
= mpz_cmp_ui (size
, GFC_MAX_DIMENSIONS
);
1477 ("'shape' argument of 'reshape' intrinsic at %L has more than "
1478 stringize (GFC_MAX_DIMENSIONS
) " elements", &shape
->where
);
1484 if (same_type_check (source
, 0, pad
, 2) == FAILURE
)
1486 if (array_check (pad
, 2) == FAILURE
)
1490 if (order
!= NULL
&& array_check (order
, 3) == FAILURE
)
1498 gfc_check_scale (gfc_expr
* x
, gfc_expr
* i
)
1501 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1504 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
1512 gfc_check_scan (gfc_expr
* x
, gfc_expr
* y
, gfc_expr
* z
)
1515 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
1518 if (type_check (y
, 1, BT_CHARACTER
) == FAILURE
)
1521 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
1524 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1532 gfc_check_selected_real_kind (gfc_expr
* p
, gfc_expr
* r
)
1535 if (p
== NULL
&& r
== NULL
)
1537 gfc_error ("Missing arguments to %s intrinsic at %L",
1538 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
1543 if (p
!= NULL
&& type_check (p
, 0, BT_INTEGER
) == FAILURE
)
1546 if (r
!= NULL
&& type_check (r
, 1, BT_INTEGER
) == FAILURE
)
1554 gfc_check_set_exponent (gfc_expr
* x
, gfc_expr
* i
)
1557 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1560 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
1568 gfc_check_shape (gfc_expr
* source
)
1572 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
1575 ar
= gfc_find_array_ref (source
);
1577 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
)
1579 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
1580 "an assumed size array", &source
->where
);
1589 gfc_check_size (gfc_expr
* array
, gfc_expr
* dim
)
1592 if (array_check (array
, 0) == FAILURE
)
1597 if (type_check (dim
, 1, BT_INTEGER
) == FAILURE
)
1600 if (kind_value_check (dim
, 1, gfc_default_integer_kind
) == FAILURE
)
1603 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
1612 gfc_check_sign (gfc_expr
* a
, gfc_expr
* b
)
1615 if (int_or_real_check (a
, 0) == FAILURE
)
1618 if (same_type_check (a
, 0, b
, 1) == FAILURE
)
1626 gfc_check_spread (gfc_expr
* source
, gfc_expr
* dim
, gfc_expr
* ncopies
)
1629 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
1631 must_be (source
, 0, "less than rank " stringize (GFC_MAX_DIMENSIONS
));
1635 if (dim_check (dim
, 1, 0) == FAILURE
)
1638 if (type_check (ncopies
, 2, BT_INTEGER
) == FAILURE
)
1641 if (scalar_check (ncopies
, 2) == FAILURE
)
1649 gfc_check_fstat (gfc_expr
* unit
, gfc_expr
* array
)
1652 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1655 if (scalar_check (unit
, 0) == FAILURE
)
1658 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
1659 || kind_value_check (unit
, 0, gfc_default_integer_kind
) == FAILURE
)
1662 if (array_check (array
, 1) == FAILURE
)
1670 gfc_check_fstat_sub (gfc_expr
* unit
, gfc_expr
* array
, gfc_expr
* status
)
1673 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1676 if (scalar_check (unit
, 0) == FAILURE
)
1679 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
1680 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
1683 if (array_check (array
, 1) == FAILURE
)
1689 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
1690 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
1693 if (scalar_check (status
, 2) == FAILURE
)
1701 gfc_check_stat (gfc_expr
* name
, gfc_expr
* array
)
1704 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1707 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
1708 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
1711 if (array_check (array
, 1) == FAILURE
)
1719 gfc_check_stat_sub (gfc_expr
* name
, gfc_expr
* array
, gfc_expr
* status
)
1722 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1725 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
1726 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
1729 if (array_check (array
, 1) == FAILURE
)
1735 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
1736 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
1739 if (scalar_check (status
, 2) == FAILURE
)
1747 gfc_check_transfer (gfc_expr
* source ATTRIBUTE_UNUSED
,
1748 gfc_expr
* mold ATTRIBUTE_UNUSED
,
1754 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
1757 if (scalar_check (size
, 2) == FAILURE
)
1760 if (nonoptional_check (size
, 2) == FAILURE
)
1769 gfc_check_transpose (gfc_expr
* matrix
)
1772 if (rank_check (matrix
, 0, 2) == FAILURE
)
1780 gfc_check_ubound (gfc_expr
* array
, gfc_expr
* dim
)
1783 if (array_check (array
, 0) == FAILURE
)
1788 if (dim_check (dim
, 1, 1) == FAILURE
)
1791 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
1799 gfc_check_unpack (gfc_expr
* vector
, gfc_expr
* mask
, gfc_expr
* field
)
1802 if (rank_check (vector
, 0, 1) == FAILURE
)
1805 if (array_check (mask
, 1) == FAILURE
)
1808 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
1811 if (same_type_check (vector
, 0, field
, 2) == FAILURE
)
1819 gfc_check_verify (gfc_expr
* x
, gfc_expr
* y
, gfc_expr
* z
)
1822 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
1825 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1828 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
1836 gfc_check_trim (gfc_expr
* x
)
1838 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
1841 if (scalar_check (x
, 0) == FAILURE
)
1848 /* Common check function for the half a dozen intrinsics that have a
1849 single real argument. */
1852 gfc_check_x (gfc_expr
* x
)
1855 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1862 /************* Check functions for intrinsic subroutines *************/
1865 gfc_check_cpu_time (gfc_expr
* time
)
1868 if (scalar_check (time
, 0) == FAILURE
)
1871 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
1874 if (variable_check (time
, 0) == FAILURE
)
1882 gfc_check_date_and_time (gfc_expr
* date
, gfc_expr
* time
,
1883 gfc_expr
* zone
, gfc_expr
* values
)
1888 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
1890 if (scalar_check (date
, 0) == FAILURE
)
1892 if (variable_check (date
, 0) == FAILURE
)
1898 if (type_check (time
, 1, BT_CHARACTER
) == FAILURE
)
1900 if (scalar_check (time
, 1) == FAILURE
)
1902 if (variable_check (time
, 1) == FAILURE
)
1908 if (type_check (zone
, 2, BT_CHARACTER
) == FAILURE
)
1910 if (scalar_check (zone
, 2) == FAILURE
)
1912 if (variable_check (zone
, 2) == FAILURE
)
1918 if (type_check (values
, 3, BT_INTEGER
) == FAILURE
)
1920 if (array_check (values
, 3) == FAILURE
)
1922 if (rank_check (values
, 3, 1) == FAILURE
)
1924 if (variable_check (values
, 3) == FAILURE
)
1933 gfc_check_mvbits (gfc_expr
* from
, gfc_expr
* frompos
, gfc_expr
* len
,
1934 gfc_expr
* to
, gfc_expr
* topos
)
1937 if (type_check (from
, 0, BT_INTEGER
) == FAILURE
)
1940 if (type_check (frompos
, 1, BT_INTEGER
) == FAILURE
)
1943 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
1946 if (same_type_check (from
, 0, to
, 3) == FAILURE
)
1949 if (variable_check (to
, 3) == FAILURE
)
1952 if (type_check (topos
, 4, BT_INTEGER
) == FAILURE
)
1960 gfc_check_random_number (gfc_expr
* harvest
)
1963 if (type_check (harvest
, 0, BT_REAL
) == FAILURE
)
1966 if (variable_check (harvest
, 0) == FAILURE
)
1974 gfc_check_random_seed (gfc_expr
* size
, gfc_expr
* put
, gfc_expr
* get
)
1979 if (scalar_check (size
, 0) == FAILURE
)
1982 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
1985 if (variable_check (size
, 0) == FAILURE
)
1988 if (kind_value_check (size
, 0, gfc_default_integer_kind
) == FAILURE
)
1996 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
,
1999 if (array_check (put
, 1) == FAILURE
)
2002 if (rank_check (put
, 1, 1) == FAILURE
)
2005 if (type_check (put
, 1, BT_INTEGER
) == FAILURE
)
2008 if (kind_value_check (put
, 1, gfc_default_integer_kind
) == FAILURE
)
2015 if (size
!= NULL
|| put
!= NULL
)
2016 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
,
2019 if (array_check (get
, 2) == FAILURE
)
2022 if (rank_check (get
, 2, 1) == FAILURE
)
2025 if (type_check (get
, 2, BT_INTEGER
) == FAILURE
)
2028 if (variable_check (get
, 2) == FAILURE
)
2031 if (kind_value_check (get
, 2, gfc_default_integer_kind
) == FAILURE
)
2039 gfc_check_second_sub (gfc_expr
* time
)
2042 if (scalar_check (time
, 0) == FAILURE
)
2045 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
2048 if (kind_value_check(time
, 0, 4) == FAILURE
)
2055 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2056 count, count_rate, and count_max are all optional arguments */
2059 gfc_check_system_clock (gfc_expr
* count
, gfc_expr
* count_rate
,
2060 gfc_expr
* count_max
)
2065 if (scalar_check (count
, 0) == FAILURE
)
2068 if (type_check (count
, 0, BT_INTEGER
) == FAILURE
)
2071 if (variable_check (count
, 0) == FAILURE
)
2075 if (count_rate
!= NULL
)
2077 if (scalar_check (count_rate
, 1) == FAILURE
)
2080 if (type_check (count_rate
, 1, BT_INTEGER
) == FAILURE
)
2083 if (variable_check (count_rate
, 1) == FAILURE
)
2086 if (count
!= NULL
&& same_type_check(count
, 0, count_rate
, 1) == FAILURE
)
2091 if (count_max
!= NULL
)
2093 if (scalar_check (count_max
, 2) == FAILURE
)
2096 if (type_check (count_max
, 2, BT_INTEGER
) == FAILURE
)
2099 if (variable_check (count_max
, 2) == FAILURE
)
2102 if (count
!= NULL
&& same_type_check(count
, 0, count_max
, 2) == FAILURE
)
2105 if (count_rate
!= NULL
2106 && same_type_check(count_rate
, 1, count_max
, 2) == FAILURE
)
2115 gfc_check_irand (gfc_expr
* x
)
2120 if (scalar_check (x
, 0) == FAILURE
)
2123 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
2126 if (kind_value_check(x
, 0, 4) == FAILURE
)
2133 gfc_check_rand (gfc_expr
* x
)
2138 if (scalar_check (x
, 0) == FAILURE
)
2141 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
2144 if (kind_value_check(x
, 0, 4) == FAILURE
)
2151 gfc_check_srand (gfc_expr
* x
)
2153 if (scalar_check (x
, 0) == FAILURE
)
2156 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
2159 if (kind_value_check(x
, 0, 4) == FAILURE
)
2166 gfc_check_etime (gfc_expr
* x
)
2168 if (array_check (x
, 0) == FAILURE
)
2171 if (rank_check (x
, 0, 1) == FAILURE
)
2174 if (variable_check (x
, 0) == FAILURE
)
2177 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2180 if (kind_value_check(x
, 0, 4) == FAILURE
)
2187 gfc_check_etime_sub (gfc_expr
* values
, gfc_expr
* time
)
2189 if (array_check (values
, 0) == FAILURE
)
2192 if (rank_check (values
, 0, 1) == FAILURE
)
2195 if (variable_check (values
, 0) == FAILURE
)
2198 if (type_check (values
, 0, BT_REAL
) == FAILURE
)
2201 if (kind_value_check(values
, 0, 4) == FAILURE
)
2204 if (scalar_check (time
, 1) == FAILURE
)
2207 if (type_check (time
, 1, BT_REAL
) == FAILURE
)
2210 if (kind_value_check(time
, 1, 4) == FAILURE
)
2218 gfc_check_getcwd_sub (gfc_expr
* cwd
, gfc_expr
* status
)
2221 if (type_check (cwd
, 0, BT_CHARACTER
) == FAILURE
)
2227 if (scalar_check (status
, 1) == FAILURE
)
2230 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
2238 gfc_check_exit (gfc_expr
* status
)
2244 if (type_check (status
, 0, BT_INTEGER
) == FAILURE
)
2247 if (scalar_check (status
, 0) == FAILURE
)
2255 gfc_check_flush (gfc_expr
* unit
)
2261 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
2264 if (scalar_check (unit
, 0) == FAILURE
)
2272 gfc_check_umask (gfc_expr
* mask
)
2275 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
2278 if (scalar_check (mask
, 0) == FAILURE
)
2286 gfc_check_umask_sub (gfc_expr
* mask
, gfc_expr
* old
)
2289 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
2292 if (scalar_check (mask
, 0) == FAILURE
)
2298 if (scalar_check (old
, 1) == FAILURE
)
2301 if (type_check (old
, 1, BT_INTEGER
) == FAILURE
)
2309 gfc_check_unlink (gfc_expr
* name
)
2312 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
2320 gfc_check_unlink_sub (gfc_expr
* name
, gfc_expr
* status
)
2323 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
2329 if (scalar_check (status
, 1) == FAILURE
)
2332 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
2340 gfc_check_system_sub (gfc_expr
* cmd
, gfc_expr
* status
)
2342 if (type_check (cmd
, 0, BT_CHARACTER
) == FAILURE
)
2345 if (scalar_check (status
, 1) == FAILURE
)
2348 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
2351 if (kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
)