* config/alpha/alpha.c, config/alpha/alpha.md,
[official-gcc.git] / gcc / fortran / check.c
blob6e4d798f6d1ab820d1ea8082c6559ea12bcc989e
1 /* Check functions
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
24 /* These functions check to see if an argument list is compatible with
25 a particular intrinsic function or subroutine. Presence of
26 required arguments has already been established, the argument list
27 has been sorted into the right order and has NULL arguments in the
28 correct places for missing optional arguments. */
30 #include "config.h"
31 #include "system.h"
32 #include "flags.h"
33 #include "gfortran.h"
34 #include "intrinsic.h"
37 /* Check the type of an expression. */
39 static try
40 type_check (gfc_expr *e, int n, bt type)
42 if (e->ts.type == type)
43 return SUCCESS;
45 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
46 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where,
47 gfc_basic_typename (type));
49 return FAILURE;
53 /* Check that the expression is a numeric type. */
55 static try
56 numeric_check (gfc_expr *e, int n)
58 if (gfc_numeric_ts (&e->ts))
59 return SUCCESS;
61 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
62 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
64 return FAILURE;
68 /* Check that an expression is integer or real. */
70 static try
71 int_or_real_check (gfc_expr *e, int n)
73 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
75 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
76 "or REAL", gfc_current_intrinsic_arg[n],
77 gfc_current_intrinsic, &e->where);
78 return FAILURE;
81 return SUCCESS;
85 /* Check that an expression is real or complex. */
87 static try
88 real_or_complex_check (gfc_expr *e, int n)
90 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
92 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
93 "or COMPLEX", gfc_current_intrinsic_arg[n],
94 gfc_current_intrinsic, &e->where);
95 return FAILURE;
98 return SUCCESS;
102 /* Check that the expression is an optional constant integer
103 and that it specifies a valid kind for that type. */
105 static try
106 kind_check (gfc_expr *k, int n, bt type)
108 int kind;
110 if (k == NULL)
111 return SUCCESS;
113 if (type_check (k, n, BT_INTEGER) == FAILURE)
114 return FAILURE;
116 if (k->expr_type != EXPR_CONSTANT)
118 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
119 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
120 &k->where);
121 return FAILURE;
124 if (gfc_extract_int (k, &kind) != NULL
125 || gfc_validate_kind (type, kind, true) < 0)
127 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
128 &k->where);
129 return FAILURE;
132 return SUCCESS;
136 /* Make sure the expression is a double precision real. */
138 static try
139 double_check (gfc_expr *d, int n)
141 if (type_check (d, n, BT_REAL) == FAILURE)
142 return FAILURE;
144 if (d->ts.kind != gfc_default_double_kind)
146 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
147 "precision", gfc_current_intrinsic_arg[n],
148 gfc_current_intrinsic, &d->where);
149 return FAILURE;
152 return SUCCESS;
156 /* Make sure the expression is a logical array. */
158 static try
159 logical_array_check (gfc_expr *array, int n)
161 if (array->ts.type != BT_LOGICAL || array->rank == 0)
163 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
164 "array", gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
165 &array->where);
166 return FAILURE;
169 return SUCCESS;
173 /* Make sure an expression is an array. */
175 static try
176 array_check (gfc_expr *e, int n)
178 if (e->rank != 0)
179 return SUCCESS;
181 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
182 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
184 return FAILURE;
188 /* Make sure an expression is a scalar. */
190 static try
191 scalar_check (gfc_expr *e, int n)
193 if (e->rank == 0)
194 return SUCCESS;
196 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
197 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
199 return FAILURE;
203 /* Make sure two expressions have the same type. */
205 static try
206 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
208 if (gfc_compare_types (&e->ts, &f->ts))
209 return SUCCESS;
211 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
212 "and kind as '%s'", gfc_current_intrinsic_arg[m],
213 gfc_current_intrinsic, &f->where, gfc_current_intrinsic_arg[n]);
215 return FAILURE;
219 /* Make sure that an expression has a certain (nonzero) rank. */
221 static try
222 rank_check (gfc_expr *e, int n, int rank)
224 if (e->rank == rank)
225 return SUCCESS;
227 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
228 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
229 &e->where, rank);
231 return FAILURE;
235 /* Make sure a variable expression is not an optional dummy argument. */
237 static try
238 nonoptional_check (gfc_expr *e, int n)
240 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
242 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
243 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
244 &e->where);
247 /* TODO: Recursive check on nonoptional variables? */
249 return SUCCESS;
253 /* Check that an expression has a particular kind. */
255 static try
256 kind_value_check (gfc_expr *e, int n, int k)
258 if (e->ts.kind == k)
259 return SUCCESS;
261 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
262 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
263 &e->where, k);
265 return FAILURE;
269 /* Make sure an expression is a variable. */
271 static try
272 variable_check (gfc_expr *e, int n)
274 if ((e->expr_type == EXPR_VARIABLE
275 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
276 || (e->expr_type == EXPR_FUNCTION
277 && e->symtree->n.sym->result == e->symtree->n.sym))
278 return SUCCESS;
280 if (e->expr_type == EXPR_VARIABLE
281 && e->symtree->n.sym->attr.intent == INTENT_IN)
283 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
284 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
285 &e->where);
286 return FAILURE;
289 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
290 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
292 return FAILURE;
296 /* Check the common DIM parameter for correctness. */
298 static try
299 dim_check (gfc_expr *dim, int n, int optional)
301 if (optional && dim == NULL)
302 return SUCCESS;
304 if (dim == NULL)
306 gfc_error ("Missing DIM parameter in intrinsic '%s' at %L",
307 gfc_current_intrinsic, gfc_current_intrinsic_where);
308 return FAILURE;
311 if (type_check (dim, n, BT_INTEGER) == FAILURE)
312 return FAILURE;
314 if (scalar_check (dim, n) == FAILURE)
315 return FAILURE;
317 if (nonoptional_check (dim, n) == FAILURE)
318 return FAILURE;
320 return SUCCESS;
324 /* If a DIM parameter is a constant, make sure that it is greater than
325 zero and less than or equal to the rank of the given array. If
326 allow_assumed is zero then dim must be less than the rank of the array
327 for assumed size arrays. */
329 static try
330 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
332 gfc_array_ref *ar;
333 int rank;
335 if (dim->expr_type != EXPR_CONSTANT || array->expr_type != EXPR_VARIABLE)
336 return SUCCESS;
338 ar = gfc_find_array_ref (array);
339 rank = array->rank;
340 if (ar->as->type == AS_ASSUMED_SIZE && !allow_assumed)
341 rank--;
343 if (mpz_cmp_ui (dim->value.integer, 1) < 0
344 || mpz_cmp_ui (dim->value.integer, rank) > 0)
346 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
347 "dimension index", gfc_current_intrinsic, &dim->where);
349 return FAILURE;
352 return SUCCESS;
356 /* Compare the size of a along dimension ai with the size of b along
357 dimension bi, returning 0 if they are known not to be identical,
358 and 1 if they are identical, or if this cannot be determined. */
360 static int
361 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
363 mpz_t a_size, b_size;
364 int ret;
366 gcc_assert (a->rank > ai);
367 gcc_assert (b->rank > bi);
369 ret = 1;
371 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
373 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
375 if (mpz_cmp (a_size, b_size) != 0)
376 ret = 0;
378 mpz_clear (b_size);
380 mpz_clear (a_size);
382 return ret;
386 /* Error return for transformational intrinsics not allowed in
387 initialization expressions. */
389 static try
390 non_init_transformational (void)
392 gfc_error ("transformational intrinsic '%s' at %L is not permitted "
393 "in an initialization expression", gfc_current_intrinsic,
394 gfc_current_intrinsic_where);
395 return FAILURE;
398 /***** Check functions *****/
400 /* Check subroutine suitable for intrinsics taking a real argument and
401 a kind argument for the result. */
403 static try
404 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
406 if (type_check (a, 0, BT_REAL) == FAILURE)
407 return FAILURE;
408 if (kind_check (kind, 1, type) == FAILURE)
409 return FAILURE;
411 return SUCCESS;
415 /* Check subroutine suitable for ceiling, floor and nint. */
418 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
420 return check_a_kind (a, kind, BT_INTEGER);
424 /* Check subroutine suitable for aint, anint. */
427 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
429 return check_a_kind (a, kind, BT_REAL);
434 gfc_check_abs (gfc_expr *a)
436 if (numeric_check (a, 0) == FAILURE)
437 return FAILURE;
439 return SUCCESS;
444 gfc_check_achar (gfc_expr *a)
446 if (type_check (a, 0, BT_INTEGER) == FAILURE)
447 return FAILURE;
449 return SUCCESS;
454 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
456 if (type_check (name, 0, BT_CHARACTER) == FAILURE
457 || scalar_check (name, 0) == FAILURE)
458 return FAILURE;
460 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
461 || scalar_check (mode, 1) == FAILURE)
462 return FAILURE;
464 return SUCCESS;
469 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
471 if (logical_array_check (mask, 0) == FAILURE)
472 return FAILURE;
474 if (dim_check (dim, 1, 1) == FAILURE)
475 return FAILURE;
477 if (gfc_init_expr)
478 return non_init_transformational ();
480 return SUCCESS;
485 gfc_check_allocated (gfc_expr *array)
487 symbol_attribute attr;
489 if (variable_check (array, 0) == FAILURE)
490 return FAILURE;
492 if (array_check (array, 0) == FAILURE)
493 return FAILURE;
495 attr = gfc_variable_attr (array, NULL);
496 if (!attr.allocatable)
498 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
499 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
500 &array->where);
501 return FAILURE;
504 return SUCCESS;
508 /* Common check function where the first argument must be real or
509 integer and the second argument must be the same as the first. */
512 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
514 if (int_or_real_check (a, 0) == FAILURE)
515 return FAILURE;
517 if (a->ts.type != p->ts.type)
519 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
520 "have the same type", gfc_current_intrinsic_arg[0],
521 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
522 &p->where);
523 return FAILURE;
526 if (a->ts.kind != p->ts.kind)
528 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
529 &p->where) == FAILURE)
530 return FAILURE;
533 return SUCCESS;
538 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
540 symbol_attribute attr;
541 int i;
542 try t;
543 locus *where;
545 where = &pointer->where;
547 if (pointer->expr_type == EXPR_VARIABLE)
548 attr = gfc_variable_attr (pointer, NULL);
549 else if (pointer->expr_type == EXPR_FUNCTION)
550 attr = pointer->symtree->n.sym->attr;
551 else if (pointer->expr_type == EXPR_NULL)
552 goto null_arg;
553 else
554 gcc_assert (0); /* Pointer must be a variable or a function. */
556 if (!attr.pointer)
558 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
559 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
560 &pointer->where);
561 return FAILURE;
564 /* Target argument is optional. */
565 if (target == NULL)
566 return SUCCESS;
568 where = &target->where;
569 if (target->expr_type == EXPR_NULL)
570 goto null_arg;
572 if (target->expr_type == EXPR_VARIABLE)
573 attr = gfc_variable_attr (target, NULL);
574 else if (target->expr_type == EXPR_FUNCTION)
575 attr = target->symtree->n.sym->attr;
576 else
578 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
579 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
580 gfc_current_intrinsic, &target->where);
581 return FAILURE;
584 if (!attr.pointer && !attr.target)
586 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
587 "or a TARGET", gfc_current_intrinsic_arg[1],
588 gfc_current_intrinsic, &target->where);
589 return FAILURE;
592 t = SUCCESS;
593 if (same_type_check (pointer, 0, target, 1) == FAILURE)
594 t = FAILURE;
595 if (rank_check (target, 0, pointer->rank) == FAILURE)
596 t = FAILURE;
597 if (target->rank > 0)
599 for (i = 0; i < target->rank; i++)
600 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
602 gfc_error ("Array section with a vector subscript at %L shall not "
603 "be the target of a pointer",
604 &target->where);
605 t = FAILURE;
606 break;
609 return t;
611 null_arg:
613 gfc_error ("NULL pointer at %L is not permitted as actual argument "
614 "of '%s' intrinsic function", where, gfc_current_intrinsic);
615 return FAILURE;
621 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
623 if (type_check (y, 0, BT_REAL) == FAILURE)
624 return FAILURE;
625 if (same_type_check (y, 0, x, 1) == FAILURE)
626 return FAILURE;
628 return SUCCESS;
632 /* BESJN and BESYN functions. */
635 gfc_check_besn (gfc_expr *n, gfc_expr *x)
637 if (scalar_check (n, 0) == FAILURE)
638 return FAILURE;
640 if (type_check (n, 0, BT_INTEGER) == FAILURE)
641 return FAILURE;
643 if (scalar_check (x, 1) == FAILURE)
644 return FAILURE;
646 if (type_check (x, 1, BT_REAL) == FAILURE)
647 return FAILURE;
649 return SUCCESS;
654 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
656 if (type_check (i, 0, BT_INTEGER) == FAILURE)
657 return FAILURE;
658 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
659 return FAILURE;
661 return SUCCESS;
666 gfc_check_char (gfc_expr *i, gfc_expr *kind)
668 if (type_check (i, 0, BT_INTEGER) == FAILURE)
669 return FAILURE;
670 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
671 return FAILURE;
673 return SUCCESS;
678 gfc_check_chdir (gfc_expr *dir)
680 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
681 return FAILURE;
683 return SUCCESS;
688 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
690 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
691 return FAILURE;
693 if (status == NULL)
694 return SUCCESS;
696 if (type_check (status, 1, BT_INTEGER) == FAILURE)
697 return FAILURE;
699 if (scalar_check (status, 1) == FAILURE)
700 return FAILURE;
702 return SUCCESS;
707 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
709 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
710 return FAILURE;
712 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
713 return FAILURE;
715 return SUCCESS;
720 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
722 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
723 return FAILURE;
725 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
726 return FAILURE;
728 if (status == NULL)
729 return SUCCESS;
731 if (type_check (status, 2, BT_INTEGER) == FAILURE)
732 return FAILURE;
734 if (scalar_check (status, 2) == FAILURE)
735 return FAILURE;
737 return SUCCESS;
742 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
744 if (numeric_check (x, 0) == FAILURE)
745 return FAILURE;
747 if (y != NULL)
749 if (numeric_check (y, 1) == FAILURE)
750 return FAILURE;
752 if (x->ts.type == BT_COMPLEX)
754 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
755 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
756 gfc_current_intrinsic, &y->where);
757 return FAILURE;
761 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
762 return FAILURE;
764 return SUCCESS;
769 gfc_check_complex (gfc_expr *x, gfc_expr *y)
771 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
773 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
774 "or REAL", gfc_current_intrinsic_arg[0],
775 gfc_current_intrinsic, &x->where);
776 return FAILURE;
778 if (scalar_check (x, 0) == FAILURE)
779 return FAILURE;
781 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
783 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
784 "or REAL", gfc_current_intrinsic_arg[1],
785 gfc_current_intrinsic, &y->where);
786 return FAILURE;
788 if (scalar_check (y, 1) == FAILURE)
789 return FAILURE;
791 return SUCCESS;
796 gfc_check_count (gfc_expr *mask, gfc_expr *dim)
798 if (logical_array_check (mask, 0) == FAILURE)
799 return FAILURE;
800 if (dim_check (dim, 1, 1) == FAILURE)
801 return FAILURE;
803 if (gfc_init_expr)
804 return non_init_transformational ();
806 return SUCCESS;
811 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
813 if (array_check (array, 0) == FAILURE)
814 return FAILURE;
816 if (array->rank == 1)
818 if (scalar_check (shift, 1) == FAILURE)
819 return FAILURE;
821 else
823 /* TODO: more requirements on shift parameter. */
826 if (dim_check (dim, 2, 1) == FAILURE)
827 return FAILURE;
829 if (gfc_init_expr)
830 return non_init_transformational ();
832 return SUCCESS;
837 gfc_check_ctime (gfc_expr *time)
839 if (scalar_check (time, 0) == FAILURE)
840 return FAILURE;
842 if (type_check (time, 0, BT_INTEGER) == FAILURE)
843 return FAILURE;
845 return SUCCESS;
850 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
852 if (numeric_check (x, 0) == FAILURE)
853 return FAILURE;
855 if (y != NULL)
857 if (numeric_check (y, 1) == FAILURE)
858 return FAILURE;
860 if (x->ts.type == BT_COMPLEX)
862 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
863 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
864 gfc_current_intrinsic, &y->where);
865 return FAILURE;
869 return SUCCESS;
874 gfc_check_dble (gfc_expr *x)
876 if (numeric_check (x, 0) == FAILURE)
877 return FAILURE;
879 return SUCCESS;
884 gfc_check_digits (gfc_expr *x)
886 if (int_or_real_check (x, 0) == FAILURE)
887 return FAILURE;
889 return SUCCESS;
894 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
896 switch (vector_a->ts.type)
898 case BT_LOGICAL:
899 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
900 return FAILURE;
901 break;
903 case BT_INTEGER:
904 case BT_REAL:
905 case BT_COMPLEX:
906 if (numeric_check (vector_b, 1) == FAILURE)
907 return FAILURE;
908 break;
910 default:
911 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
912 "or LOGICAL", gfc_current_intrinsic_arg[0],
913 gfc_current_intrinsic, &vector_a->where);
914 return FAILURE;
917 if (rank_check (vector_a, 0, 1) == FAILURE)
918 return FAILURE;
920 if (rank_check (vector_b, 1, 1) == FAILURE)
921 return FAILURE;
923 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
925 gfc_error ("different shape for arguments '%s' and '%s' at %L for "
926 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
927 gfc_current_intrinsic_arg[1], &vector_a->where);
928 return FAILURE;
931 if (gfc_init_expr)
932 return non_init_transformational ();
934 return SUCCESS;
939 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
940 gfc_expr *dim)
942 if (array_check (array, 0) == FAILURE)
943 return FAILURE;
945 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
946 return FAILURE;
948 if (array->rank == 1)
950 if (scalar_check (shift, 2) == FAILURE)
951 return FAILURE;
953 else
955 /* TODO: more weird restrictions on shift. */
958 if (boundary != NULL)
960 if (same_type_check (array, 0, boundary, 2) == FAILURE)
961 return FAILURE;
963 /* TODO: more restrictions on boundary. */
966 if (dim_check (dim, 1, 1) == FAILURE)
967 return FAILURE;
969 if (gfc_init_expr)
970 return non_init_transformational ();
972 return SUCCESS;
976 /* A single complex argument. */
979 gfc_check_fn_c (gfc_expr *a)
981 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
982 return FAILURE;
984 return SUCCESS;
988 /* A single real argument. */
991 gfc_check_fn_r (gfc_expr *a)
993 if (type_check (a, 0, BT_REAL) == FAILURE)
994 return FAILURE;
996 return SUCCESS;
1000 /* A single real or complex argument. */
1003 gfc_check_fn_rc (gfc_expr *a)
1005 if (real_or_complex_check (a, 0) == FAILURE)
1006 return FAILURE;
1008 return SUCCESS;
1013 gfc_check_fnum (gfc_expr *unit)
1015 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1016 return FAILURE;
1018 if (scalar_check (unit, 0) == FAILURE)
1019 return FAILURE;
1021 return SUCCESS;
1025 /* This is used for the g77 one-argument Bessel functions, and the
1026 error function. */
1029 gfc_check_g77_math1 (gfc_expr *x)
1031 if (scalar_check (x, 0) == FAILURE)
1032 return FAILURE;
1034 if (type_check (x, 0, BT_REAL) == FAILURE)
1035 return FAILURE;
1037 return SUCCESS;
1042 gfc_check_huge (gfc_expr *x)
1044 if (int_or_real_check (x, 0) == FAILURE)
1045 return FAILURE;
1047 return SUCCESS;
1051 /* Check that the single argument is an integer. */
1054 gfc_check_i (gfc_expr *i)
1056 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1057 return FAILURE;
1059 return SUCCESS;
1064 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1066 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1067 return FAILURE;
1069 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1070 return FAILURE;
1072 if (i->ts.kind != j->ts.kind)
1074 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1075 &i->where) == FAILURE)
1076 return FAILURE;
1079 return SUCCESS;
1084 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1086 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1087 return FAILURE;
1089 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1090 return FAILURE;
1092 return SUCCESS;
1097 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1099 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1100 return FAILURE;
1102 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1103 return FAILURE;
1105 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1106 return FAILURE;
1108 return SUCCESS;
1113 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1115 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1116 return FAILURE;
1118 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1119 return FAILURE;
1121 return SUCCESS;
1126 gfc_check_ichar_iachar (gfc_expr *c)
1128 int i;
1130 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1131 return FAILURE;
1133 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1135 gfc_expr *start;
1136 gfc_expr *end;
1137 gfc_ref *ref;
1139 /* Substring references don't have the charlength set. */
1140 ref = c->ref;
1141 while (ref && ref->type != REF_SUBSTRING)
1142 ref = ref->next;
1144 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1146 if (!ref)
1148 /* Check that the argument is length one. Non-constant lengths
1149 can't be checked here, so assume they are ok. */
1150 if (c->ts.cl && c->ts.cl->length)
1152 /* If we already have a length for this expression then use it. */
1153 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1154 return SUCCESS;
1155 i = mpz_get_si (c->ts.cl->length->value.integer);
1157 else
1158 return SUCCESS;
1160 else
1162 start = ref->u.ss.start;
1163 end = ref->u.ss.end;
1165 gcc_assert (start);
1166 if (end == NULL || end->expr_type != EXPR_CONSTANT
1167 || start->expr_type != EXPR_CONSTANT)
1168 return SUCCESS;
1170 i = mpz_get_si (end->value.integer) + 1
1171 - mpz_get_si (start->value.integer);
1174 else
1175 return SUCCESS;
1177 if (i != 1)
1179 gfc_error ("Argument of %s at %L must be of length one",
1180 gfc_current_intrinsic, &c->where);
1181 return FAILURE;
1184 return SUCCESS;
1189 gfc_check_idnint (gfc_expr *a)
1191 if (double_check (a, 0) == FAILURE)
1192 return FAILURE;
1194 return SUCCESS;
1199 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1201 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1202 return FAILURE;
1204 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1205 return FAILURE;
1207 if (i->ts.kind != j->ts.kind)
1209 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1210 &i->where) == FAILURE)
1211 return FAILURE;
1214 return SUCCESS;
1219 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back)
1221 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1222 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1223 return FAILURE;
1226 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1227 return FAILURE;
1229 if (string->ts.kind != substring->ts.kind)
1231 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1232 "kind as '%s'", gfc_current_intrinsic_arg[1],
1233 gfc_current_intrinsic, &substring->where,
1234 gfc_current_intrinsic_arg[0]);
1235 return FAILURE;
1238 return SUCCESS;
1243 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1245 if (numeric_check (x, 0) == FAILURE)
1246 return FAILURE;
1248 if (kind != NULL)
1250 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1251 return FAILURE;
1253 if (scalar_check (kind, 1) == FAILURE)
1254 return FAILURE;
1257 return SUCCESS;
1262 gfc_check_intconv (gfc_expr *x)
1264 if (numeric_check (x, 0) == FAILURE)
1265 return FAILURE;
1267 return SUCCESS;
1272 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1274 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1275 return FAILURE;
1277 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1278 return FAILURE;
1280 if (i->ts.kind != j->ts.kind)
1282 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1283 &i->where) == FAILURE)
1284 return FAILURE;
1287 return SUCCESS;
1292 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1294 if (type_check (i, 0, BT_INTEGER) == FAILURE
1295 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1296 return FAILURE;
1298 return SUCCESS;
1303 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1305 if (type_check (i, 0, BT_INTEGER) == FAILURE
1306 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1307 return FAILURE;
1309 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1310 return FAILURE;
1312 return SUCCESS;
1317 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1319 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1320 return FAILURE;
1322 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1323 return FAILURE;
1325 return SUCCESS;
1330 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1332 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1333 return FAILURE;
1335 if (scalar_check (pid, 0) == FAILURE)
1336 return FAILURE;
1338 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1339 return FAILURE;
1341 if (scalar_check (sig, 1) == FAILURE)
1342 return FAILURE;
1344 if (status == NULL)
1345 return SUCCESS;
1347 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1348 return FAILURE;
1350 if (scalar_check (status, 2) == FAILURE)
1351 return FAILURE;
1353 return SUCCESS;
1358 gfc_check_kind (gfc_expr *x)
1360 if (x->ts.type == BT_DERIVED)
1362 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1363 "non-derived type", gfc_current_intrinsic_arg[0],
1364 gfc_current_intrinsic, &x->where);
1365 return FAILURE;
1368 return SUCCESS;
1373 gfc_check_lbound (gfc_expr *array, gfc_expr *dim)
1375 if (array_check (array, 0) == FAILURE)
1376 return FAILURE;
1378 if (dim != NULL)
1380 if (dim_check (dim, 1, 1) == FAILURE)
1381 return FAILURE;
1383 if (dim_rank_check (dim, array, 1) == FAILURE)
1384 return FAILURE;
1386 return SUCCESS;
1391 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1393 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1394 return FAILURE;
1396 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1397 return FAILURE;
1399 return SUCCESS;
1404 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1406 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1407 return FAILURE;
1409 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1410 return FAILURE;
1412 if (status == NULL)
1413 return SUCCESS;
1415 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1416 return FAILURE;
1418 if (scalar_check (status, 2) == FAILURE)
1419 return FAILURE;
1421 return SUCCESS;
1426 gfc_check_loc (gfc_expr *expr)
1428 return variable_check (expr, 0);
1433 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1435 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1436 return FAILURE;
1438 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1439 return FAILURE;
1441 return SUCCESS;
1446 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1448 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1449 return FAILURE;
1451 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1452 return FAILURE;
1454 if (status == NULL)
1455 return SUCCESS;
1457 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1458 return FAILURE;
1460 if (scalar_check (status, 2) == FAILURE)
1461 return FAILURE;
1463 return SUCCESS;
1468 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1470 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1471 return FAILURE;
1472 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1473 return FAILURE;
1475 return SUCCESS;
1479 /* Min/max family. */
1481 static try
1482 min_max_args (gfc_actual_arglist *arg)
1484 if (arg == NULL || arg->next == NULL)
1486 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1487 gfc_current_intrinsic, gfc_current_intrinsic_where);
1488 return FAILURE;
1491 return SUCCESS;
1495 static try
1496 check_rest (bt type, int kind, gfc_actual_arglist *arg)
1498 gfc_expr *x;
1499 int n;
1501 if (min_max_args (arg) == FAILURE)
1502 return FAILURE;
1504 n = 1;
1506 for (; arg; arg = arg->next, n++)
1508 x = arg->expr;
1509 if (x->ts.type != type || x->ts.kind != kind)
1511 if (x->ts.type == type)
1513 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1514 "kinds at %L", &x->where) == FAILURE)
1515 return FAILURE;
1517 else
1519 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1520 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1521 gfc_basic_typename (type), kind);
1522 return FAILURE;
1527 return SUCCESS;
1532 gfc_check_min_max (gfc_actual_arglist *arg)
1534 gfc_expr *x;
1536 if (min_max_args (arg) == FAILURE)
1537 return FAILURE;
1539 x = arg->expr;
1541 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1543 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER "
1544 "or REAL", gfc_current_intrinsic, &x->where);
1545 return FAILURE;
1548 return check_rest (x->ts.type, x->ts.kind, arg);
1553 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1555 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1560 gfc_check_min_max_real (gfc_actual_arglist *arg)
1562 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1567 gfc_check_min_max_double (gfc_actual_arglist *arg)
1569 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1573 /* End of min/max family. */
1576 gfc_check_malloc (gfc_expr *size)
1578 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1579 return FAILURE;
1581 if (scalar_check (size, 0) == FAILURE)
1582 return FAILURE;
1584 return SUCCESS;
1589 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1591 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1593 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1594 "or LOGICAL", gfc_current_intrinsic_arg[0],
1595 gfc_current_intrinsic, &matrix_a->where);
1596 return FAILURE;
1599 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1601 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1602 "or LOGICAL", gfc_current_intrinsic_arg[1],
1603 gfc_current_intrinsic, &matrix_b->where);
1604 return FAILURE;
1607 switch (matrix_a->rank)
1609 case 1:
1610 if (rank_check (matrix_b, 1, 2) == FAILURE)
1611 return FAILURE;
1612 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1613 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1615 gfc_error ("different shape on dimension 1 for arguments '%s' "
1616 "and '%s' at %L for intrinsic matmul",
1617 gfc_current_intrinsic_arg[0],
1618 gfc_current_intrinsic_arg[1], &matrix_a->where);
1619 return FAILURE;
1621 break;
1623 case 2:
1624 if (matrix_b->rank != 2)
1626 if (rank_check (matrix_b, 1, 1) == FAILURE)
1627 return FAILURE;
1629 /* matrix_b has rank 1 or 2 here. Common check for the cases
1630 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1631 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1632 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1634 gfc_error ("different shape on dimension 2 for argument '%s' and "
1635 "dimension 1 for argument '%s' at %L for intrinsic "
1636 "matmul", gfc_current_intrinsic_arg[0],
1637 gfc_current_intrinsic_arg[1], &matrix_a->where);
1638 return FAILURE;
1640 break;
1642 default:
1643 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1644 "1 or 2", gfc_current_intrinsic_arg[0],
1645 gfc_current_intrinsic, &matrix_a->where);
1646 return FAILURE;
1649 if (gfc_init_expr)
1650 return non_init_transformational ();
1652 return SUCCESS;
1656 /* Whoever came up with this interface was probably on something.
1657 The possibilities for the occupation of the second and third
1658 parameters are:
1660 Arg #2 Arg #3
1661 NULL NULL
1662 DIM NULL
1663 MASK NULL
1664 NULL MASK minloc(array, mask=m)
1665 DIM MASK
1667 I.e. in the case of minloc(array,mask), mask will be in the second
1668 position of the argument list and we'll have to fix that up. */
1671 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1673 gfc_expr *a, *m, *d;
1675 a = ap->expr;
1676 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1677 return FAILURE;
1679 d = ap->next->expr;
1680 m = ap->next->next->expr;
1682 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1683 && ap->next->name == NULL)
1685 m = d;
1686 d = NULL;
1687 ap->next->expr = NULL;
1688 ap->next->next->expr = m;
1691 if (dim_check (d, 1, 1) == FAILURE)
1692 return FAILURE;
1694 if (d && dim_rank_check (d, a, 0) == FAILURE)
1695 return FAILURE;
1697 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1698 return FAILURE;
1700 if (m != NULL)
1702 char buffer[80];
1703 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1704 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1705 gfc_current_intrinsic);
1706 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1707 return FAILURE;
1710 if (gfc_init_expr)
1711 return non_init_transformational ();
1713 return SUCCESS;
1717 /* Similar to minloc/maxloc, the argument list might need to be
1718 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1719 difference is that MINLOC/MAXLOC take an additional KIND argument.
1720 The possibilities are:
1722 Arg #2 Arg #3
1723 NULL NULL
1724 DIM NULL
1725 MASK NULL
1726 NULL MASK minval(array, mask=m)
1727 DIM MASK
1729 I.e. in the case of minval(array,mask), mask will be in the second
1730 position of the argument list and we'll have to fix that up. */
1732 static try
1733 check_reduction (gfc_actual_arglist *ap)
1735 gfc_expr *a, *m, *d;
1737 a = ap->expr;
1738 d = ap->next->expr;
1739 m = ap->next->next->expr;
1741 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1742 && ap->next->name == NULL)
1744 m = d;
1745 d = NULL;
1746 ap->next->expr = NULL;
1747 ap->next->next->expr = m;
1750 if (dim_check (d, 1, 1) == FAILURE)
1751 return FAILURE;
1753 if (d && dim_rank_check (d, a, 0) == FAILURE)
1754 return FAILURE;
1756 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1757 return FAILURE;
1759 if (m != NULL)
1761 char buffer[80];
1762 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1763 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1764 gfc_current_intrinsic);
1765 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1766 return FAILURE;
1769 return SUCCESS;
1774 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1776 if (int_or_real_check (ap->expr, 0) == FAILURE
1777 || array_check (ap->expr, 0) == FAILURE)
1778 return FAILURE;
1780 if (gfc_init_expr)
1781 return non_init_transformational ();
1783 return check_reduction (ap);
1788 gfc_check_product_sum (gfc_actual_arglist *ap)
1790 if (numeric_check (ap->expr, 0) == FAILURE
1791 || array_check (ap->expr, 0) == FAILURE)
1792 return FAILURE;
1794 if (gfc_init_expr)
1795 return non_init_transformational ();
1797 return check_reduction (ap);
1802 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
1804 char buffer[80];
1806 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1807 return FAILURE;
1809 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1810 return FAILURE;
1812 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1813 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1814 gfc_current_intrinsic);
1815 if (gfc_check_conformance (buffer, tsource, fsource) == FAILURE)
1816 return FAILURE;
1818 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1819 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1820 gfc_current_intrinsic);
1821 if (gfc_check_conformance (buffer, tsource, mask) == FAILURE)
1822 return FAILURE;
1824 return SUCCESS;
1828 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
1830 symbol_attribute attr;
1832 if (variable_check (from, 0) == FAILURE)
1833 return FAILURE;
1835 if (array_check (from, 0) == FAILURE)
1836 return FAILURE;
1838 attr = gfc_variable_attr (from, NULL);
1839 if (!attr.allocatable)
1841 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1842 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1843 &from->where);
1844 return FAILURE;
1847 if (variable_check (to, 0) == FAILURE)
1848 return FAILURE;
1850 if (array_check (to, 0) == FAILURE)
1851 return FAILURE;
1853 attr = gfc_variable_attr (to, NULL);
1854 if (!attr.allocatable)
1856 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1857 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1858 &to->where);
1859 return FAILURE;
1862 if (same_type_check (from, 0, to, 1) == FAILURE)
1863 return FAILURE;
1865 if (to->rank != from->rank)
1867 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1868 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
1869 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1870 &to->where, from->rank, to->rank);
1871 return FAILURE;
1874 if (to->ts.kind != from->ts.kind)
1876 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1877 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
1878 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1879 &to->where, from->ts.kind, to->ts.kind);
1880 return FAILURE;
1883 return SUCCESS;
1888 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
1890 if (type_check (x, 0, BT_REAL) == FAILURE)
1891 return FAILURE;
1893 if (type_check (s, 1, BT_REAL) == FAILURE)
1894 return FAILURE;
1896 return SUCCESS;
1901 gfc_check_new_line (gfc_expr *a)
1903 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1904 return FAILURE;
1906 return SUCCESS;
1911 gfc_check_null (gfc_expr *mold)
1913 symbol_attribute attr;
1915 if (mold == NULL)
1916 return SUCCESS;
1918 if (variable_check (mold, 0) == FAILURE)
1919 return FAILURE;
1921 attr = gfc_variable_attr (mold, NULL);
1923 if (!attr.pointer)
1925 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1926 gfc_current_intrinsic_arg[0],
1927 gfc_current_intrinsic, &mold->where);
1928 return FAILURE;
1931 return SUCCESS;
1936 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
1938 char buffer[80];
1940 if (array_check (array, 0) == FAILURE)
1941 return FAILURE;
1943 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1944 return FAILURE;
1946 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1947 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1948 gfc_current_intrinsic);
1949 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1950 return FAILURE;
1952 if (vector != NULL)
1954 if (same_type_check (array, 0, vector, 2) == FAILURE)
1955 return FAILURE;
1957 if (rank_check (vector, 2, 1) == FAILURE)
1958 return FAILURE;
1960 /* TODO: More constraints here. */
1963 if (gfc_init_expr)
1964 return non_init_transformational ();
1966 return SUCCESS;
1971 gfc_check_precision (gfc_expr *x)
1973 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1975 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1976 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1977 gfc_current_intrinsic, &x->where);
1978 return FAILURE;
1981 return SUCCESS;
1986 gfc_check_present (gfc_expr *a)
1988 gfc_symbol *sym;
1990 if (variable_check (a, 0) == FAILURE)
1991 return FAILURE;
1993 sym = a->symtree->n.sym;
1994 if (!sym->attr.dummy)
1996 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1997 "dummy variable", gfc_current_intrinsic_arg[0],
1998 gfc_current_intrinsic, &a->where);
1999 return FAILURE;
2002 if (!sym->attr.optional)
2004 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2005 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
2006 gfc_current_intrinsic, &a->where);
2007 return FAILURE;
2010 /* 13.14.82 PRESENT(A)
2011 ......
2012 Argument. A shall be the name of an optional dummy argument that is
2013 accessible in the subprogram in which the PRESENT function reference
2014 appears... */
2016 if (a->ref != NULL
2017 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2018 && a->ref->u.ar.type == AR_FULL))
2020 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2021 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2022 gfc_current_intrinsic, &a->where, sym->name);
2023 return FAILURE;
2026 return SUCCESS;
2031 gfc_check_radix (gfc_expr *x)
2033 if (int_or_real_check (x, 0) == FAILURE)
2034 return FAILURE;
2036 return SUCCESS;
2041 gfc_check_range (gfc_expr *x)
2043 if (numeric_check (x, 0) == FAILURE)
2044 return FAILURE;
2046 return SUCCESS;
2050 /* real, float, sngl. */
2052 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2054 if (numeric_check (a, 0) == FAILURE)
2055 return FAILURE;
2057 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2058 return FAILURE;
2060 return SUCCESS;
2065 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2067 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2068 return FAILURE;
2070 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2071 return FAILURE;
2073 return SUCCESS;
2078 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2080 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2081 return FAILURE;
2083 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2084 return FAILURE;
2086 if (status == NULL)
2087 return SUCCESS;
2089 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2090 return FAILURE;
2092 if (scalar_check (status, 2) == FAILURE)
2093 return FAILURE;
2095 return SUCCESS;
2100 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2102 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2103 return FAILURE;
2105 if (scalar_check (x, 0) == FAILURE)
2106 return FAILURE;
2108 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2109 return FAILURE;
2111 if (scalar_check (y, 1) == FAILURE)
2112 return FAILURE;
2114 return SUCCESS;
2119 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2120 gfc_expr *pad, gfc_expr *order)
2122 mpz_t size;
2123 mpz_t nelems;
2124 int m;
2126 if (array_check (source, 0) == FAILURE)
2127 return FAILURE;
2129 if (rank_check (shape, 1, 1) == FAILURE)
2130 return FAILURE;
2132 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2133 return FAILURE;
2135 if (gfc_array_size (shape, &size) != SUCCESS)
2137 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2138 "array of constant size", &shape->where);
2139 return FAILURE;
2142 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2143 mpz_clear (size);
2145 if (m > 0)
2147 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2148 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2149 return FAILURE;
2152 if (pad != NULL)
2154 if (same_type_check (source, 0, pad, 2) == FAILURE)
2155 return FAILURE;
2156 if (array_check (pad, 2) == FAILURE)
2157 return FAILURE;
2160 if (order != NULL && array_check (order, 3) == FAILURE)
2161 return FAILURE;
2163 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2164 && gfc_is_constant_expr (shape)
2165 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2166 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2168 /* Check the match in size between source and destination. */
2169 if (gfc_array_size (source, &nelems) == SUCCESS)
2171 gfc_constructor *c;
2172 bool test;
2174 c = shape->value.constructor;
2175 mpz_init_set_ui (size, 1);
2176 for (; c; c = c->next)
2177 mpz_mul (size, size, c->expr->value.integer);
2179 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2180 mpz_clear (nelems);
2181 mpz_clear (size);
2183 if (test)
2185 gfc_error ("Without padding, there are not enough elements "
2186 "in the intrinsic RESHAPE source at %L to match "
2187 "the shape", &source->where);
2188 return FAILURE;
2193 return SUCCESS;
2198 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2200 if (type_check (x, 0, BT_REAL) == FAILURE)
2201 return FAILURE;
2203 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2204 return FAILURE;
2206 return SUCCESS;
2211 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2213 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2214 return FAILURE;
2216 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2217 return FAILURE;
2219 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2220 return FAILURE;
2222 if (same_type_check (x, 0, y, 1) == FAILURE)
2223 return FAILURE;
2225 return SUCCESS;
2230 gfc_check_secnds (gfc_expr *r)
2232 if (type_check (r, 0, BT_REAL) == FAILURE)
2233 return FAILURE;
2235 if (kind_value_check (r, 0, 4) == FAILURE)
2236 return FAILURE;
2238 if (scalar_check (r, 0) == FAILURE)
2239 return FAILURE;
2241 return SUCCESS;
2246 gfc_check_selected_int_kind (gfc_expr *r)
2248 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2249 return FAILURE;
2251 if (scalar_check (r, 0) == FAILURE)
2252 return FAILURE;
2254 return SUCCESS;
2259 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2261 if (p == NULL && r == NULL)
2263 gfc_error ("Missing arguments to %s intrinsic at %L",
2264 gfc_current_intrinsic, gfc_current_intrinsic_where);
2266 return FAILURE;
2269 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2270 return FAILURE;
2272 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2273 return FAILURE;
2275 return SUCCESS;
2280 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2282 if (type_check (x, 0, BT_REAL) == FAILURE)
2283 return FAILURE;
2285 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2286 return FAILURE;
2288 return SUCCESS;
2293 gfc_check_shape (gfc_expr *source)
2295 gfc_array_ref *ar;
2297 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2298 return SUCCESS;
2300 ar = gfc_find_array_ref (source);
2302 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2304 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2305 "an assumed size array", &source->where);
2306 return FAILURE;
2309 return SUCCESS;
2314 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2316 if (int_or_real_check (a, 0) == FAILURE)
2317 return FAILURE;
2319 if (same_type_check (a, 0, b, 1) == FAILURE)
2320 return FAILURE;
2322 return SUCCESS;
2327 gfc_check_size (gfc_expr *array, gfc_expr *dim)
2329 if (array_check (array, 0) == FAILURE)
2330 return FAILURE;
2332 if (dim != NULL)
2334 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2335 return FAILURE;
2337 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2338 return FAILURE;
2340 if (dim_rank_check (dim, array, 0) == FAILURE)
2341 return FAILURE;
2344 return SUCCESS;
2349 gfc_check_sleep_sub (gfc_expr *seconds)
2351 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2352 return FAILURE;
2354 if (scalar_check (seconds, 0) == FAILURE)
2355 return FAILURE;
2357 return SUCCESS;
2362 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2364 if (source->rank >= GFC_MAX_DIMENSIONS)
2366 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2367 "than rank %d", gfc_current_intrinsic_arg[0],
2368 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2370 return FAILURE;
2373 if (dim_check (dim, 1, 0) == FAILURE)
2374 return FAILURE;
2376 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2377 return FAILURE;
2379 if (scalar_check (ncopies, 2) == FAILURE)
2380 return FAILURE;
2382 if (gfc_init_expr)
2383 return non_init_transformational ();
2385 return SUCCESS;
2389 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2390 functions). */
2393 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2395 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2396 return FAILURE;
2398 if (scalar_check (unit, 0) == FAILURE)
2399 return FAILURE;
2401 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2402 return FAILURE;
2404 if (status == NULL)
2405 return SUCCESS;
2407 if (type_check (status, 2, BT_INTEGER) == FAILURE
2408 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2409 || scalar_check (status, 2) == FAILURE)
2410 return FAILURE;
2412 return SUCCESS;
2417 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2419 return gfc_check_fgetputc_sub (unit, c, NULL);
2424 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2426 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2427 return FAILURE;
2429 if (status == NULL)
2430 return SUCCESS;
2432 if (type_check (status, 1, BT_INTEGER) == FAILURE
2433 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2434 || scalar_check (status, 1) == FAILURE)
2435 return FAILURE;
2437 return SUCCESS;
2442 gfc_check_fgetput (gfc_expr *c)
2444 return gfc_check_fgetput_sub (c, NULL);
2449 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2451 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2452 return FAILURE;
2454 if (scalar_check (unit, 0) == FAILURE)
2455 return FAILURE;
2457 if (type_check (array, 1, BT_INTEGER) == FAILURE
2458 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2459 return FAILURE;
2461 if (array_check (array, 1) == FAILURE)
2462 return FAILURE;
2464 return SUCCESS;
2469 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2471 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2472 return FAILURE;
2474 if (scalar_check (unit, 0) == FAILURE)
2475 return FAILURE;
2477 if (type_check (array, 1, BT_INTEGER) == FAILURE
2478 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2479 return FAILURE;
2481 if (array_check (array, 1) == FAILURE)
2482 return FAILURE;
2484 if (status == NULL)
2485 return SUCCESS;
2487 if (type_check (status, 2, BT_INTEGER) == FAILURE
2488 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2489 return FAILURE;
2491 if (scalar_check (status, 2) == FAILURE)
2492 return FAILURE;
2494 return SUCCESS;
2499 gfc_check_ftell (gfc_expr *unit)
2501 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2502 return FAILURE;
2504 if (scalar_check (unit, 0) == FAILURE)
2505 return FAILURE;
2507 return SUCCESS;
2512 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2514 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2515 return FAILURE;
2517 if (scalar_check (unit, 0) == FAILURE)
2518 return FAILURE;
2520 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2521 return FAILURE;
2523 if (scalar_check (offset, 1) == FAILURE)
2524 return FAILURE;
2526 return SUCCESS;
2531 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2533 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2534 return FAILURE;
2536 if (type_check (array, 1, BT_INTEGER) == FAILURE
2537 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2538 return FAILURE;
2540 if (array_check (array, 1) == FAILURE)
2541 return FAILURE;
2543 return SUCCESS;
2548 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2550 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2551 return FAILURE;
2553 if (type_check (array, 1, BT_INTEGER) == FAILURE
2554 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2555 return FAILURE;
2557 if (array_check (array, 1) == FAILURE)
2558 return FAILURE;
2560 if (status == NULL)
2561 return SUCCESS;
2563 if (type_check (status, 2, BT_INTEGER) == FAILURE
2564 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2565 return FAILURE;
2567 if (scalar_check (status, 2) == FAILURE)
2568 return FAILURE;
2570 return SUCCESS;
2575 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
2576 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
2578 if (size != NULL)
2580 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2581 return FAILURE;
2583 if (scalar_check (size, 2) == FAILURE)
2584 return FAILURE;
2586 if (nonoptional_check (size, 2) == FAILURE)
2587 return FAILURE;
2590 return SUCCESS;
2595 gfc_check_transpose (gfc_expr *matrix)
2597 if (rank_check (matrix, 0, 2) == FAILURE)
2598 return FAILURE;
2600 if (gfc_init_expr)
2601 return non_init_transformational ();
2603 return SUCCESS;
2608 gfc_check_ubound (gfc_expr *array, gfc_expr *dim)
2610 if (array_check (array, 0) == FAILURE)
2611 return FAILURE;
2613 if (dim != NULL)
2615 if (dim_check (dim, 1, 1) == FAILURE)
2616 return FAILURE;
2618 if (dim_rank_check (dim, array, 0) == FAILURE)
2619 return FAILURE;
2622 return SUCCESS;
2627 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
2629 if (rank_check (vector, 0, 1) == FAILURE)
2630 return FAILURE;
2632 if (array_check (mask, 1) == FAILURE)
2633 return FAILURE;
2635 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2636 return FAILURE;
2638 if (same_type_check (vector, 0, field, 2) == FAILURE)
2639 return FAILURE;
2641 if (gfc_init_expr)
2642 return non_init_transformational ();
2644 return SUCCESS;
2649 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2651 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2652 return FAILURE;
2654 if (same_type_check (x, 0, y, 1) == FAILURE)
2655 return FAILURE;
2657 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2658 return FAILURE;
2660 return SUCCESS;
2665 gfc_check_trim (gfc_expr *x)
2667 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2668 return FAILURE;
2670 if (scalar_check (x, 0) == FAILURE)
2671 return FAILURE;
2673 return SUCCESS;
2678 gfc_check_ttynam (gfc_expr *unit)
2680 if (scalar_check (unit, 0) == FAILURE)
2681 return FAILURE;
2683 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2684 return FAILURE;
2686 return SUCCESS;
2690 /* Common check function for the half a dozen intrinsics that have a
2691 single real argument. */
2694 gfc_check_x (gfc_expr *x)
2696 if (type_check (x, 0, BT_REAL) == FAILURE)
2697 return FAILURE;
2699 return SUCCESS;
2703 /************* Check functions for intrinsic subroutines *************/
2706 gfc_check_cpu_time (gfc_expr *time)
2708 if (scalar_check (time, 0) == FAILURE)
2709 return FAILURE;
2711 if (type_check (time, 0, BT_REAL) == FAILURE)
2712 return FAILURE;
2714 if (variable_check (time, 0) == FAILURE)
2715 return FAILURE;
2717 return SUCCESS;
2722 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
2723 gfc_expr *zone, gfc_expr *values)
2725 if (date != NULL)
2727 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2728 return FAILURE;
2729 if (scalar_check (date, 0) == FAILURE)
2730 return FAILURE;
2731 if (variable_check (date, 0) == FAILURE)
2732 return FAILURE;
2735 if (time != NULL)
2737 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2738 return FAILURE;
2739 if (scalar_check (time, 1) == FAILURE)
2740 return FAILURE;
2741 if (variable_check (time, 1) == FAILURE)
2742 return FAILURE;
2745 if (zone != NULL)
2747 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2748 return FAILURE;
2749 if (scalar_check (zone, 2) == FAILURE)
2750 return FAILURE;
2751 if (variable_check (zone, 2) == FAILURE)
2752 return FAILURE;
2755 if (values != NULL)
2757 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2758 return FAILURE;
2759 if (array_check (values, 3) == FAILURE)
2760 return FAILURE;
2761 if (rank_check (values, 3, 1) == FAILURE)
2762 return FAILURE;
2763 if (variable_check (values, 3) == FAILURE)
2764 return FAILURE;
2767 return SUCCESS;
2772 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
2773 gfc_expr *to, gfc_expr *topos)
2775 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2776 return FAILURE;
2778 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2779 return FAILURE;
2781 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2782 return FAILURE;
2784 if (same_type_check (from, 0, to, 3) == FAILURE)
2785 return FAILURE;
2787 if (variable_check (to, 3) == FAILURE)
2788 return FAILURE;
2790 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2791 return FAILURE;
2793 return SUCCESS;
2798 gfc_check_random_number (gfc_expr *harvest)
2800 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2801 return FAILURE;
2803 if (variable_check (harvest, 0) == FAILURE)
2804 return FAILURE;
2806 return SUCCESS;
2811 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
2813 if (size != NULL)
2815 if (scalar_check (size, 0) == FAILURE)
2816 return FAILURE;
2818 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2819 return FAILURE;
2821 if (variable_check (size, 0) == FAILURE)
2822 return FAILURE;
2824 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2825 return FAILURE;
2828 if (put != NULL)
2831 if (size != NULL)
2832 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2833 &put->where);
2835 if (array_check (put, 1) == FAILURE)
2836 return FAILURE;
2838 if (rank_check (put, 1, 1) == FAILURE)
2839 return FAILURE;
2841 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2842 return FAILURE;
2844 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2845 return FAILURE;
2848 if (get != NULL)
2851 if (size != NULL || put != NULL)
2852 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2853 &get->where);
2855 if (array_check (get, 2) == FAILURE)
2856 return FAILURE;
2858 if (rank_check (get, 2, 1) == FAILURE)
2859 return FAILURE;
2861 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2862 return FAILURE;
2864 if (variable_check (get, 2) == FAILURE)
2865 return FAILURE;
2867 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2868 return FAILURE;
2871 return SUCCESS;
2876 gfc_check_second_sub (gfc_expr *time)
2878 if (scalar_check (time, 0) == FAILURE)
2879 return FAILURE;
2881 if (type_check (time, 0, BT_REAL) == FAILURE)
2882 return FAILURE;
2884 if (kind_value_check(time, 0, 4) == FAILURE)
2885 return FAILURE;
2887 return SUCCESS;
2891 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2892 count, count_rate, and count_max are all optional arguments */
2895 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
2896 gfc_expr *count_max)
2898 if (count != NULL)
2900 if (scalar_check (count, 0) == FAILURE)
2901 return FAILURE;
2903 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2904 return FAILURE;
2906 if (variable_check (count, 0) == FAILURE)
2907 return FAILURE;
2910 if (count_rate != NULL)
2912 if (scalar_check (count_rate, 1) == FAILURE)
2913 return FAILURE;
2915 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2916 return FAILURE;
2918 if (variable_check (count_rate, 1) == FAILURE)
2919 return FAILURE;
2921 if (count != NULL
2922 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2923 return FAILURE;
2927 if (count_max != NULL)
2929 if (scalar_check (count_max, 2) == FAILURE)
2930 return FAILURE;
2932 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2933 return FAILURE;
2935 if (variable_check (count_max, 2) == FAILURE)
2936 return FAILURE;
2938 if (count != NULL
2939 && same_type_check (count, 0, count_max, 2) == FAILURE)
2940 return FAILURE;
2942 if (count_rate != NULL
2943 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2944 return FAILURE;
2947 return SUCCESS;
2952 gfc_check_irand (gfc_expr *x)
2954 if (x == NULL)
2955 return SUCCESS;
2957 if (scalar_check (x, 0) == FAILURE)
2958 return FAILURE;
2960 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2961 return FAILURE;
2963 if (kind_value_check(x, 0, 4) == FAILURE)
2964 return FAILURE;
2966 return SUCCESS;
2971 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
2973 if (scalar_check (seconds, 0) == FAILURE)
2974 return FAILURE;
2976 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2977 return FAILURE;
2979 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2981 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
2982 "or PROCEDURE", gfc_current_intrinsic_arg[1],
2983 gfc_current_intrinsic, &handler->where);
2984 return FAILURE;
2987 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2988 return FAILURE;
2990 if (status == NULL)
2991 return SUCCESS;
2993 if (scalar_check (status, 2) == FAILURE)
2994 return FAILURE;
2996 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2997 return FAILURE;
2999 return SUCCESS;
3004 gfc_check_rand (gfc_expr *x)
3006 if (x == NULL)
3007 return SUCCESS;
3009 if (scalar_check (x, 0) == FAILURE)
3010 return FAILURE;
3012 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3013 return FAILURE;
3015 if (kind_value_check(x, 0, 4) == FAILURE)
3016 return FAILURE;
3018 return SUCCESS;
3023 gfc_check_srand (gfc_expr *x)
3025 if (scalar_check (x, 0) == FAILURE)
3026 return FAILURE;
3028 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3029 return FAILURE;
3031 if (kind_value_check(x, 0, 4) == FAILURE)
3032 return FAILURE;
3034 return SUCCESS;
3039 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3041 if (scalar_check (time, 0) == FAILURE)
3042 return FAILURE;
3044 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3045 return FAILURE;
3047 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3048 return FAILURE;
3050 return SUCCESS;
3055 gfc_check_etime (gfc_expr *x)
3057 if (array_check (x, 0) == FAILURE)
3058 return FAILURE;
3060 if (rank_check (x, 0, 1) == FAILURE)
3061 return FAILURE;
3063 if (variable_check (x, 0) == FAILURE)
3064 return FAILURE;
3066 if (type_check (x, 0, BT_REAL) == FAILURE)
3067 return FAILURE;
3069 if (kind_value_check(x, 0, 4) == FAILURE)
3070 return FAILURE;
3072 return SUCCESS;
3077 gfc_check_etime_sub (gfc_expr *values, gfc_expr *time)
3079 if (array_check (values, 0) == FAILURE)
3080 return FAILURE;
3082 if (rank_check (values, 0, 1) == FAILURE)
3083 return FAILURE;
3085 if (variable_check (values, 0) == FAILURE)
3086 return FAILURE;
3088 if (type_check (values, 0, BT_REAL) == FAILURE)
3089 return FAILURE;
3091 if (kind_value_check(values, 0, 4) == FAILURE)
3092 return FAILURE;
3094 if (scalar_check (time, 1) == FAILURE)
3095 return FAILURE;
3097 if (type_check (time, 1, BT_REAL) == FAILURE)
3098 return FAILURE;
3100 if (kind_value_check(time, 1, 4) == FAILURE)
3101 return FAILURE;
3103 return SUCCESS;
3108 gfc_check_fdate_sub (gfc_expr *date)
3110 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3111 return FAILURE;
3113 return SUCCESS;
3118 gfc_check_gerror (gfc_expr *msg)
3120 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3121 return FAILURE;
3123 return SUCCESS;
3128 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3130 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3131 return FAILURE;
3133 if (status == NULL)
3134 return SUCCESS;
3136 if (scalar_check (status, 1) == FAILURE)
3137 return FAILURE;
3139 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3140 return FAILURE;
3142 return SUCCESS;
3147 gfc_check_getlog (gfc_expr *msg)
3149 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3150 return FAILURE;
3152 return SUCCESS;
3157 gfc_check_exit (gfc_expr *status)
3159 if (status == NULL)
3160 return SUCCESS;
3162 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3163 return FAILURE;
3165 if (scalar_check (status, 0) == FAILURE)
3166 return FAILURE;
3168 return SUCCESS;
3173 gfc_check_flush (gfc_expr *unit)
3175 if (unit == NULL)
3176 return SUCCESS;
3178 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3179 return FAILURE;
3181 if (scalar_check (unit, 0) == FAILURE)
3182 return FAILURE;
3184 return SUCCESS;
3189 gfc_check_free (gfc_expr *i)
3191 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3192 return FAILURE;
3194 if (scalar_check (i, 0) == FAILURE)
3195 return FAILURE;
3197 return SUCCESS;
3202 gfc_check_hostnm (gfc_expr *name)
3204 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3205 return FAILURE;
3207 return SUCCESS;
3212 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3214 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3215 return FAILURE;
3217 if (status == NULL)
3218 return SUCCESS;
3220 if (scalar_check (status, 1) == FAILURE)
3221 return FAILURE;
3223 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3224 return FAILURE;
3226 return SUCCESS;
3231 gfc_check_itime_idate (gfc_expr *values)
3233 if (array_check (values, 0) == FAILURE)
3234 return FAILURE;
3236 if (rank_check (values, 0, 1) == FAILURE)
3237 return FAILURE;
3239 if (variable_check (values, 0) == FAILURE)
3240 return FAILURE;
3242 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3243 return FAILURE;
3245 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3246 return FAILURE;
3248 return SUCCESS;
3253 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3255 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3256 return FAILURE;
3258 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3259 return FAILURE;
3261 if (scalar_check (time, 0) == FAILURE)
3262 return FAILURE;
3264 if (array_check (values, 1) == FAILURE)
3265 return FAILURE;
3267 if (rank_check (values, 1, 1) == FAILURE)
3268 return FAILURE;
3270 if (variable_check (values, 1) == FAILURE)
3271 return FAILURE;
3273 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3274 return FAILURE;
3276 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3277 return FAILURE;
3279 return SUCCESS;
3284 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3286 if (scalar_check (unit, 0) == FAILURE)
3287 return FAILURE;
3289 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3290 return FAILURE;
3292 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3293 return FAILURE;
3295 return SUCCESS;
3300 gfc_check_isatty (gfc_expr *unit)
3302 if (unit == NULL)
3303 return FAILURE;
3305 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3306 return FAILURE;
3308 if (scalar_check (unit, 0) == FAILURE)
3309 return FAILURE;
3311 return SUCCESS;
3316 gfc_check_perror (gfc_expr *string)
3318 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3319 return FAILURE;
3321 return SUCCESS;
3326 gfc_check_umask (gfc_expr *mask)
3328 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3329 return FAILURE;
3331 if (scalar_check (mask, 0) == FAILURE)
3332 return FAILURE;
3334 return SUCCESS;
3339 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3341 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3342 return FAILURE;
3344 if (scalar_check (mask, 0) == FAILURE)
3345 return FAILURE;
3347 if (old == NULL)
3348 return SUCCESS;
3350 if (scalar_check (old, 1) == FAILURE)
3351 return FAILURE;
3353 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3354 return FAILURE;
3356 return SUCCESS;
3361 gfc_check_unlink (gfc_expr *name)
3363 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3364 return FAILURE;
3366 return SUCCESS;
3371 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3373 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3374 return FAILURE;
3376 if (status == NULL)
3377 return SUCCESS;
3379 if (scalar_check (status, 1) == FAILURE)
3380 return FAILURE;
3382 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3383 return FAILURE;
3385 return SUCCESS;
3390 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3392 if (scalar_check (number, 0) == FAILURE)
3393 return FAILURE;
3395 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3396 return FAILURE;
3398 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3400 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3401 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3402 gfc_current_intrinsic, &handler->where);
3403 return FAILURE;
3406 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3407 return FAILURE;
3409 return SUCCESS;
3414 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3416 if (scalar_check (number, 0) == FAILURE)
3417 return FAILURE;
3419 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3420 return FAILURE;
3422 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3424 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3425 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3426 gfc_current_intrinsic, &handler->where);
3427 return FAILURE;
3430 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3431 return FAILURE;
3433 if (status == NULL)
3434 return SUCCESS;
3436 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3437 return FAILURE;
3439 if (scalar_check (status, 2) == FAILURE)
3440 return FAILURE;
3442 return SUCCESS;
3447 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
3449 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3450 return FAILURE;
3452 if (scalar_check (status, 1) == FAILURE)
3453 return FAILURE;
3455 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3456 return FAILURE;
3458 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3459 return FAILURE;
3461 return SUCCESS;
3465 /* This is used for the GNU intrinsics AND, OR and XOR. */
3467 gfc_check_and (gfc_expr *i, gfc_expr *j)
3469 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3471 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3472 "or LOGICAL", gfc_current_intrinsic_arg[0],
3473 gfc_current_intrinsic, &i->where);
3474 return FAILURE;
3477 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3479 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3480 "or LOGICAL", gfc_current_intrinsic_arg[1],
3481 gfc_current_intrinsic, &j->where);
3482 return FAILURE;
3485 if (i->ts.type != j->ts.type)
3487 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3488 "have the same type", gfc_current_intrinsic_arg[0],
3489 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3490 &j->where);
3491 return FAILURE;
3494 if (scalar_check (i, 0) == FAILURE)
3495 return FAILURE;
3497 if (scalar_check (j, 1) == FAILURE)
3498 return FAILURE;
3500 return SUCCESS;