gcc:
[official-gcc.git] / gcc / fortran / check.c
blobfe96ea4dc9171b9f9ad0ade607dec48c6af54e7b
1 /* Check functions
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
10 version.
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
15 for more details.
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, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
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. */
29 #include "config.h"
30 #include "system.h"
31 #include "flags.h"
32 #include "gfortran.h"
33 #include "intrinsic.h"
36 /* Check the type of an expression. */
38 static try
39 type_check (gfc_expr * e, int n, bt type)
41 if (e->ts.type == type)
42 return SUCCESS;
44 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
45 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where,
46 gfc_basic_typename (type));
48 return FAILURE;
52 /* Check that the expression is a numeric type. */
54 static try
55 numeric_check (gfc_expr * e, int n)
57 if (gfc_numeric_ts (&e->ts))
58 return SUCCESS;
60 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
61 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
63 return FAILURE;
67 /* Check that an expression is integer or real. */
69 static try
70 int_or_real_check (gfc_expr * e, int n)
72 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
74 gfc_error (
75 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
76 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
77 return FAILURE;
80 return SUCCESS;
84 /* Check that an expression is real or complex. */
86 static try
87 real_or_complex_check (gfc_expr * e, int n)
89 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
91 gfc_error (
92 "'%s' argument of '%s' intrinsic at %L must be REAL or COMPLEX",
93 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
94 return FAILURE;
97 return SUCCESS;
101 /* Check that the expression is an optional constant integer
102 and that it specifies a valid kind for that type. */
104 static try
105 kind_check (gfc_expr * k, int n, bt type)
107 int kind;
109 if (k == NULL)
110 return SUCCESS;
112 if (type_check (k, n, BT_INTEGER) == FAILURE)
113 return FAILURE;
115 if (k->expr_type != EXPR_CONSTANT)
117 gfc_error (
118 "'%s' argument of '%s' intrinsic at %L must be a constant",
119 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &k->where);
120 return FAILURE;
123 if (gfc_extract_int (k, &kind) != NULL
124 || gfc_validate_kind (type, kind, true) < 0)
126 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
127 &k->where);
128 return FAILURE;
131 return SUCCESS;
135 /* Make sure the expression is a double precision real. */
137 static try
138 double_check (gfc_expr * d, int n)
140 if (type_check (d, n, BT_REAL) == FAILURE)
141 return FAILURE;
143 if (d->ts.kind != gfc_default_double_kind)
145 gfc_error (
146 "'%s' argument of '%s' intrinsic at %L must be double precision",
147 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &d->where);
148 return FAILURE;
151 return SUCCESS;
155 /* Make sure the expression is a logical array. */
157 static try
158 logical_array_check (gfc_expr * array, int n)
160 if (array->ts.type != BT_LOGICAL || array->rank == 0)
162 gfc_error (
163 "'%s' argument of '%s' intrinsic at %L must be a logical array",
164 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &array->where);
165 return FAILURE;
168 return SUCCESS;
172 /* Make sure an expression is an array. */
174 static try
175 array_check (gfc_expr * e, int n)
177 if (e->rank != 0)
178 return SUCCESS;
180 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
181 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
183 return FAILURE;
187 /* Make sure an expression is a scalar. */
189 static try
190 scalar_check (gfc_expr * e, int n)
192 if (e->rank == 0)
193 return SUCCESS;
195 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
196 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
198 return FAILURE;
202 /* Make sure two expression have the same type. */
204 static try
205 same_type_check (gfc_expr * e, int n, gfc_expr * f, int m)
207 if (gfc_compare_types (&e->ts, &f->ts))
208 return SUCCESS;
210 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
211 "and kind as '%s'", gfc_current_intrinsic_arg[m],
212 gfc_current_intrinsic, &f->where, gfc_current_intrinsic_arg[n]);
213 return FAILURE;
217 /* Make sure that an expression has a certain (nonzero) rank. */
219 static try
220 rank_check (gfc_expr * e, int n, int rank)
222 if (e->rank == rank)
223 return SUCCESS;
225 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
226 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
227 &e->where, rank);
228 return FAILURE;
232 /* Make sure a variable expression is not an optional dummy argument. */
234 static try
235 nonoptional_check (gfc_expr * e, int n)
237 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
239 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
240 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
241 &e->where);
245 /* TODO: Recursive check on nonoptional variables? */
247 return SUCCESS;
251 /* Check that an expression has a particular kind. */
253 static try
254 kind_value_check (gfc_expr * e, int n, int k)
256 if (e->ts.kind == k)
257 return SUCCESS;
259 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
260 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
261 &e->where, k);
262 return FAILURE;
266 /* Make sure an expression is a variable. */
268 static try
269 variable_check (gfc_expr * e, int n)
271 if ((e->expr_type == EXPR_VARIABLE
272 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
273 || (e->expr_type == EXPR_FUNCTION
274 && e->symtree->n.sym->result == e->symtree->n.sym))
275 return SUCCESS;
277 if (e->expr_type == EXPR_VARIABLE
278 && e->symtree->n.sym->attr.intent == INTENT_IN)
280 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
281 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
282 &e->where);
283 return FAILURE;
286 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
287 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
289 return FAILURE;
293 /* Check the common DIM parameter for correctness. */
295 static try
296 dim_check (gfc_expr * dim, int n, int optional)
298 if (optional)
300 if (dim == NULL)
301 return SUCCESS;
303 if (nonoptional_check (dim, n) == FAILURE)
304 return FAILURE;
306 return SUCCESS;
309 if (dim == NULL)
311 gfc_error ("Missing DIM parameter in intrinsic '%s' at %L",
312 gfc_current_intrinsic, gfc_current_intrinsic_where);
313 return FAILURE;
316 if (type_check (dim, n, BT_INTEGER) == FAILURE)
317 return FAILURE;
319 if (scalar_check (dim, n) == FAILURE)
320 return FAILURE;
322 return SUCCESS;
326 /* If a DIM parameter is a constant, make sure that it is greater than
327 zero and less than or equal to the rank of the given array. If
328 allow_assumed is zero then dim must be less than the rank of the array
329 for assumed size arrays. */
331 static try
332 dim_rank_check (gfc_expr * dim, gfc_expr * array, int allow_assumed)
334 gfc_array_ref *ar;
335 int rank;
337 if (dim->expr_type != EXPR_CONSTANT || array->expr_type != EXPR_VARIABLE)
338 return SUCCESS;
340 ar = gfc_find_array_ref (array);
341 rank = array->rank;
342 if (ar->as->type == AS_ASSUMED_SIZE && !allow_assumed)
343 rank--;
345 if (mpz_cmp_ui (dim->value.integer, 1) < 0
346 || mpz_cmp_ui (dim->value.integer, rank) > 0)
348 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
349 "dimension index", gfc_current_intrinsic, &dim->where);
351 return FAILURE;
354 return SUCCESS;
358 /***** Check functions *****/
360 /* Check subroutine suitable for intrinsics taking a real argument and
361 a kind argument for the result. */
363 static try
364 check_a_kind (gfc_expr * a, gfc_expr * kind, bt type)
366 if (type_check (a, 0, BT_REAL) == FAILURE)
367 return FAILURE;
368 if (kind_check (kind, 1, type) == FAILURE)
369 return FAILURE;
371 return SUCCESS;
374 /* Check subroutine suitable for ceiling, floor and nint. */
377 gfc_check_a_ikind (gfc_expr * a, gfc_expr * kind)
379 return check_a_kind (a, kind, BT_INTEGER);
382 /* Check subroutine suitable for aint, anint. */
385 gfc_check_a_xkind (gfc_expr * a, gfc_expr * kind)
387 return check_a_kind (a, kind, BT_REAL);
391 gfc_check_abs (gfc_expr * a)
393 if (numeric_check (a, 0) == FAILURE)
394 return FAILURE;
396 return SUCCESS;
400 gfc_check_achar (gfc_expr * a)
403 if (type_check (a, 0, BT_INTEGER) == FAILURE)
404 return FAILURE;
406 return SUCCESS;
411 gfc_check_all_any (gfc_expr * mask, gfc_expr * dim)
413 if (logical_array_check (mask, 0) == FAILURE)
414 return FAILURE;
416 if (dim_check (dim, 1, 1) == FAILURE)
417 return FAILURE;
419 return SUCCESS;
424 gfc_check_allocated (gfc_expr * array)
426 if (variable_check (array, 0) == FAILURE)
427 return FAILURE;
429 if (array_check (array, 0) == FAILURE)
430 return FAILURE;
432 if (!array->symtree->n.sym->attr.allocatable)
434 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
435 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
436 &array->where);
437 return FAILURE;
440 return SUCCESS;
444 /* Common check function where the first argument must be real or
445 integer and the second argument must be the same as the first. */
448 gfc_check_a_p (gfc_expr * a, gfc_expr * p)
450 if (int_or_real_check (a, 0) == FAILURE)
451 return FAILURE;
453 if (same_type_check (a, 0, p, 1) == FAILURE)
454 return FAILURE;
456 return SUCCESS;
461 gfc_check_associated (gfc_expr * pointer, gfc_expr * target)
463 symbol_attribute attr;
464 int i;
465 try t;
467 if (variable_check (pointer, 0) == FAILURE)
468 return FAILURE;
470 attr = gfc_variable_attr (pointer, NULL);
471 if (!attr.pointer)
473 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
474 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
475 &pointer->where);
476 return FAILURE;
479 if (target == NULL)
480 return SUCCESS;
482 /* Target argument is optional. */
483 if (target->expr_type == EXPR_NULL)
485 gfc_error ("NULL pointer at %L is not permitted as actual argument "
486 "of '%s' intrinsic function",
487 &target->where, gfc_current_intrinsic);
488 return FAILURE;
491 attr = gfc_variable_attr (target, NULL);
492 if (!attr.pointer && !attr.target)
494 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
495 "or a TARGET", gfc_current_intrinsic_arg[1],
496 gfc_current_intrinsic, &target->where);
497 return FAILURE;
500 t = SUCCESS;
501 if (same_type_check (pointer, 0, target, 1) == FAILURE)
502 t = FAILURE;
503 if (rank_check (target, 0, pointer->rank) == FAILURE)
504 t = FAILURE;
505 if (target->rank > 0)
507 for (i = 0; i < target->rank; i++)
508 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
510 gfc_error ("Array section with a vector subscript at %L shall not "
511 "be the target of a pointer",
512 &target->where);
513 t = FAILURE;
514 break;
517 return t;
522 gfc_check_atan2 (gfc_expr * y, gfc_expr * x)
524 if (type_check (y, 0, BT_REAL) == FAILURE)
525 return FAILURE;
526 if (same_type_check (y, 0, x, 1) == FAILURE)
527 return FAILURE;
529 return SUCCESS;
533 /* BESJN and BESYN functions. */
536 gfc_check_besn (gfc_expr * n, gfc_expr * x)
538 if (scalar_check (n, 0) == FAILURE)
539 return FAILURE;
541 if (type_check (n, 0, BT_INTEGER) == FAILURE)
542 return FAILURE;
544 if (scalar_check (x, 1) == FAILURE)
545 return FAILURE;
547 if (type_check (x, 1, BT_REAL) == FAILURE)
548 return FAILURE;
550 return SUCCESS;
555 gfc_check_btest (gfc_expr * i, gfc_expr * pos)
557 if (type_check (i, 0, BT_INTEGER) == FAILURE)
558 return FAILURE;
559 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
560 return FAILURE;
562 return SUCCESS;
567 gfc_check_char (gfc_expr * i, gfc_expr * kind)
569 if (type_check (i, 0, BT_INTEGER) == FAILURE)
570 return FAILURE;
571 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
572 return FAILURE;
574 return SUCCESS;
579 gfc_check_chdir (gfc_expr * dir)
581 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
582 return FAILURE;
584 return SUCCESS;
589 gfc_check_chdir_sub (gfc_expr * dir, gfc_expr * status)
591 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
592 return FAILURE;
594 if (status == NULL)
595 return SUCCESS;
597 if (type_check (status, 1, BT_INTEGER) == FAILURE)
598 return FAILURE;
600 if (scalar_check (status, 1) == FAILURE)
601 return FAILURE;
603 return SUCCESS;
608 gfc_check_cmplx (gfc_expr * x, gfc_expr * y, gfc_expr * kind)
610 if (numeric_check (x, 0) == FAILURE)
611 return FAILURE;
613 if (y != NULL)
615 if (numeric_check (y, 1) == FAILURE)
616 return FAILURE;
618 if (x->ts.type == BT_COMPLEX)
620 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
621 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
622 gfc_current_intrinsic, &y->where);
623 return FAILURE;
627 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
628 return FAILURE;
630 return SUCCESS;
635 gfc_check_count (gfc_expr * mask, gfc_expr * dim)
637 if (logical_array_check (mask, 0) == FAILURE)
638 return FAILURE;
639 if (dim_check (dim, 1, 1) == FAILURE)
640 return FAILURE;
642 return SUCCESS;
647 gfc_check_cshift (gfc_expr * array, gfc_expr * shift, gfc_expr * dim)
649 if (array_check (array, 0) == FAILURE)
650 return FAILURE;
652 if (array->rank == 1)
654 if (scalar_check (shift, 1) == FAILURE)
655 return FAILURE;
657 else
659 /* TODO: more requirements on shift parameter. */
662 if (dim_check (dim, 2, 1) == FAILURE)
663 return FAILURE;
665 return SUCCESS;
670 gfc_check_dcmplx (gfc_expr * x, gfc_expr * y)
672 if (numeric_check (x, 0) == FAILURE)
673 return FAILURE;
675 if (y != NULL)
677 if (numeric_check (y, 1) == FAILURE)
678 return FAILURE;
680 if (x->ts.type == BT_COMPLEX)
682 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
683 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
684 gfc_current_intrinsic, &y->where);
685 return FAILURE;
689 return SUCCESS;
694 gfc_check_dble (gfc_expr * x)
696 if (numeric_check (x, 0) == FAILURE)
697 return FAILURE;
699 return SUCCESS;
704 gfc_check_digits (gfc_expr * x)
706 if (int_or_real_check (x, 0) == FAILURE)
707 return FAILURE;
709 return SUCCESS;
714 gfc_check_dot_product (gfc_expr * vector_a, gfc_expr * vector_b)
716 switch (vector_a->ts.type)
718 case BT_LOGICAL:
719 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
720 return FAILURE;
721 break;
723 case BT_INTEGER:
724 case BT_REAL:
725 case BT_COMPLEX:
726 if (numeric_check (vector_b, 1) == FAILURE)
727 return FAILURE;
728 break;
730 default:
731 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
732 "or LOGICAL", gfc_current_intrinsic_arg[0],
733 gfc_current_intrinsic, &vector_a->where);
734 return FAILURE;
737 if (rank_check (vector_a, 0, 1) == FAILURE)
738 return FAILURE;
740 if (rank_check (vector_b, 1, 1) == FAILURE)
741 return FAILURE;
743 return SUCCESS;
748 gfc_check_eoshift (gfc_expr * array, gfc_expr * shift, gfc_expr * boundary,
749 gfc_expr * dim)
751 if (array_check (array, 0) == FAILURE)
752 return FAILURE;
754 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
755 return FAILURE;
757 if (array->rank == 1)
759 if (scalar_check (shift, 2) == FAILURE)
760 return FAILURE;
762 else
764 /* TODO: more weird restrictions on shift. */
767 if (boundary != NULL)
769 if (same_type_check (array, 0, boundary, 2) == FAILURE)
770 return FAILURE;
772 /* TODO: more restrictions on boundary. */
775 if (dim_check (dim, 1, 1) == FAILURE)
776 return FAILURE;
778 return SUCCESS;
782 /* A single complex argument. */
785 gfc_check_fn_c (gfc_expr * a)
787 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
788 return FAILURE;
790 return SUCCESS;
794 /* A single real argument. */
797 gfc_check_fn_r (gfc_expr * a)
799 if (type_check (a, 0, BT_REAL) == FAILURE)
800 return FAILURE;
802 return SUCCESS;
806 /* A single real or complex argument. */
809 gfc_check_fn_rc (gfc_expr * a)
811 if (real_or_complex_check (a, 0) == FAILURE)
812 return FAILURE;
814 return SUCCESS;
819 gfc_check_fnum (gfc_expr * unit)
821 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
822 return FAILURE;
824 if (scalar_check (unit, 0) == FAILURE)
825 return FAILURE;
827 return SUCCESS;
831 /* This is used for the g77 one-argument Bessel functions, and the
832 error function. */
835 gfc_check_g77_math1 (gfc_expr * x)
837 if (scalar_check (x, 0) == FAILURE)
838 return FAILURE;
840 if (type_check (x, 0, BT_REAL) == FAILURE)
841 return FAILURE;
843 return SUCCESS;
848 gfc_check_huge (gfc_expr * x)
850 if (int_or_real_check (x, 0) == FAILURE)
851 return FAILURE;
853 return SUCCESS;
857 /* Check that the single argument is an integer. */
860 gfc_check_i (gfc_expr * i)
862 if (type_check (i, 0, BT_INTEGER) == FAILURE)
863 return FAILURE;
865 return SUCCESS;
870 gfc_check_iand (gfc_expr * i, gfc_expr * j)
872 if (type_check (i, 0, BT_INTEGER) == FAILURE)
873 return FAILURE;
875 if (type_check (j, 1, BT_INTEGER) == FAILURE)
876 return FAILURE;
878 if (i->ts.kind != j->ts.kind)
880 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
881 &i->where) == FAILURE)
882 return FAILURE;
885 return SUCCESS;
890 gfc_check_ibclr (gfc_expr * i, gfc_expr * pos)
892 if (type_check (i, 0, BT_INTEGER) == FAILURE)
893 return FAILURE;
895 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
896 return FAILURE;
898 return SUCCESS;
903 gfc_check_ibits (gfc_expr * i, gfc_expr * pos, gfc_expr * len)
905 if (type_check (i, 0, BT_INTEGER) == FAILURE)
906 return FAILURE;
908 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
909 return FAILURE;
911 if (type_check (len, 2, BT_INTEGER) == FAILURE)
912 return FAILURE;
914 return SUCCESS;
919 gfc_check_ibset (gfc_expr * i, gfc_expr * pos)
921 if (type_check (i, 0, BT_INTEGER) == FAILURE)
922 return FAILURE;
924 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
925 return FAILURE;
927 return SUCCESS;
932 gfc_check_ichar_iachar (gfc_expr * c)
934 int i;
936 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
937 return FAILURE;
939 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
941 gfc_expr *start;
942 gfc_expr *end;
943 gfc_ref *ref;
945 /* Substring references don't have the charlength set. */
946 ref = c->ref;
947 while (ref && ref->type != REF_SUBSTRING)
948 ref = ref->next;
950 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
952 if (!ref)
954 /* Check that the argument is length one. Non-constant lengths
955 can't be checked here, so assume thay are ok. */
956 if (c->ts.cl && c->ts.cl->length)
958 /* If we already have a length for this expression then use it. */
959 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
960 return SUCCESS;
961 i = mpz_get_si (c->ts.cl->length->value.integer);
963 else
964 return SUCCESS;
966 else
968 start = ref->u.ss.start;
969 end = ref->u.ss.end;
971 gcc_assert (start);
972 if (end == NULL || end->expr_type != EXPR_CONSTANT
973 || start->expr_type != EXPR_CONSTANT)
974 return SUCCESS;
976 i = mpz_get_si (end->value.integer) + 1
977 - mpz_get_si (start->value.integer);
980 else
981 return SUCCESS;
983 if (i != 1)
985 gfc_error ("Argument of %s at %L must be of length one",
986 gfc_current_intrinsic, &c->where);
987 return FAILURE;
990 return SUCCESS;
995 gfc_check_idnint (gfc_expr * a)
997 if (double_check (a, 0) == FAILURE)
998 return FAILURE;
1000 return SUCCESS;
1005 gfc_check_ieor (gfc_expr * i, gfc_expr * j)
1007 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1008 return FAILURE;
1010 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1011 return FAILURE;
1013 if (i->ts.kind != j->ts.kind)
1015 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1016 &i->where) == FAILURE)
1017 return FAILURE;
1020 return SUCCESS;
1025 gfc_check_index (gfc_expr * string, gfc_expr * substring, gfc_expr * back)
1027 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1028 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1029 return FAILURE;
1032 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1033 return FAILURE;
1035 if (string->ts.kind != substring->ts.kind)
1037 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1038 "kind as '%s'", gfc_current_intrinsic_arg[1],
1039 gfc_current_intrinsic, &substring->where,
1040 gfc_current_intrinsic_arg[0]);
1041 return FAILURE;
1044 return SUCCESS;
1049 gfc_check_int (gfc_expr * x, gfc_expr * kind)
1051 if (numeric_check (x, 0) == FAILURE)
1052 return FAILURE;
1054 if (kind != NULL)
1056 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1057 return FAILURE;
1059 if (scalar_check (kind, 1) == FAILURE)
1060 return FAILURE;
1063 return SUCCESS;
1068 gfc_check_ior (gfc_expr * i, gfc_expr * j)
1070 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1071 return FAILURE;
1073 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1074 return FAILURE;
1076 if (i->ts.kind != j->ts.kind)
1078 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1079 &i->where) == FAILURE)
1080 return FAILURE;
1083 return SUCCESS;
1088 gfc_check_ishft (gfc_expr * i, gfc_expr * shift)
1090 if (type_check (i, 0, BT_INTEGER) == FAILURE
1091 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1092 return FAILURE;
1094 return SUCCESS;
1099 gfc_check_ishftc (gfc_expr * i, gfc_expr * shift, gfc_expr * size)
1101 if (type_check (i, 0, BT_INTEGER) == FAILURE
1102 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1103 return FAILURE;
1105 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1106 return FAILURE;
1108 return SUCCESS;
1113 gfc_check_kill (gfc_expr * pid, gfc_expr * sig)
1115 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1116 return FAILURE;
1118 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1119 return FAILURE;
1121 return SUCCESS;
1126 gfc_check_kill_sub (gfc_expr * pid, gfc_expr * sig, gfc_expr * status)
1128 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1129 return FAILURE;
1131 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1132 return FAILURE;
1134 if (status == NULL)
1135 return SUCCESS;
1137 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1138 return FAILURE;
1140 if (scalar_check (status, 2) == FAILURE)
1141 return FAILURE;
1143 return SUCCESS;
1148 gfc_check_kind (gfc_expr * x)
1150 if (x->ts.type == BT_DERIVED)
1152 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1153 "non-derived type", gfc_current_intrinsic_arg[0],
1154 gfc_current_intrinsic, &x->where);
1155 return FAILURE;
1158 return SUCCESS;
1163 gfc_check_lbound (gfc_expr * array, gfc_expr * dim)
1165 if (array_check (array, 0) == FAILURE)
1166 return FAILURE;
1168 if (dim != NULL)
1170 if (dim_check (dim, 1, 1) == FAILURE)
1171 return FAILURE;
1173 if (dim_rank_check (dim, array, 1) == FAILURE)
1174 return FAILURE;
1176 return SUCCESS;
1181 gfc_check_link (gfc_expr * path1, gfc_expr * path2)
1183 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1184 return FAILURE;
1186 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1187 return FAILURE;
1189 return SUCCESS;
1194 gfc_check_link_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1196 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1197 return FAILURE;
1199 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1200 return FAILURE;
1202 if (status == NULL)
1203 return SUCCESS;
1205 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1206 return FAILURE;
1208 if (scalar_check (status, 2) == FAILURE)
1209 return FAILURE;
1211 return SUCCESS;
1215 gfc_check_loc (gfc_expr *expr)
1217 return variable_check (expr, 0);
1222 gfc_check_symlnk (gfc_expr * path1, gfc_expr * path2)
1224 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1225 return FAILURE;
1227 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1228 return FAILURE;
1230 return SUCCESS;
1235 gfc_check_symlnk_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1237 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1238 return FAILURE;
1240 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1241 return FAILURE;
1243 if (status == NULL)
1244 return SUCCESS;
1246 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1247 return FAILURE;
1249 if (scalar_check (status, 2) == FAILURE)
1250 return FAILURE;
1252 return SUCCESS;
1257 gfc_check_logical (gfc_expr * a, gfc_expr * kind)
1259 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1260 return FAILURE;
1261 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1262 return FAILURE;
1264 return SUCCESS;
1268 /* Min/max family. */
1270 static try
1271 min_max_args (gfc_actual_arglist * arg)
1273 if (arg == NULL || arg->next == NULL)
1275 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1276 gfc_current_intrinsic, gfc_current_intrinsic_where);
1277 return FAILURE;
1280 return SUCCESS;
1284 static try
1285 check_rest (bt type, int kind, gfc_actual_arglist * arg)
1287 gfc_expr *x;
1288 int n;
1290 if (min_max_args (arg) == FAILURE)
1291 return FAILURE;
1293 n = 1;
1295 for (; arg; arg = arg->next, n++)
1297 x = arg->expr;
1298 if (x->ts.type != type || x->ts.kind != kind)
1300 if (x->ts.type == type)
1302 if (gfc_notify_std (GFC_STD_GNU,
1303 "Extension: Different type kinds at %L", &x->where)
1304 == FAILURE)
1305 return FAILURE;
1307 else
1309 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be %s(%d)",
1310 n, gfc_current_intrinsic, &x->where,
1311 gfc_basic_typename (type), kind);
1312 return FAILURE;
1317 return SUCCESS;
1322 gfc_check_min_max (gfc_actual_arglist * arg)
1324 gfc_expr *x;
1326 if (min_max_args (arg) == FAILURE)
1327 return FAILURE;
1329 x = arg->expr;
1331 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1333 gfc_error
1334 ("'a1' argument of '%s' intrinsic at %L must be INTEGER or REAL",
1335 gfc_current_intrinsic, &x->where);
1336 return FAILURE;
1339 return check_rest (x->ts.type, x->ts.kind, arg);
1344 gfc_check_min_max_integer (gfc_actual_arglist * arg)
1346 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1351 gfc_check_min_max_real (gfc_actual_arglist * arg)
1353 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1358 gfc_check_min_max_double (gfc_actual_arglist * arg)
1360 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1363 /* End of min/max family. */
1366 gfc_check_malloc (gfc_expr * size)
1368 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1369 return FAILURE;
1371 if (scalar_check (size, 0) == FAILURE)
1372 return FAILURE;
1374 return SUCCESS;
1379 gfc_check_matmul (gfc_expr * matrix_a, gfc_expr * matrix_b)
1381 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1383 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1384 "or LOGICAL", gfc_current_intrinsic_arg[0],
1385 gfc_current_intrinsic, &matrix_a->where);
1386 return FAILURE;
1389 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1391 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1392 "or LOGICAL", gfc_current_intrinsic_arg[1],
1393 gfc_current_intrinsic, &matrix_b->where);
1394 return FAILURE;
1397 switch (matrix_a->rank)
1399 case 1:
1400 if (rank_check (matrix_b, 1, 2) == FAILURE)
1401 return FAILURE;
1402 break;
1404 case 2:
1405 if (matrix_b->rank == 2)
1406 break;
1407 if (rank_check (matrix_b, 1, 1) == FAILURE)
1408 return FAILURE;
1409 break;
1411 default:
1412 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1413 "1 or 2", gfc_current_intrinsic_arg[0],
1414 gfc_current_intrinsic, &matrix_a->where);
1415 return FAILURE;
1418 return SUCCESS;
1422 /* Whoever came up with this interface was probably on something.
1423 The possibilities for the occupation of the second and third
1424 parameters are:
1426 Arg #2 Arg #3
1427 NULL NULL
1428 DIM NULL
1429 MASK NULL
1430 NULL MASK minloc(array, mask=m)
1431 DIM MASK
1433 I.e. in the case of minloc(array,mask), mask will be in the second
1434 position of the argument list and we'll have to fix that up. */
1437 gfc_check_minloc_maxloc (gfc_actual_arglist * ap)
1439 gfc_expr *a, *m, *d;
1441 a = ap->expr;
1442 if (int_or_real_check (a, 0) == FAILURE
1443 || array_check (a, 0) == FAILURE)
1444 return FAILURE;
1446 d = ap->next->expr;
1447 m = ap->next->next->expr;
1449 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1450 && ap->next->name == NULL)
1452 m = d;
1453 d = NULL;
1455 ap->next->expr = NULL;
1456 ap->next->next->expr = m;
1459 if (d != NULL
1460 && (scalar_check (d, 1) == FAILURE
1461 || type_check (d, 1, BT_INTEGER) == FAILURE))
1462 return FAILURE;
1464 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1465 return FAILURE;
1467 return SUCCESS;
1471 /* Similar to minloc/maxloc, the argument list might need to be
1472 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1473 difference is that MINLOC/MAXLOC take an additional KIND argument.
1474 The possibilities are:
1476 Arg #2 Arg #3
1477 NULL NULL
1478 DIM NULL
1479 MASK NULL
1480 NULL MASK minval(array, mask=m)
1481 DIM MASK
1483 I.e. in the case of minval(array,mask), mask will be in the second
1484 position of the argument list and we'll have to fix that up. */
1486 static try
1487 check_reduction (gfc_actual_arglist * ap)
1489 gfc_expr *m, *d;
1491 d = ap->next->expr;
1492 m = ap->next->next->expr;
1494 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1495 && ap->next->name == NULL)
1497 m = d;
1498 d = NULL;
1500 ap->next->expr = NULL;
1501 ap->next->next->expr = m;
1504 if (d != NULL
1505 && (scalar_check (d, 1) == FAILURE
1506 || type_check (d, 1, BT_INTEGER) == FAILURE))
1507 return FAILURE;
1509 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1510 return FAILURE;
1512 return SUCCESS;
1517 gfc_check_minval_maxval (gfc_actual_arglist * ap)
1519 if (int_or_real_check (ap->expr, 0) == FAILURE
1520 || array_check (ap->expr, 0) == FAILURE)
1521 return FAILURE;
1523 return check_reduction (ap);
1528 gfc_check_product_sum (gfc_actual_arglist * ap)
1530 if (numeric_check (ap->expr, 0) == FAILURE
1531 || array_check (ap->expr, 0) == FAILURE)
1532 return FAILURE;
1534 return check_reduction (ap);
1539 gfc_check_merge (gfc_expr * tsource, gfc_expr * fsource, gfc_expr * mask)
1541 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1542 return FAILURE;
1544 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1545 return FAILURE;
1547 return SUCCESS;
1552 gfc_check_nearest (gfc_expr * x, gfc_expr * s)
1554 if (type_check (x, 0, BT_REAL) == FAILURE)
1555 return FAILURE;
1557 if (type_check (s, 1, BT_REAL) == FAILURE)
1558 return FAILURE;
1560 return SUCCESS;
1565 gfc_check_null (gfc_expr * mold)
1567 symbol_attribute attr;
1569 if (mold == NULL)
1570 return SUCCESS;
1572 if (variable_check (mold, 0) == FAILURE)
1573 return FAILURE;
1575 attr = gfc_variable_attr (mold, NULL);
1577 if (!attr.pointer)
1579 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1580 gfc_current_intrinsic_arg[0],
1581 gfc_current_intrinsic, &mold->where);
1582 return FAILURE;
1585 return SUCCESS;
1590 gfc_check_pack (gfc_expr * array, gfc_expr * mask, gfc_expr * vector)
1592 if (array_check (array, 0) == FAILURE)
1593 return FAILURE;
1595 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1596 return FAILURE;
1598 if (mask->rank != 0 && mask->rank != array->rank)
1600 gfc_error ("'%s' argument of '%s' intrinsic at %L must be conformable "
1601 "with '%s' argument", gfc_current_intrinsic_arg[0],
1602 gfc_current_intrinsic, &array->where,
1603 gfc_current_intrinsic_arg[1]);
1604 return FAILURE;
1607 if (vector != NULL)
1609 if (same_type_check (array, 0, vector, 2) == FAILURE)
1610 return FAILURE;
1612 if (rank_check (vector, 2, 1) == FAILURE)
1613 return FAILURE;
1615 /* TODO: More constraints here. */
1618 return SUCCESS;
1623 gfc_check_precision (gfc_expr * x)
1625 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1627 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1628 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1629 gfc_current_intrinsic, &x->where);
1630 return FAILURE;
1633 return SUCCESS;
1638 gfc_check_present (gfc_expr * a)
1640 gfc_symbol *sym;
1642 if (variable_check (a, 0) == FAILURE)
1643 return FAILURE;
1645 sym = a->symtree->n.sym;
1646 if (!sym->attr.dummy)
1648 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1649 "dummy variable", gfc_current_intrinsic_arg[0],
1650 gfc_current_intrinsic, &a->where);
1651 return FAILURE;
1654 if (!sym->attr.optional)
1656 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
1657 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
1658 gfc_current_intrinsic, &a->where);
1659 return FAILURE;
1662 return SUCCESS;
1667 gfc_check_radix (gfc_expr * x)
1669 if (int_or_real_check (x, 0) == FAILURE)
1670 return FAILURE;
1672 return SUCCESS;
1677 gfc_check_range (gfc_expr * x)
1679 if (numeric_check (x, 0) == FAILURE)
1680 return FAILURE;
1682 return SUCCESS;
1686 /* real, float, sngl. */
1688 gfc_check_real (gfc_expr * a, gfc_expr * kind)
1690 if (numeric_check (a, 0) == FAILURE)
1691 return FAILURE;
1693 if (kind_check (kind, 1, BT_REAL) == FAILURE)
1694 return FAILURE;
1696 return SUCCESS;
1701 gfc_check_rename (gfc_expr * path1, gfc_expr * path2)
1703 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1704 return FAILURE;
1706 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1707 return FAILURE;
1709 return SUCCESS;
1714 gfc_check_rename_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1716 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1717 return FAILURE;
1719 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1720 return FAILURE;
1722 if (status == NULL)
1723 return SUCCESS;
1725 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1726 return FAILURE;
1728 if (scalar_check (status, 2) == FAILURE)
1729 return FAILURE;
1731 return SUCCESS;
1736 gfc_check_repeat (gfc_expr * x, gfc_expr * y)
1738 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1739 return FAILURE;
1741 if (scalar_check (x, 0) == FAILURE)
1742 return FAILURE;
1744 if (type_check (y, 0, BT_INTEGER) == FAILURE)
1745 return FAILURE;
1747 if (scalar_check (y, 1) == FAILURE)
1748 return FAILURE;
1750 return SUCCESS;
1755 gfc_check_reshape (gfc_expr * source, gfc_expr * shape,
1756 gfc_expr * pad, gfc_expr * order)
1758 mpz_t size;
1759 int m;
1761 if (array_check (source, 0) == FAILURE)
1762 return FAILURE;
1764 if (rank_check (shape, 1, 1) == FAILURE)
1765 return FAILURE;
1767 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
1768 return FAILURE;
1770 if (gfc_array_size (shape, &size) != SUCCESS)
1772 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
1773 "array of constant size", &shape->where);
1774 return FAILURE;
1777 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
1778 mpz_clear (size);
1780 if (m > 0)
1782 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
1783 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
1784 return FAILURE;
1787 if (pad != NULL)
1789 if (same_type_check (source, 0, pad, 2) == FAILURE)
1790 return FAILURE;
1791 if (array_check (pad, 2) == FAILURE)
1792 return FAILURE;
1795 if (order != NULL && array_check (order, 3) == FAILURE)
1796 return FAILURE;
1798 return SUCCESS;
1803 gfc_check_scale (gfc_expr * x, gfc_expr * i)
1805 if (type_check (x, 0, BT_REAL) == FAILURE)
1806 return FAILURE;
1808 if (type_check (i, 1, BT_INTEGER) == FAILURE)
1809 return FAILURE;
1811 return SUCCESS;
1816 gfc_check_scan (gfc_expr * x, gfc_expr * y, gfc_expr * z)
1818 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1819 return FAILURE;
1821 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
1822 return FAILURE;
1824 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
1825 return FAILURE;
1827 if (same_type_check (x, 0, y, 1) == FAILURE)
1828 return FAILURE;
1830 return SUCCESS;
1835 gfc_check_secnds (gfc_expr * r)
1838 if (type_check (r, 0, BT_REAL) == FAILURE)
1839 return FAILURE;
1841 if (kind_value_check (r, 0, 4) == FAILURE)
1842 return FAILURE;
1844 if (scalar_check (r, 0) == FAILURE)
1845 return FAILURE;
1847 return SUCCESS;
1852 gfc_check_selected_int_kind (gfc_expr * r)
1855 if (type_check (r, 0, BT_INTEGER) == FAILURE)
1856 return FAILURE;
1858 if (scalar_check (r, 0) == FAILURE)
1859 return FAILURE;
1861 return SUCCESS;
1866 gfc_check_selected_real_kind (gfc_expr * p, gfc_expr * r)
1868 if (p == NULL && r == NULL)
1870 gfc_error ("Missing arguments to %s intrinsic at %L",
1871 gfc_current_intrinsic, gfc_current_intrinsic_where);
1873 return FAILURE;
1876 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
1877 return FAILURE;
1879 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
1880 return FAILURE;
1882 return SUCCESS;
1887 gfc_check_set_exponent (gfc_expr * x, gfc_expr * i)
1889 if (type_check (x, 0, BT_REAL) == FAILURE)
1890 return FAILURE;
1892 if (type_check (i, 1, BT_INTEGER) == FAILURE)
1893 return FAILURE;
1895 return SUCCESS;
1900 gfc_check_shape (gfc_expr * source)
1902 gfc_array_ref *ar;
1904 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
1905 return SUCCESS;
1907 ar = gfc_find_array_ref (source);
1909 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
1911 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
1912 "an assumed size array", &source->where);
1913 return FAILURE;
1916 return SUCCESS;
1921 gfc_check_sign (gfc_expr * a, gfc_expr * b)
1923 if (int_or_real_check (a, 0) == FAILURE)
1924 return FAILURE;
1926 if (same_type_check (a, 0, b, 1) == FAILURE)
1927 return FAILURE;
1929 return SUCCESS;
1934 gfc_check_size (gfc_expr * array, gfc_expr * dim)
1936 if (array_check (array, 0) == FAILURE)
1937 return FAILURE;
1939 if (dim != NULL)
1941 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
1942 return FAILURE;
1944 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
1945 return FAILURE;
1947 if (dim_rank_check (dim, array, 0) == FAILURE)
1948 return FAILURE;
1951 return SUCCESS;
1956 gfc_check_sleep_sub (gfc_expr * seconds)
1958 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
1959 return FAILURE;
1961 if (scalar_check (seconds, 0) == FAILURE)
1962 return FAILURE;
1964 return SUCCESS;
1969 gfc_check_spread (gfc_expr * source, gfc_expr * dim, gfc_expr * ncopies)
1971 if (source->rank >= GFC_MAX_DIMENSIONS)
1973 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
1974 "than rank %d", gfc_current_intrinsic_arg[0],
1975 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
1977 return FAILURE;
1980 if (dim_check (dim, 1, 0) == FAILURE)
1981 return FAILURE;
1983 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
1984 return FAILURE;
1986 if (scalar_check (ncopies, 2) == FAILURE)
1987 return FAILURE;
1989 return SUCCESS;
1994 gfc_check_fstat (gfc_expr * unit, gfc_expr * array)
1996 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1997 return FAILURE;
1999 if (scalar_check (unit, 0) == FAILURE)
2000 return FAILURE;
2002 if (type_check (array, 1, BT_INTEGER) == FAILURE
2003 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2004 return FAILURE;
2006 if (array_check (array, 1) == FAILURE)
2007 return FAILURE;
2009 return SUCCESS;
2014 gfc_check_fstat_sub (gfc_expr * unit, gfc_expr * array, gfc_expr * status)
2016 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2017 return FAILURE;
2019 if (scalar_check (unit, 0) == FAILURE)
2020 return FAILURE;
2022 if (type_check (array, 1, BT_INTEGER) == FAILURE
2023 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2024 return FAILURE;
2026 if (array_check (array, 1) == FAILURE)
2027 return FAILURE;
2029 if (status == NULL)
2030 return SUCCESS;
2032 if (type_check (status, 2, BT_INTEGER) == FAILURE
2033 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2034 return FAILURE;
2036 if (scalar_check (status, 2) == FAILURE)
2037 return FAILURE;
2039 return SUCCESS;
2044 gfc_check_stat (gfc_expr * name, gfc_expr * array)
2046 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2047 return FAILURE;
2049 if (type_check (array, 1, BT_INTEGER) == FAILURE
2050 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2051 return FAILURE;
2053 if (array_check (array, 1) == FAILURE)
2054 return FAILURE;
2056 return SUCCESS;
2061 gfc_check_stat_sub (gfc_expr * name, gfc_expr * array, gfc_expr * status)
2063 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2064 return FAILURE;
2066 if (type_check (array, 1, BT_INTEGER) == FAILURE
2067 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2068 return FAILURE;
2070 if (array_check (array, 1) == FAILURE)
2071 return FAILURE;
2073 if (status == NULL)
2074 return SUCCESS;
2076 if (type_check (status, 2, BT_INTEGER) == FAILURE
2077 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2078 return FAILURE;
2080 if (scalar_check (status, 2) == FAILURE)
2081 return FAILURE;
2083 return SUCCESS;
2088 gfc_check_transfer (gfc_expr * source ATTRIBUTE_UNUSED,
2089 gfc_expr * mold ATTRIBUTE_UNUSED,
2090 gfc_expr * size)
2092 if (size != NULL)
2094 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2095 return FAILURE;
2097 if (scalar_check (size, 2) == FAILURE)
2098 return FAILURE;
2100 if (nonoptional_check (size, 2) == FAILURE)
2101 return FAILURE;
2104 return SUCCESS;
2109 gfc_check_transpose (gfc_expr * matrix)
2111 if (rank_check (matrix, 0, 2) == FAILURE)
2112 return FAILURE;
2114 return SUCCESS;
2119 gfc_check_ubound (gfc_expr * array, gfc_expr * dim)
2121 if (array_check (array, 0) == FAILURE)
2122 return FAILURE;
2124 if (dim != NULL)
2126 if (dim_check (dim, 1, 1) == FAILURE)
2127 return FAILURE;
2129 if (dim_rank_check (dim, array, 0) == FAILURE)
2130 return FAILURE;
2133 return SUCCESS;
2138 gfc_check_unpack (gfc_expr * vector, gfc_expr * mask, gfc_expr * field)
2140 if (rank_check (vector, 0, 1) == FAILURE)
2141 return FAILURE;
2143 if (array_check (mask, 1) == FAILURE)
2144 return FAILURE;
2146 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2147 return FAILURE;
2149 if (same_type_check (vector, 0, field, 2) == FAILURE)
2150 return FAILURE;
2152 return SUCCESS;
2157 gfc_check_verify (gfc_expr * x, gfc_expr * y, gfc_expr * z)
2159 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2160 return FAILURE;
2162 if (same_type_check (x, 0, y, 1) == FAILURE)
2163 return FAILURE;
2165 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2166 return FAILURE;
2168 return SUCCESS;
2173 gfc_check_trim (gfc_expr * x)
2175 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2176 return FAILURE;
2178 if (scalar_check (x, 0) == FAILURE)
2179 return FAILURE;
2181 return SUCCESS;
2185 /* Common check function for the half a dozen intrinsics that have a
2186 single real argument. */
2189 gfc_check_x (gfc_expr * x)
2191 if (type_check (x, 0, BT_REAL) == FAILURE)
2192 return FAILURE;
2194 return SUCCESS;
2198 /************* Check functions for intrinsic subroutines *************/
2201 gfc_check_cpu_time (gfc_expr * time)
2203 if (scalar_check (time, 0) == FAILURE)
2204 return FAILURE;
2206 if (type_check (time, 0, BT_REAL) == FAILURE)
2207 return FAILURE;
2209 if (variable_check (time, 0) == FAILURE)
2210 return FAILURE;
2212 return SUCCESS;
2217 gfc_check_date_and_time (gfc_expr * date, gfc_expr * time,
2218 gfc_expr * zone, gfc_expr * values)
2220 if (date != NULL)
2222 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2223 return FAILURE;
2224 if (scalar_check (date, 0) == FAILURE)
2225 return FAILURE;
2226 if (variable_check (date, 0) == FAILURE)
2227 return FAILURE;
2230 if (time != NULL)
2232 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2233 return FAILURE;
2234 if (scalar_check (time, 1) == FAILURE)
2235 return FAILURE;
2236 if (variable_check (time, 1) == FAILURE)
2237 return FAILURE;
2240 if (zone != NULL)
2242 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2243 return FAILURE;
2244 if (scalar_check (zone, 2) == FAILURE)
2245 return FAILURE;
2246 if (variable_check (zone, 2) == FAILURE)
2247 return FAILURE;
2250 if (values != NULL)
2252 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2253 return FAILURE;
2254 if (array_check (values, 3) == FAILURE)
2255 return FAILURE;
2256 if (rank_check (values, 3, 1) == FAILURE)
2257 return FAILURE;
2258 if (variable_check (values, 3) == FAILURE)
2259 return FAILURE;
2262 return SUCCESS;
2267 gfc_check_mvbits (gfc_expr * from, gfc_expr * frompos, gfc_expr * len,
2268 gfc_expr * to, gfc_expr * topos)
2270 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2271 return FAILURE;
2273 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2274 return FAILURE;
2276 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2277 return FAILURE;
2279 if (same_type_check (from, 0, to, 3) == FAILURE)
2280 return FAILURE;
2282 if (variable_check (to, 3) == FAILURE)
2283 return FAILURE;
2285 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2286 return FAILURE;
2288 return SUCCESS;
2293 gfc_check_random_number (gfc_expr * harvest)
2295 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2296 return FAILURE;
2298 if (variable_check (harvest, 0) == FAILURE)
2299 return FAILURE;
2301 return SUCCESS;
2306 gfc_check_random_seed (gfc_expr * size, gfc_expr * put, gfc_expr * get)
2308 if (size != NULL)
2310 if (scalar_check (size, 0) == FAILURE)
2311 return FAILURE;
2313 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2314 return FAILURE;
2316 if (variable_check (size, 0) == FAILURE)
2317 return FAILURE;
2319 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2320 return FAILURE;
2323 if (put != NULL)
2326 if (size != NULL)
2327 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2328 &put->where);
2330 if (array_check (put, 1) == FAILURE)
2331 return FAILURE;
2333 if (rank_check (put, 1, 1) == FAILURE)
2334 return FAILURE;
2336 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2337 return FAILURE;
2339 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2340 return FAILURE;
2343 if (get != NULL)
2346 if (size != NULL || put != NULL)
2347 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2348 &get->where);
2350 if (array_check (get, 2) == FAILURE)
2351 return FAILURE;
2353 if (rank_check (get, 2, 1) == FAILURE)
2354 return FAILURE;
2356 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2357 return FAILURE;
2359 if (variable_check (get, 2) == FAILURE)
2360 return FAILURE;
2362 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2363 return FAILURE;
2366 return SUCCESS;
2370 gfc_check_second_sub (gfc_expr * time)
2372 if (scalar_check (time, 0) == FAILURE)
2373 return FAILURE;
2375 if (type_check (time, 0, BT_REAL) == FAILURE)
2376 return FAILURE;
2378 if (kind_value_check(time, 0, 4) == FAILURE)
2379 return FAILURE;
2381 return SUCCESS;
2385 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2386 count, count_rate, and count_max are all optional arguments */
2389 gfc_check_system_clock (gfc_expr * count, gfc_expr * count_rate,
2390 gfc_expr * count_max)
2392 if (count != NULL)
2394 if (scalar_check (count, 0) == FAILURE)
2395 return FAILURE;
2397 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2398 return FAILURE;
2400 if (variable_check (count, 0) == FAILURE)
2401 return FAILURE;
2404 if (count_rate != NULL)
2406 if (scalar_check (count_rate, 1) == FAILURE)
2407 return FAILURE;
2409 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2410 return FAILURE;
2412 if (variable_check (count_rate, 1) == FAILURE)
2413 return FAILURE;
2415 if (count != NULL
2416 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2417 return FAILURE;
2421 if (count_max != NULL)
2423 if (scalar_check (count_max, 2) == FAILURE)
2424 return FAILURE;
2426 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2427 return FAILURE;
2429 if (variable_check (count_max, 2) == FAILURE)
2430 return FAILURE;
2432 if (count != NULL
2433 && same_type_check (count, 0, count_max, 2) == FAILURE)
2434 return FAILURE;
2436 if (count_rate != NULL
2437 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2438 return FAILURE;
2441 return SUCCESS;
2445 gfc_check_irand (gfc_expr * x)
2447 if (x == NULL)
2448 return SUCCESS;
2450 if (scalar_check (x, 0) == FAILURE)
2451 return FAILURE;
2453 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2454 return FAILURE;
2456 if (kind_value_check(x, 0, 4) == FAILURE)
2457 return FAILURE;
2459 return SUCCESS;
2464 gfc_check_alarm_sub (gfc_expr * seconds, gfc_expr * handler, gfc_expr * status)
2466 if (scalar_check (seconds, 0) == FAILURE)
2467 return FAILURE;
2469 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2470 return FAILURE;
2472 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2474 gfc_error (
2475 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
2476 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
2477 return FAILURE;
2480 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2481 return FAILURE;
2483 if (status == NULL)
2484 return SUCCESS;
2486 if (scalar_check (status, 2) == FAILURE)
2487 return FAILURE;
2489 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2490 return FAILURE;
2492 return SUCCESS;
2497 gfc_check_rand (gfc_expr * x)
2499 if (x == NULL)
2500 return SUCCESS;
2502 if (scalar_check (x, 0) == FAILURE)
2503 return FAILURE;
2505 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2506 return FAILURE;
2508 if (kind_value_check(x, 0, 4) == FAILURE)
2509 return FAILURE;
2511 return SUCCESS;
2515 gfc_check_srand (gfc_expr * x)
2517 if (scalar_check (x, 0) == FAILURE)
2518 return FAILURE;
2520 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2521 return FAILURE;
2523 if (kind_value_check(x, 0, 4) == FAILURE)
2524 return FAILURE;
2526 return SUCCESS;
2530 gfc_check_etime (gfc_expr * x)
2532 if (array_check (x, 0) == FAILURE)
2533 return FAILURE;
2535 if (rank_check (x, 0, 1) == FAILURE)
2536 return FAILURE;
2538 if (variable_check (x, 0) == FAILURE)
2539 return FAILURE;
2541 if (type_check (x, 0, BT_REAL) == FAILURE)
2542 return FAILURE;
2544 if (kind_value_check(x, 0, 4) == FAILURE)
2545 return FAILURE;
2547 return SUCCESS;
2551 gfc_check_etime_sub (gfc_expr * values, gfc_expr * time)
2553 if (array_check (values, 0) == FAILURE)
2554 return FAILURE;
2556 if (rank_check (values, 0, 1) == FAILURE)
2557 return FAILURE;
2559 if (variable_check (values, 0) == FAILURE)
2560 return FAILURE;
2562 if (type_check (values, 0, BT_REAL) == FAILURE)
2563 return FAILURE;
2565 if (kind_value_check(values, 0, 4) == FAILURE)
2566 return FAILURE;
2568 if (scalar_check (time, 1) == FAILURE)
2569 return FAILURE;
2571 if (type_check (time, 1, BT_REAL) == FAILURE)
2572 return FAILURE;
2574 if (kind_value_check(time, 1, 4) == FAILURE)
2575 return FAILURE;
2577 return SUCCESS;
2582 gfc_check_gerror (gfc_expr * msg)
2584 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
2585 return FAILURE;
2587 return SUCCESS;
2592 gfc_check_getcwd_sub (gfc_expr * cwd, gfc_expr * status)
2594 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
2595 return FAILURE;
2597 if (status == NULL)
2598 return SUCCESS;
2600 if (scalar_check (status, 1) == FAILURE)
2601 return FAILURE;
2603 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2604 return FAILURE;
2606 return SUCCESS;
2611 gfc_check_getlog (gfc_expr * msg)
2613 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
2614 return FAILURE;
2616 return SUCCESS;
2621 gfc_check_exit (gfc_expr * status)
2623 if (status == NULL)
2624 return SUCCESS;
2626 if (type_check (status, 0, BT_INTEGER) == FAILURE)
2627 return FAILURE;
2629 if (scalar_check (status, 0) == FAILURE)
2630 return FAILURE;
2632 return SUCCESS;
2637 gfc_check_flush (gfc_expr * unit)
2639 if (unit == NULL)
2640 return SUCCESS;
2642 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2643 return FAILURE;
2645 if (scalar_check (unit, 0) == FAILURE)
2646 return FAILURE;
2648 return SUCCESS;
2653 gfc_check_free (gfc_expr * i)
2655 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2656 return FAILURE;
2658 if (scalar_check (i, 0) == FAILURE)
2659 return FAILURE;
2661 return SUCCESS;
2666 gfc_check_hostnm (gfc_expr * name)
2668 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2669 return FAILURE;
2671 return SUCCESS;
2676 gfc_check_hostnm_sub (gfc_expr * name, gfc_expr * status)
2678 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2679 return FAILURE;
2681 if (status == NULL)
2682 return SUCCESS;
2684 if (scalar_check (status, 1) == FAILURE)
2685 return FAILURE;
2687 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2688 return FAILURE;
2690 return SUCCESS;
2695 gfc_check_ttynam_sub (gfc_expr * unit, gfc_expr * name)
2697 if (scalar_check (unit, 0) == FAILURE)
2698 return FAILURE;
2700 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2701 return FAILURE;
2703 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
2704 return FAILURE;
2706 return SUCCESS;
2711 gfc_check_isatty (gfc_expr * unit)
2713 if (unit == NULL)
2714 return FAILURE;
2716 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2717 return FAILURE;
2719 if (scalar_check (unit, 0) == FAILURE)
2720 return FAILURE;
2722 return SUCCESS;
2727 gfc_check_perror (gfc_expr * string)
2729 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
2730 return FAILURE;
2732 return SUCCESS;
2737 gfc_check_umask (gfc_expr * mask)
2739 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
2740 return FAILURE;
2742 if (scalar_check (mask, 0) == FAILURE)
2743 return FAILURE;
2745 return SUCCESS;
2750 gfc_check_umask_sub (gfc_expr * mask, gfc_expr * old)
2752 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
2753 return FAILURE;
2755 if (scalar_check (mask, 0) == FAILURE)
2756 return FAILURE;
2758 if (old == NULL)
2759 return SUCCESS;
2761 if (scalar_check (old, 1) == FAILURE)
2762 return FAILURE;
2764 if (type_check (old, 1, BT_INTEGER) == FAILURE)
2765 return FAILURE;
2767 return SUCCESS;
2772 gfc_check_unlink (gfc_expr * name)
2774 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2775 return FAILURE;
2777 return SUCCESS;
2782 gfc_check_unlink_sub (gfc_expr * name, gfc_expr * status)
2784 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2785 return FAILURE;
2787 if (status == NULL)
2788 return SUCCESS;
2790 if (scalar_check (status, 1) == FAILURE)
2791 return FAILURE;
2793 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2794 return FAILURE;
2796 return SUCCESS;
2801 gfc_check_signal (gfc_expr * number, gfc_expr * handler)
2803 if (scalar_check (number, 0) == FAILURE)
2804 return FAILURE;
2806 if (type_check (number, 0, BT_INTEGER) == FAILURE)
2807 return FAILURE;
2809 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2811 gfc_error (
2812 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
2813 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
2814 return FAILURE;
2817 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2818 return FAILURE;
2820 return SUCCESS;
2825 gfc_check_signal_sub (gfc_expr * number, gfc_expr * handler, gfc_expr * status)
2827 if (scalar_check (number, 0) == FAILURE)
2828 return FAILURE;
2830 if (type_check (number, 0, BT_INTEGER) == FAILURE)
2831 return FAILURE;
2833 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2835 gfc_error (
2836 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
2837 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
2838 return FAILURE;
2841 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2842 return FAILURE;
2844 if (status == NULL)
2845 return SUCCESS;
2847 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2848 return FAILURE;
2850 if (scalar_check (status, 2) == FAILURE)
2851 return FAILURE;
2853 return SUCCESS;
2858 gfc_check_system_sub (gfc_expr * cmd, gfc_expr * status)
2860 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
2861 return FAILURE;
2863 if (scalar_check (status, 1) == FAILURE)
2864 return FAILURE;
2866 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2867 return FAILURE;
2869 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
2870 return FAILURE;
2872 return SUCCESS;