2 Copyright (C) 2002, 2003, 2004, 2005 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. */
33 #include "intrinsic.h"
36 /* The fundamental complaint function of this source file. This
37 function can be called in all kinds of ways. */
40 must_be (gfc_expr * e, int n, const char *thing)
42 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
43 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where,
48 /* Check the type of an expression. */
51 type_check (gfc_expr * e, int n, bt type)
53 if (e->ts.type == type)
56 must_be (e, n, gfc_basic_typename (type));
62 /* Check that the expression is a numeric type. */
65 numeric_check (gfc_expr * e, int n)
67 if (gfc_numeric_ts (&e->ts))
70 must_be (e, n, "a numeric type");
76 /* Check that an expression is integer or real. */
79 int_or_real_check (gfc_expr * e, int n)
81 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
83 must_be (e, n, "INTEGER or REAL");
91 /* Check that an expression is real or complex. */
94 real_or_complex_check (gfc_expr * e, int n)
96 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
98 must_be (e, n, "REAL or COMPLEX");
106 /* Check that the expression is an optional constant integer
107 and that it specifies a valid kind for that type. */
110 kind_check (gfc_expr * k, int n, bt type)
117 if (type_check (k, n, BT_INTEGER) == FAILURE)
120 if (k->expr_type != EXPR_CONSTANT)
122 must_be (k, n, "a constant");
126 if (gfc_extract_int (k, &kind) != NULL
127 || gfc_validate_kind (type, kind, true) < 0)
129 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
138 /* Make sure the expression is a double precision real. */
141 double_check (gfc_expr * d, int n)
143 if (type_check (d, n, BT_REAL) == FAILURE)
146 if (d->ts.kind != gfc_default_double_kind)
148 must_be (d, n, "double precision");
156 /* Make sure the expression is a logical array. */
159 logical_array_check (gfc_expr * array, int n)
161 if (array->ts.type != BT_LOGICAL || array->rank == 0)
163 must_be (array, n, "a logical array");
171 /* Make sure an expression is an array. */
174 array_check (gfc_expr * e, int n)
179 must_be (e, n, "an array");
185 /* Make sure an expression is a scalar. */
188 scalar_check (gfc_expr * e, int n)
193 must_be (e, n, "a scalar");
199 /* Make sure two expression have the same type. */
202 same_type_check (gfc_expr * e, int n, gfc_expr * f, int m)
206 if (gfc_compare_types (&e->ts, &f->ts))
209 sprintf (message, "the same type and kind as '%s'",
210 gfc_current_intrinsic_arg[n]);
212 must_be (f, m, message);
218 /* Make sure that an expression has a certain (nonzero) rank. */
221 rank_check (gfc_expr * e, int n, int rank)
228 sprintf (message, "of rank %d", rank);
230 must_be (e, n, message);
236 /* Make sure a variable expression is not an optional dummy argument. */
239 nonoptional_check (gfc_expr * e, int n)
241 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
243 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
244 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
249 /* TODO: Recursive check on nonoptional variables? */
255 /* Check that an expression has a particular kind. */
258 kind_value_check (gfc_expr * e, int n, int k)
265 sprintf (message, "of kind %d", k);
267 must_be (e, n, message);
272 /* Make sure an expression is a variable. */
275 variable_check (gfc_expr * e, int n)
277 if ((e->expr_type == EXPR_VARIABLE
278 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
279 || (e->expr_type == EXPR_FUNCTION
280 && e->symtree->n.sym->result == e->symtree->n.sym))
283 if (e->expr_type == EXPR_VARIABLE
284 && e->symtree->n.sym->attr.intent == INTENT_IN)
286 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
287 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
292 must_be (e, n, "a variable");
298 /* Check the common DIM parameter for correctness. */
301 dim_check (gfc_expr * dim, int n, int optional)
308 if (nonoptional_check (dim, n) == FAILURE)
316 gfc_error ("Missing DIM parameter in intrinsic '%s' at %L",
317 gfc_current_intrinsic, gfc_current_intrinsic_where);
321 if (type_check (dim, n, BT_INTEGER) == FAILURE)
324 if (scalar_check (dim, n) == FAILURE)
331 /* If a DIM parameter is a constant, make sure that it is greater than
332 zero and less than or equal to the rank of the given array. If
333 allow_assumed is zero then dim must be less than the rank of the array
334 for assumed size arrays. */
337 dim_rank_check (gfc_expr * dim, gfc_expr * array, int allow_assumed)
342 if (dim->expr_type != EXPR_CONSTANT || array->expr_type != EXPR_VARIABLE)
345 ar = gfc_find_array_ref (array);
347 if (ar->as->type == AS_ASSUMED_SIZE && !allow_assumed)
350 if (mpz_cmp_ui (dim->value.integer, 1) < 0
351 || mpz_cmp_ui (dim->value.integer, rank) > 0)
353 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
354 "dimension index", gfc_current_intrinsic, &dim->where);
363 /***** Check functions *****/
365 /* Check subroutine suitable for intrinsics taking a real argument and
366 a kind argument for the result. */
369 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)
384 return check_a_kind (a, kind, BT_INTEGER);
387 /* Check subroutine suitable for aint, anint. */
390 gfc_check_a_xkind (gfc_expr * a, gfc_expr * kind)
392 return check_a_kind (a, kind, BT_REAL);
396 gfc_check_abs (gfc_expr * a)
398 if (numeric_check (a, 0) == FAILURE)
406 gfc_check_all_any (gfc_expr * mask, gfc_expr * dim)
408 if (logical_array_check (mask, 0) == FAILURE)
411 if (dim_check (dim, 1, 1) == FAILURE)
419 gfc_check_allocated (gfc_expr * array)
421 if (variable_check (array, 0) == FAILURE)
424 if (array_check (array, 0) == FAILURE)
427 if (!array->symtree->n.sym->attr.allocatable)
429 must_be (array, 0, "ALLOCATABLE");
437 /* Common check function where the first argument must be real or
438 integer and the second argument must be the same as the first. */
441 gfc_check_a_p (gfc_expr * a, gfc_expr * p)
443 if (int_or_real_check (a, 0) == FAILURE)
446 if (same_type_check (a, 0, p, 1) == FAILURE)
454 gfc_check_associated (gfc_expr * pointer, gfc_expr * target)
456 symbol_attribute attr;
460 if (variable_check (pointer, 0) == FAILURE)
463 attr = gfc_variable_attr (pointer, NULL);
466 must_be (pointer, 0, "a POINTER");
473 /* Target argument is optional. */
474 if (target->expr_type == EXPR_NULL)
476 gfc_error ("NULL pointer at %L is not permitted as actual argument "
477 "of '%s' intrinsic function",
478 &target->where, gfc_current_intrinsic);
482 attr = gfc_variable_attr (target, NULL);
483 if (!attr.pointer && !attr.target)
485 must_be (target, 1, "a POINTER or a TARGET");
490 if (same_type_check (pointer, 0, target, 1) == FAILURE)
492 if (rank_check (target, 0, pointer->rank) == FAILURE)
494 if (target->rank > 0)
496 for (i = 0; i < target->rank; i++)
497 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
499 gfc_error ("Array section with a vector subscript at %L shall not "
500 "be the target of an pointer",
511 gfc_check_atan2 (gfc_expr * y, gfc_expr * x)
513 if (type_check (y, 0, BT_REAL) == FAILURE)
515 if (same_type_check (y, 0, x, 1) == FAILURE)
522 /* BESJN and BESYN functions. */
525 gfc_check_besn (gfc_expr * n, gfc_expr * x)
527 if (scalar_check (n, 0) == FAILURE)
530 if (type_check (n, 0, BT_INTEGER) == FAILURE)
533 if (scalar_check (x, 1) == FAILURE)
536 if (type_check (x, 1, BT_REAL) == FAILURE)
544 gfc_check_btest (gfc_expr * i, gfc_expr * pos)
546 if (type_check (i, 0, BT_INTEGER) == FAILURE)
548 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
556 gfc_check_char (gfc_expr * i, gfc_expr * kind)
558 if (type_check (i, 0, BT_INTEGER) == FAILURE)
560 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
568 gfc_check_cmplx (gfc_expr * x, gfc_expr * y, gfc_expr * kind)
570 if (numeric_check (x, 0) == FAILURE)
575 if (numeric_check (y, 1) == FAILURE)
578 if (x->ts.type == BT_COMPLEX)
580 must_be (y, 1, "not be present if 'x' is COMPLEX");
585 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
593 gfc_check_count (gfc_expr * mask, gfc_expr * dim)
595 if (logical_array_check (mask, 0) == FAILURE)
597 if (dim_check (dim, 1, 1) == FAILURE)
605 gfc_check_cshift (gfc_expr * array, gfc_expr * shift, gfc_expr * dim)
607 if (array_check (array, 0) == FAILURE)
610 if (array->rank == 1)
612 if (scalar_check (shift, 1) == FAILURE)
617 /* TODO: more requirements on shift parameter. */
620 if (dim_check (dim, 2, 1) == FAILURE)
628 gfc_check_dcmplx (gfc_expr * x, gfc_expr * y)
630 if (numeric_check (x, 0) == FAILURE)
635 if (numeric_check (y, 1) == FAILURE)
638 if (x->ts.type == BT_COMPLEX)
640 must_be (y, 1, "not be present if 'x' is COMPLEX");
650 gfc_check_dble (gfc_expr * x)
652 if (numeric_check (x, 0) == FAILURE)
660 gfc_check_digits (gfc_expr * x)
662 if (int_or_real_check (x, 0) == FAILURE)
670 gfc_check_dot_product (gfc_expr * vector_a, gfc_expr * vector_b)
672 switch (vector_a->ts.type)
675 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
682 if (numeric_check (vector_b, 1) == FAILURE)
687 must_be (vector_a, 0, "numeric or LOGICAL");
691 if (rank_check (vector_a, 0, 1) == FAILURE)
694 if (rank_check (vector_b, 1, 1) == FAILURE)
702 gfc_check_eoshift (gfc_expr * array, gfc_expr * shift, gfc_expr * boundary,
705 if (array_check (array, 0) == FAILURE)
708 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
711 if (array->rank == 1)
713 if (scalar_check (shift, 2) == FAILURE)
718 /* TODO: more weird restrictions on shift. */
721 if (boundary != NULL)
723 if (same_type_check (array, 0, boundary, 2) == FAILURE)
726 /* TODO: more restrictions on boundary. */
729 if (dim_check (dim, 1, 1) == FAILURE)
736 /* A single complex argument. */
739 gfc_check_fn_c (gfc_expr * a)
741 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
748 /* A single real argument. */
751 gfc_check_fn_r (gfc_expr * a)
753 if (type_check (a, 0, BT_REAL) == FAILURE)
760 /* A single real or complex argument. */
763 gfc_check_fn_rc (gfc_expr * a)
765 if (real_or_complex_check (a, 0) == FAILURE)
773 gfc_check_fnum (gfc_expr * unit)
775 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
778 if (scalar_check (unit, 0) == FAILURE)
785 /* This is used for the g77 one-argument Bessel functions, and the
789 gfc_check_g77_math1 (gfc_expr * x)
791 if (scalar_check (x, 0) == FAILURE)
794 if (type_check (x, 0, BT_REAL) == FAILURE)
802 gfc_check_huge (gfc_expr * x)
804 if (int_or_real_check (x, 0) == FAILURE)
811 /* Check that the single argument is an integer. */
814 gfc_check_i (gfc_expr * i)
816 if (type_check (i, 0, BT_INTEGER) == FAILURE)
824 gfc_check_iand (gfc_expr * i, gfc_expr * j)
826 if (type_check (i, 0, BT_INTEGER) == FAILURE)
829 if (type_check (j, 1, BT_INTEGER) == FAILURE)
832 if (i->ts.kind != j->ts.kind)
834 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
835 &i->where) == FAILURE)
844 gfc_check_ibclr (gfc_expr * i, gfc_expr * pos)
846 if (type_check (i, 0, BT_INTEGER) == FAILURE)
849 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
857 gfc_check_ibits (gfc_expr * i, gfc_expr * pos, gfc_expr * len)
859 if (type_check (i, 0, BT_INTEGER) == FAILURE)
862 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
865 if (type_check (len, 2, BT_INTEGER) == FAILURE)
873 gfc_check_ibset (gfc_expr * i, gfc_expr * pos)
875 if (type_check (i, 0, BT_INTEGER) == FAILURE)
878 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
886 gfc_check_idnint (gfc_expr * a)
888 if (double_check (a, 0) == FAILURE)
896 gfc_check_ieor (gfc_expr * i, gfc_expr * j)
898 if (type_check (i, 0, BT_INTEGER) == FAILURE)
901 if (type_check (j, 1, BT_INTEGER) == FAILURE)
904 if (i->ts.kind != j->ts.kind)
906 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
907 &i->where) == FAILURE)
916 gfc_check_index (gfc_expr * string, gfc_expr * substring, gfc_expr * back)
918 if (type_check (string, 0, BT_CHARACTER) == FAILURE
919 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
923 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
926 if (string->ts.kind != substring->ts.kind)
928 must_be (substring, 1, "the same kind as 'string'");
937 gfc_check_int (gfc_expr * x, gfc_expr * kind)
939 if (numeric_check (x, 0) == FAILURE
940 || kind_check (kind, 1, BT_INTEGER) == FAILURE)
948 gfc_check_ior (gfc_expr * i, gfc_expr * j)
950 if (type_check (i, 0, BT_INTEGER) == FAILURE)
953 if (type_check (j, 1, BT_INTEGER) == FAILURE)
956 if (i->ts.kind != j->ts.kind)
958 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
959 &i->where) == FAILURE)
968 gfc_check_ishft (gfc_expr * i, gfc_expr * shift)
970 if (type_check (i, 0, BT_INTEGER) == FAILURE
971 || type_check (shift, 1, BT_INTEGER) == FAILURE)
979 gfc_check_ishftc (gfc_expr * i, gfc_expr * shift, gfc_expr * size)
981 if (type_check (i, 0, BT_INTEGER) == FAILURE
982 || type_check (shift, 1, BT_INTEGER) == FAILURE)
985 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
993 gfc_check_kind (gfc_expr * x)
995 if (x->ts.type == BT_DERIVED)
997 must_be (x, 0, "a non-derived type");
1006 gfc_check_lbound (gfc_expr * array, gfc_expr * dim)
1008 if (array_check (array, 0) == FAILURE)
1013 if (dim_check (dim, 1, 1) == FAILURE)
1016 if (dim_rank_check (dim, array, 1) == FAILURE)
1024 gfc_check_logical (gfc_expr * a, gfc_expr * kind)
1026 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1028 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1035 /* Min/max family. */
1038 min_max_args (gfc_actual_arglist * arg)
1040 if (arg == NULL || arg->next == NULL)
1042 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1043 gfc_current_intrinsic, gfc_current_intrinsic_where);
1052 check_rest (bt type, int kind, gfc_actual_arglist * arg)
1057 if (min_max_args (arg) == FAILURE)
1062 for (; arg; arg = arg->next, n++)
1065 if (x->ts.type != type || x->ts.kind != kind)
1067 if (x->ts.type == type)
1069 if (gfc_notify_std (GFC_STD_GNU,
1070 "Extension: Different type kinds at %L", &x->where)
1076 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be %s(%d)",
1077 n, gfc_current_intrinsic, &x->where,
1078 gfc_basic_typename (type), kind);
1089 gfc_check_min_max (gfc_actual_arglist * arg)
1093 if (min_max_args (arg) == FAILURE)
1098 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1101 ("'a1' argument of '%s' intrinsic at %L must be INTEGER or REAL",
1102 gfc_current_intrinsic, &x->where);
1106 return check_rest (x->ts.type, x->ts.kind, arg);
1111 gfc_check_min_max_integer (gfc_actual_arglist * arg)
1113 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1118 gfc_check_min_max_real (gfc_actual_arglist * arg)
1120 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1125 gfc_check_min_max_double (gfc_actual_arglist * arg)
1127 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1130 /* End of min/max family. */
1134 gfc_check_matmul (gfc_expr * matrix_a, gfc_expr * matrix_b)
1136 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1138 must_be (matrix_a, 0, "numeric or LOGICAL");
1142 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1144 must_be (matrix_b, 0, "numeric or LOGICAL");
1148 switch (matrix_a->rank)
1151 if (rank_check (matrix_b, 1, 2) == FAILURE)
1156 if (matrix_b->rank == 2)
1158 if (rank_check (matrix_b, 1, 1) == FAILURE)
1163 must_be (matrix_a, 0, "of rank 1 or 2");
1171 /* Whoever came up with this interface was probably on something.
1172 The possibilities for the occupation of the second and third
1179 NULL MASK minloc(array, mask=m)
1182 I.e. in the case of minloc(array,mask), mask will be in the second
1183 position of the argument list and we'll have to fix that up. */
1186 gfc_check_minloc_maxloc (gfc_actual_arglist * ap)
1188 gfc_expr *a, *m, *d;
1191 if (int_or_real_check (a, 0) == FAILURE
1192 || array_check (a, 0) == FAILURE)
1196 m = ap->next->next->expr;
1198 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1199 && ap->next->name[0] == '\0')
1204 ap->next->expr = NULL;
1205 ap->next->next->expr = m;
1209 && (scalar_check (d, 1) == FAILURE
1210 || type_check (d, 1, BT_INTEGER) == FAILURE))
1213 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1220 /* Similar to minloc/maxloc, the argument list might need to be
1221 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1222 difference is that MINLOC/MAXLOC take an additional KIND argument.
1223 The possibilities are:
1229 NULL MASK minval(array, mask=m)
1232 I.e. in the case of minval(array,mask), mask will be in the second
1233 position of the argument list and we'll have to fix that up. */
1236 check_reduction (gfc_actual_arglist * ap)
1241 m = ap->next->next->expr;
1243 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1244 && ap->next->name[0] == '\0')
1249 ap->next->expr = NULL;
1250 ap->next->next->expr = m;
1254 && (scalar_check (d, 1) == FAILURE
1255 || type_check (d, 1, BT_INTEGER) == FAILURE))
1258 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1266 gfc_check_minval_maxval (gfc_actual_arglist * ap)
1268 if (int_or_real_check (ap->expr, 0) == FAILURE
1269 || array_check (ap->expr, 0) == FAILURE)
1272 return check_reduction (ap);
1277 gfc_check_product_sum (gfc_actual_arglist * ap)
1279 if (numeric_check (ap->expr, 0) == FAILURE
1280 || array_check (ap->expr, 0) == FAILURE)
1283 return check_reduction (ap);
1288 gfc_check_merge (gfc_expr * tsource, gfc_expr * fsource, gfc_expr * mask)
1290 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1293 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1301 gfc_check_nearest (gfc_expr * x, gfc_expr * s)
1303 if (type_check (x, 0, BT_REAL) == FAILURE)
1306 if (type_check (s, 1, BT_REAL) == FAILURE)
1314 gfc_check_null (gfc_expr * mold)
1316 symbol_attribute attr;
1321 if (variable_check (mold, 0) == FAILURE)
1324 attr = gfc_variable_attr (mold, NULL);
1328 must_be (mold, 0, "a POINTER");
1337 gfc_check_pack (gfc_expr * array, gfc_expr * mask, gfc_expr * vector)
1339 if (array_check (array, 0) == FAILURE)
1342 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1345 if (mask->rank != 0 && mask->rank != array->rank)
1347 must_be (array, 0, "conformable with 'mask' argument");
1353 if (same_type_check (array, 0, vector, 2) == FAILURE)
1356 if (rank_check (vector, 2, 1) == FAILURE)
1359 /* TODO: More constraints here. */
1367 gfc_check_precision (gfc_expr * x)
1369 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1371 must_be (x, 0, "of type REAL or COMPLEX");
1380 gfc_check_present (gfc_expr * a)
1384 if (variable_check (a, 0) == FAILURE)
1387 sym = a->symtree->n.sym;
1388 if (!sym->attr.dummy)
1390 must_be (a, 0, "a dummy variable");
1394 if (!sym->attr.optional)
1396 must_be (a, 0, "an OPTIONAL dummy variable");
1405 gfc_check_radix (gfc_expr * x)
1407 if (int_or_real_check (x, 0) == FAILURE)
1415 gfc_check_range (gfc_expr * x)
1417 if (numeric_check (x, 0) == FAILURE)
1424 /* real, float, sngl. */
1426 gfc_check_real (gfc_expr * a, gfc_expr * kind)
1428 if (numeric_check (a, 0) == FAILURE)
1431 if (kind_check (kind, 1, BT_REAL) == FAILURE)
1439 gfc_check_repeat (gfc_expr * x, gfc_expr * y)
1441 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1444 if (scalar_check (x, 0) == FAILURE)
1447 if (type_check (y, 0, BT_INTEGER) == FAILURE)
1450 if (scalar_check (y, 1) == FAILURE)
1458 gfc_check_reshape (gfc_expr * source, gfc_expr * shape,
1459 gfc_expr * pad, gfc_expr * order)
1464 if (array_check (source, 0) == FAILURE)
1467 if (rank_check (shape, 1, 1) == FAILURE)
1470 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
1473 if (gfc_array_size (shape, &size) != SUCCESS)
1475 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
1476 "array of constant size", &shape->where);
1480 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
1486 ("'shape' argument of 'reshape' intrinsic at %L has more than "
1487 stringize (GFC_MAX_DIMENSIONS) " elements", &shape->where);
1493 if (same_type_check (source, 0, pad, 2) == FAILURE)
1495 if (array_check (pad, 2) == FAILURE)
1499 if (order != NULL && array_check (order, 3) == FAILURE)
1507 gfc_check_scale (gfc_expr * x, gfc_expr * i)
1509 if (type_check (x, 0, BT_REAL) == FAILURE)
1512 if (type_check (i, 1, BT_INTEGER) == FAILURE)
1520 gfc_check_scan (gfc_expr * x, gfc_expr * y, gfc_expr * z)
1522 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1525 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
1528 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
1531 if (same_type_check (x, 0, y, 1) == FAILURE)
1539 gfc_check_selected_real_kind (gfc_expr * p, gfc_expr * r)
1541 if (p == NULL && r == NULL)
1543 gfc_error ("Missing arguments to %s intrinsic at %L",
1544 gfc_current_intrinsic, gfc_current_intrinsic_where);
1549 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
1552 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
1560 gfc_check_set_exponent (gfc_expr * x, gfc_expr * i)
1562 if (type_check (x, 0, BT_REAL) == FAILURE)
1565 if (type_check (i, 1, BT_INTEGER) == FAILURE)
1573 gfc_check_shape (gfc_expr * source)
1577 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
1580 ar = gfc_find_array_ref (source);
1582 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
1584 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
1585 "an assumed size array", &source->where);
1594 gfc_check_sign (gfc_expr * a, gfc_expr * b)
1596 if (int_or_real_check (a, 0) == FAILURE)
1599 if (same_type_check (a, 0, b, 1) == FAILURE)
1607 gfc_check_size (gfc_expr * array, gfc_expr * dim)
1609 if (array_check (array, 0) == FAILURE)
1614 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
1617 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
1620 if (dim_rank_check (dim, array, 0) == FAILURE)
1629 gfc_check_spread (gfc_expr * source, gfc_expr * dim, gfc_expr * ncopies)
1631 if (source->rank >= GFC_MAX_DIMENSIONS)
1633 must_be (source, 0, "less than rank " stringize (GFC_MAX_DIMENSIONS));
1637 if (dim_check (dim, 1, 0) == FAILURE)
1640 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
1643 if (scalar_check (ncopies, 2) == FAILURE)
1651 gfc_check_fstat (gfc_expr * unit, gfc_expr * array)
1653 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1656 if (scalar_check (unit, 0) == FAILURE)
1659 if (type_check (array, 1, BT_INTEGER) == FAILURE
1660 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
1663 if (array_check (array, 1) == FAILURE)
1671 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)
1703 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1706 if (type_check (array, 1, BT_INTEGER) == FAILURE
1707 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
1710 if (array_check (array, 1) == FAILURE)
1718 gfc_check_stat_sub (gfc_expr * name, gfc_expr * array, gfc_expr * status)
1720 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1723 if (type_check (array, 1, BT_INTEGER) == FAILURE
1724 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
1727 if (array_check (array, 1) == FAILURE)
1733 if (type_check (status, 2, BT_INTEGER) == FAILURE
1734 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
1737 if (scalar_check (status, 2) == FAILURE)
1745 gfc_check_transfer (gfc_expr * source ATTRIBUTE_UNUSED,
1746 gfc_expr * mold ATTRIBUTE_UNUSED,
1751 if (type_check (size, 2, BT_INTEGER) == FAILURE)
1754 if (scalar_check (size, 2) == FAILURE)
1757 if (nonoptional_check (size, 2) == FAILURE)
1766 gfc_check_transpose (gfc_expr * matrix)
1768 if (rank_check (matrix, 0, 2) == FAILURE)
1776 gfc_check_ubound (gfc_expr * array, gfc_expr * dim)
1778 if (array_check (array, 0) == FAILURE)
1783 if (dim_check (dim, 1, 1) == FAILURE)
1786 if (dim_rank_check (dim, array, 0) == FAILURE)
1795 gfc_check_unpack (gfc_expr * vector, gfc_expr * mask, gfc_expr * field)
1797 if (rank_check (vector, 0, 1) == FAILURE)
1800 if (array_check (mask, 1) == FAILURE)
1803 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1806 if (same_type_check (vector, 0, field, 2) == FAILURE)
1814 gfc_check_verify (gfc_expr * x, gfc_expr * y, gfc_expr * z)
1816 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1819 if (same_type_check (x, 0, y, 1) == FAILURE)
1822 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
1830 gfc_check_trim (gfc_expr * x)
1832 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1835 if (scalar_check (x, 0) == FAILURE)
1842 /* Common check function for the half a dozen intrinsics that have a
1843 single real argument. */
1846 gfc_check_x (gfc_expr * x)
1848 if (type_check (x, 0, BT_REAL) == FAILURE)
1855 /************* Check functions for intrinsic subroutines *************/
1858 gfc_check_cpu_time (gfc_expr * time)
1860 if (scalar_check (time, 0) == FAILURE)
1863 if (type_check (time, 0, BT_REAL) == FAILURE)
1866 if (variable_check (time, 0) == FAILURE)
1874 gfc_check_date_and_time (gfc_expr * date, gfc_expr * time,
1875 gfc_expr * zone, gfc_expr * values)
1879 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
1881 if (scalar_check (date, 0) == FAILURE)
1883 if (variable_check (date, 0) == FAILURE)
1889 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
1891 if (scalar_check (time, 1) == FAILURE)
1893 if (variable_check (time, 1) == FAILURE)
1899 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
1901 if (scalar_check (zone, 2) == FAILURE)
1903 if (variable_check (zone, 2) == FAILURE)
1909 if (type_check (values, 3, BT_INTEGER) == FAILURE)
1911 if (array_check (values, 3) == FAILURE)
1913 if (rank_check (values, 3, 1) == FAILURE)
1915 if (variable_check (values, 3) == FAILURE)
1924 gfc_check_mvbits (gfc_expr * from, gfc_expr * frompos, gfc_expr * len,
1925 gfc_expr * to, gfc_expr * topos)
1927 if (type_check (from, 0, BT_INTEGER) == FAILURE)
1930 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
1933 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1936 if (same_type_check (from, 0, to, 3) == FAILURE)
1939 if (variable_check (to, 3) == FAILURE)
1942 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
1950 gfc_check_random_number (gfc_expr * harvest)
1952 if (type_check (harvest, 0, BT_REAL) == FAILURE)
1955 if (variable_check (harvest, 0) == FAILURE)
1963 gfc_check_random_seed (gfc_expr * size, gfc_expr * put, gfc_expr * get)
1967 if (scalar_check (size, 0) == FAILURE)
1970 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1973 if (variable_check (size, 0) == FAILURE)
1976 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
1984 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
1987 if (array_check (put, 1) == FAILURE)
1990 if (rank_check (put, 1, 1) == FAILURE)
1993 if (type_check (put, 1, BT_INTEGER) == FAILURE)
1996 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2003 if (size != NULL || put != NULL)
2004 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2007 if (array_check (get, 2) == FAILURE)
2010 if (rank_check (get, 2, 1) == FAILURE)
2013 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2016 if (variable_check (get, 2) == FAILURE)
2019 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2027 gfc_check_second_sub (gfc_expr * time)
2029 if (scalar_check (time, 0) == FAILURE)
2032 if (type_check (time, 0, BT_REAL) == FAILURE)
2035 if (kind_value_check(time, 0, 4) == FAILURE)
2042 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2043 count, count_rate, and count_max are all optional arguments */
2046 gfc_check_system_clock (gfc_expr * count, gfc_expr * count_rate,
2047 gfc_expr * count_max)
2051 if (scalar_check (count, 0) == FAILURE)
2054 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2057 if (variable_check (count, 0) == FAILURE)
2061 if (count_rate != NULL)
2063 if (scalar_check (count_rate, 1) == FAILURE)
2066 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2069 if (variable_check (count_rate, 1) == FAILURE)
2073 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2078 if (count_max != NULL)
2080 if (scalar_check (count_max, 2) == FAILURE)
2083 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2086 if (variable_check (count_max, 2) == FAILURE)
2090 && same_type_check (count, 0, count_max, 2) == FAILURE)
2093 if (count_rate != NULL
2094 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2102 gfc_check_irand (gfc_expr * x)
2107 if (scalar_check (x, 0) == FAILURE)
2110 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2113 if (kind_value_check(x, 0, 4) == FAILURE)
2120 gfc_check_rand (gfc_expr * x)
2125 if (scalar_check (x, 0) == FAILURE)
2128 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2131 if (kind_value_check(x, 0, 4) == FAILURE)
2138 gfc_check_srand (gfc_expr * x)
2140 if (scalar_check (x, 0) == FAILURE)
2143 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2146 if (kind_value_check(x, 0, 4) == FAILURE)
2153 gfc_check_etime (gfc_expr * x)
2155 if (array_check (x, 0) == FAILURE)
2158 if (rank_check (x, 0, 1) == FAILURE)
2161 if (variable_check (x, 0) == FAILURE)
2164 if (type_check (x, 0, BT_REAL) == FAILURE)
2167 if (kind_value_check(x, 0, 4) == FAILURE)
2174 gfc_check_etime_sub (gfc_expr * values, gfc_expr * time)
2176 if (array_check (values, 0) == FAILURE)
2179 if (rank_check (values, 0, 1) == FAILURE)
2182 if (variable_check (values, 0) == FAILURE)
2185 if (type_check (values, 0, BT_REAL) == FAILURE)
2188 if (kind_value_check(values, 0, 4) == FAILURE)
2191 if (scalar_check (time, 1) == FAILURE)
2194 if (type_check (time, 1, BT_REAL) == FAILURE)
2197 if (kind_value_check(time, 1, 4) == FAILURE)
2205 gfc_check_getcwd_sub (gfc_expr * cwd, gfc_expr * status)
2207 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
2213 if (scalar_check (status, 1) == FAILURE)
2216 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2224 gfc_check_exit (gfc_expr * status)
2229 if (type_check (status, 0, BT_INTEGER) == FAILURE)
2232 if (scalar_check (status, 0) == FAILURE)
2240 gfc_check_flush (gfc_expr * unit)
2245 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2248 if (scalar_check (unit, 0) == FAILURE)
2256 gfc_check_umask (gfc_expr * mask)
2258 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
2261 if (scalar_check (mask, 0) == FAILURE)
2269 gfc_check_umask_sub (gfc_expr * mask, gfc_expr * old)
2271 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
2274 if (scalar_check (mask, 0) == FAILURE)
2280 if (scalar_check (old, 1) == FAILURE)
2283 if (type_check (old, 1, BT_INTEGER) == FAILURE)
2291 gfc_check_unlink (gfc_expr * name)
2293 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2301 gfc_check_unlink_sub (gfc_expr * name, gfc_expr * status)
2303 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2309 if (scalar_check (status, 1) == FAILURE)
2312 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2320 gfc_check_system_sub (gfc_expr * cmd, gfc_expr * status)
2322 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
2325 if (scalar_check (status, 1) == FAILURE)
2328 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2331 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)