toplev.c (floor_log2, exact_log2): Don't define if __cplusplus.
[official-gcc.git] / gcc / fortran / check.c
blobfeb07f081f9e150456c3efd34c4a0335c99071e3
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 (a->ts.type != p->ts.type)
455 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
456 "have the same type", gfc_current_intrinsic_arg[0],
457 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
458 &p->where);
459 return FAILURE;
462 if (a->ts.kind != p->ts.kind)
464 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
465 &p->where) == FAILURE)
466 return FAILURE;
469 return SUCCESS;
474 gfc_check_associated (gfc_expr * pointer, gfc_expr * target)
476 symbol_attribute attr;
477 int i;
478 try t;
480 if (pointer->expr_type == EXPR_VARIABLE)
481 attr = gfc_variable_attr (pointer, NULL);
482 else if (pointer->expr_type == EXPR_FUNCTION)
483 attr = pointer->symtree->n.sym->attr;
484 else
485 gcc_assert (0); /* Pointer must be a variable or a function. */
487 if (!attr.pointer)
489 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
490 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
491 &pointer->where);
492 return FAILURE;
495 /* Target argument is optional. */
496 if (target == NULL)
497 return SUCCESS;
499 if (target->expr_type == EXPR_NULL)
501 gfc_error ("NULL pointer at %L is not permitted as actual argument "
502 "of '%s' intrinsic function",
503 &target->where, gfc_current_intrinsic);
504 return FAILURE;
507 if (target->expr_type == EXPR_VARIABLE)
508 attr = gfc_variable_attr (target, NULL);
509 else if (target->expr_type == EXPR_FUNCTION)
510 attr = target->symtree->n.sym->attr;
511 else
512 gcc_assert (0); /* Target must be a variable or a function. */
514 if (!attr.pointer && !attr.target)
516 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
517 "or a TARGET", gfc_current_intrinsic_arg[1],
518 gfc_current_intrinsic, &target->where);
519 return FAILURE;
522 t = SUCCESS;
523 if (same_type_check (pointer, 0, target, 1) == FAILURE)
524 t = FAILURE;
525 if (rank_check (target, 0, pointer->rank) == FAILURE)
526 t = FAILURE;
527 if (target->rank > 0)
529 for (i = 0; i < target->rank; i++)
530 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
532 gfc_error ("Array section with a vector subscript at %L shall not "
533 "be the target of a pointer",
534 &target->where);
535 t = FAILURE;
536 break;
539 return t;
544 gfc_check_atan2 (gfc_expr * y, gfc_expr * x)
546 if (type_check (y, 0, BT_REAL) == FAILURE)
547 return FAILURE;
548 if (same_type_check (y, 0, x, 1) == FAILURE)
549 return FAILURE;
551 return SUCCESS;
555 /* BESJN and BESYN functions. */
558 gfc_check_besn (gfc_expr * n, gfc_expr * x)
560 if (scalar_check (n, 0) == FAILURE)
561 return FAILURE;
563 if (type_check (n, 0, BT_INTEGER) == FAILURE)
564 return FAILURE;
566 if (scalar_check (x, 1) == FAILURE)
567 return FAILURE;
569 if (type_check (x, 1, BT_REAL) == FAILURE)
570 return FAILURE;
572 return SUCCESS;
577 gfc_check_btest (gfc_expr * i, gfc_expr * pos)
579 if (type_check (i, 0, BT_INTEGER) == FAILURE)
580 return FAILURE;
581 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
582 return FAILURE;
584 return SUCCESS;
589 gfc_check_char (gfc_expr * i, gfc_expr * kind)
591 if (type_check (i, 0, BT_INTEGER) == FAILURE)
592 return FAILURE;
593 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
594 return FAILURE;
596 return SUCCESS;
601 gfc_check_chdir (gfc_expr * dir)
603 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
604 return FAILURE;
606 return SUCCESS;
611 gfc_check_chdir_sub (gfc_expr * dir, gfc_expr * status)
613 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
614 return FAILURE;
616 if (status == NULL)
617 return SUCCESS;
619 if (type_check (status, 1, BT_INTEGER) == FAILURE)
620 return FAILURE;
622 if (scalar_check (status, 1) == FAILURE)
623 return FAILURE;
625 return SUCCESS;
630 gfc_check_cmplx (gfc_expr * x, gfc_expr * y, gfc_expr * kind)
632 if (numeric_check (x, 0) == FAILURE)
633 return FAILURE;
635 if (y != NULL)
637 if (numeric_check (y, 1) == FAILURE)
638 return FAILURE;
640 if (x->ts.type == BT_COMPLEX)
642 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
643 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
644 gfc_current_intrinsic, &y->where);
645 return FAILURE;
649 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
650 return FAILURE;
652 return SUCCESS;
657 gfc_check_complex (gfc_expr * x, gfc_expr * y)
659 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
661 gfc_error (
662 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
663 gfc_current_intrinsic_arg[0], gfc_current_intrinsic, &x->where);
664 return FAILURE;
666 if (scalar_check (x, 0) == FAILURE)
667 return FAILURE;
669 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
671 gfc_error (
672 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
673 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &y->where);
674 return FAILURE;
676 if (scalar_check (y, 1) == FAILURE)
677 return FAILURE;
679 return SUCCESS;
684 gfc_check_count (gfc_expr * mask, gfc_expr * dim)
686 if (logical_array_check (mask, 0) == FAILURE)
687 return FAILURE;
688 if (dim_check (dim, 1, 1) == FAILURE)
689 return FAILURE;
691 return SUCCESS;
696 gfc_check_cshift (gfc_expr * array, gfc_expr * shift, gfc_expr * dim)
698 if (array_check (array, 0) == FAILURE)
699 return FAILURE;
701 if (array->rank == 1)
703 if (scalar_check (shift, 1) == FAILURE)
704 return FAILURE;
706 else
708 /* TODO: more requirements on shift parameter. */
711 if (dim_check (dim, 2, 1) == FAILURE)
712 return FAILURE;
714 return SUCCESS;
719 gfc_check_ctime (gfc_expr * time)
721 if (scalar_check (time, 0) == FAILURE)
722 return FAILURE;
724 if (type_check (time, 0, BT_INTEGER) == FAILURE)
725 return FAILURE;
727 return SUCCESS;
732 gfc_check_dcmplx (gfc_expr * x, gfc_expr * y)
734 if (numeric_check (x, 0) == FAILURE)
735 return FAILURE;
737 if (y != NULL)
739 if (numeric_check (y, 1) == FAILURE)
740 return FAILURE;
742 if (x->ts.type == BT_COMPLEX)
744 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
745 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
746 gfc_current_intrinsic, &y->where);
747 return FAILURE;
751 return SUCCESS;
756 gfc_check_dble (gfc_expr * x)
758 if (numeric_check (x, 0) == FAILURE)
759 return FAILURE;
761 return SUCCESS;
766 gfc_check_digits (gfc_expr * x)
768 if (int_or_real_check (x, 0) == FAILURE)
769 return FAILURE;
771 return SUCCESS;
776 gfc_check_dot_product (gfc_expr * vector_a, gfc_expr * vector_b)
778 switch (vector_a->ts.type)
780 case BT_LOGICAL:
781 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
782 return FAILURE;
783 break;
785 case BT_INTEGER:
786 case BT_REAL:
787 case BT_COMPLEX:
788 if (numeric_check (vector_b, 1) == FAILURE)
789 return FAILURE;
790 break;
792 default:
793 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
794 "or LOGICAL", gfc_current_intrinsic_arg[0],
795 gfc_current_intrinsic, &vector_a->where);
796 return FAILURE;
799 if (rank_check (vector_a, 0, 1) == FAILURE)
800 return FAILURE;
802 if (rank_check (vector_b, 1, 1) == FAILURE)
803 return FAILURE;
805 return SUCCESS;
810 gfc_check_eoshift (gfc_expr * array, gfc_expr * shift, gfc_expr * boundary,
811 gfc_expr * dim)
813 if (array_check (array, 0) == FAILURE)
814 return FAILURE;
816 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
817 return FAILURE;
819 if (array->rank == 1)
821 if (scalar_check (shift, 2) == FAILURE)
822 return FAILURE;
824 else
826 /* TODO: more weird restrictions on shift. */
829 if (boundary != NULL)
831 if (same_type_check (array, 0, boundary, 2) == FAILURE)
832 return FAILURE;
834 /* TODO: more restrictions on boundary. */
837 if (dim_check (dim, 1, 1) == FAILURE)
838 return FAILURE;
840 return SUCCESS;
844 /* A single complex argument. */
847 gfc_check_fn_c (gfc_expr * a)
849 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
850 return FAILURE;
852 return SUCCESS;
856 /* A single real argument. */
859 gfc_check_fn_r (gfc_expr * a)
861 if (type_check (a, 0, BT_REAL) == FAILURE)
862 return FAILURE;
864 return SUCCESS;
868 /* A single real or complex argument. */
871 gfc_check_fn_rc (gfc_expr * a)
873 if (real_or_complex_check (a, 0) == FAILURE)
874 return FAILURE;
876 return SUCCESS;
881 gfc_check_fnum (gfc_expr * unit)
883 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
884 return FAILURE;
886 if (scalar_check (unit, 0) == FAILURE)
887 return FAILURE;
889 return SUCCESS;
893 /* This is used for the g77 one-argument Bessel functions, and the
894 error function. */
897 gfc_check_g77_math1 (gfc_expr * x)
899 if (scalar_check (x, 0) == FAILURE)
900 return FAILURE;
902 if (type_check (x, 0, BT_REAL) == FAILURE)
903 return FAILURE;
905 return SUCCESS;
910 gfc_check_huge (gfc_expr * x)
912 if (int_or_real_check (x, 0) == FAILURE)
913 return FAILURE;
915 return SUCCESS;
919 /* Check that the single argument is an integer. */
922 gfc_check_i (gfc_expr * i)
924 if (type_check (i, 0, BT_INTEGER) == FAILURE)
925 return FAILURE;
927 return SUCCESS;
932 gfc_check_iand (gfc_expr * i, gfc_expr * j)
934 if (type_check (i, 0, BT_INTEGER) == FAILURE)
935 return FAILURE;
937 if (type_check (j, 1, BT_INTEGER) == FAILURE)
938 return FAILURE;
940 if (i->ts.kind != j->ts.kind)
942 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
943 &i->where) == FAILURE)
944 return FAILURE;
947 return SUCCESS;
952 gfc_check_ibclr (gfc_expr * i, gfc_expr * pos)
954 if (type_check (i, 0, BT_INTEGER) == FAILURE)
955 return FAILURE;
957 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
958 return FAILURE;
960 return SUCCESS;
965 gfc_check_ibits (gfc_expr * i, gfc_expr * pos, gfc_expr * len)
967 if (type_check (i, 0, BT_INTEGER) == FAILURE)
968 return FAILURE;
970 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
971 return FAILURE;
973 if (type_check (len, 2, BT_INTEGER) == FAILURE)
974 return FAILURE;
976 return SUCCESS;
981 gfc_check_ibset (gfc_expr * i, gfc_expr * pos)
983 if (type_check (i, 0, BT_INTEGER) == FAILURE)
984 return FAILURE;
986 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
987 return FAILURE;
989 return SUCCESS;
994 gfc_check_ichar_iachar (gfc_expr * c)
996 int i;
998 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
999 return FAILURE;
1001 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1003 gfc_expr *start;
1004 gfc_expr *end;
1005 gfc_ref *ref;
1007 /* Substring references don't have the charlength set. */
1008 ref = c->ref;
1009 while (ref && ref->type != REF_SUBSTRING)
1010 ref = ref->next;
1012 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1014 if (!ref)
1016 /* Check that the argument is length one. Non-constant lengths
1017 can't be checked here, so assume thay are ok. */
1018 if (c->ts.cl && c->ts.cl->length)
1020 /* If we already have a length for this expression then use it. */
1021 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1022 return SUCCESS;
1023 i = mpz_get_si (c->ts.cl->length->value.integer);
1025 else
1026 return SUCCESS;
1028 else
1030 start = ref->u.ss.start;
1031 end = ref->u.ss.end;
1033 gcc_assert (start);
1034 if (end == NULL || end->expr_type != EXPR_CONSTANT
1035 || start->expr_type != EXPR_CONSTANT)
1036 return SUCCESS;
1038 i = mpz_get_si (end->value.integer) + 1
1039 - mpz_get_si (start->value.integer);
1042 else
1043 return SUCCESS;
1045 if (i != 1)
1047 gfc_error ("Argument of %s at %L must be of length one",
1048 gfc_current_intrinsic, &c->where);
1049 return FAILURE;
1052 return SUCCESS;
1057 gfc_check_idnint (gfc_expr * a)
1059 if (double_check (a, 0) == FAILURE)
1060 return FAILURE;
1062 return SUCCESS;
1067 gfc_check_ieor (gfc_expr * i, gfc_expr * j)
1069 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1070 return FAILURE;
1072 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1073 return FAILURE;
1075 if (i->ts.kind != j->ts.kind)
1077 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1078 &i->where) == FAILURE)
1079 return FAILURE;
1082 return SUCCESS;
1087 gfc_check_index (gfc_expr * string, gfc_expr * substring, gfc_expr * back)
1089 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1090 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1091 return FAILURE;
1094 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1095 return FAILURE;
1097 if (string->ts.kind != substring->ts.kind)
1099 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1100 "kind as '%s'", gfc_current_intrinsic_arg[1],
1101 gfc_current_intrinsic, &substring->where,
1102 gfc_current_intrinsic_arg[0]);
1103 return FAILURE;
1106 return SUCCESS;
1111 gfc_check_int (gfc_expr * x, gfc_expr * kind)
1113 if (numeric_check (x, 0) == FAILURE)
1114 return FAILURE;
1116 if (kind != NULL)
1118 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1119 return FAILURE;
1121 if (scalar_check (kind, 1) == FAILURE)
1122 return FAILURE;
1125 return SUCCESS;
1130 gfc_check_ior (gfc_expr * i, gfc_expr * j)
1132 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1133 return FAILURE;
1135 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1136 return FAILURE;
1138 if (i->ts.kind != j->ts.kind)
1140 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1141 &i->where) == FAILURE)
1142 return FAILURE;
1145 return SUCCESS;
1150 gfc_check_ishft (gfc_expr * i, gfc_expr * shift)
1152 if (type_check (i, 0, BT_INTEGER) == FAILURE
1153 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1154 return FAILURE;
1156 return SUCCESS;
1161 gfc_check_ishftc (gfc_expr * i, gfc_expr * shift, gfc_expr * size)
1163 if (type_check (i, 0, BT_INTEGER) == FAILURE
1164 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1165 return FAILURE;
1167 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1168 return FAILURE;
1170 return SUCCESS;
1175 gfc_check_kill (gfc_expr * pid, gfc_expr * sig)
1177 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1178 return FAILURE;
1180 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1181 return FAILURE;
1183 return SUCCESS;
1188 gfc_check_kill_sub (gfc_expr * pid, gfc_expr * sig, gfc_expr * status)
1190 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1191 return FAILURE;
1193 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1194 return FAILURE;
1196 if (status == NULL)
1197 return SUCCESS;
1199 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1200 return FAILURE;
1202 if (scalar_check (status, 2) == FAILURE)
1203 return FAILURE;
1205 return SUCCESS;
1210 gfc_check_kind (gfc_expr * x)
1212 if (x->ts.type == BT_DERIVED)
1214 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1215 "non-derived type", gfc_current_intrinsic_arg[0],
1216 gfc_current_intrinsic, &x->where);
1217 return FAILURE;
1220 return SUCCESS;
1225 gfc_check_lbound (gfc_expr * array, gfc_expr * dim)
1227 if (array_check (array, 0) == FAILURE)
1228 return FAILURE;
1230 if (dim != NULL)
1232 if (dim_check (dim, 1, 1) == FAILURE)
1233 return FAILURE;
1235 if (dim_rank_check (dim, array, 1) == FAILURE)
1236 return FAILURE;
1238 return SUCCESS;
1243 gfc_check_link (gfc_expr * path1, gfc_expr * path2)
1245 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1246 return FAILURE;
1248 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1249 return FAILURE;
1251 return SUCCESS;
1256 gfc_check_link_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1258 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1259 return FAILURE;
1261 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1262 return FAILURE;
1264 if (status == NULL)
1265 return SUCCESS;
1267 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1268 return FAILURE;
1270 if (scalar_check (status, 2) == FAILURE)
1271 return FAILURE;
1273 return SUCCESS;
1277 gfc_check_loc (gfc_expr *expr)
1279 return variable_check (expr, 0);
1284 gfc_check_symlnk (gfc_expr * path1, gfc_expr * path2)
1286 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1287 return FAILURE;
1289 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1290 return FAILURE;
1292 return SUCCESS;
1297 gfc_check_symlnk_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1299 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1300 return FAILURE;
1302 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1303 return FAILURE;
1305 if (status == NULL)
1306 return SUCCESS;
1308 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1309 return FAILURE;
1311 if (scalar_check (status, 2) == FAILURE)
1312 return FAILURE;
1314 return SUCCESS;
1319 gfc_check_logical (gfc_expr * a, gfc_expr * kind)
1321 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1322 return FAILURE;
1323 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1324 return FAILURE;
1326 return SUCCESS;
1330 /* Min/max family. */
1332 static try
1333 min_max_args (gfc_actual_arglist * arg)
1335 if (arg == NULL || arg->next == NULL)
1337 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1338 gfc_current_intrinsic, gfc_current_intrinsic_where);
1339 return FAILURE;
1342 return SUCCESS;
1346 static try
1347 check_rest (bt type, int kind, gfc_actual_arglist * arg)
1349 gfc_expr *x;
1350 int n;
1352 if (min_max_args (arg) == FAILURE)
1353 return FAILURE;
1355 n = 1;
1357 for (; arg; arg = arg->next, n++)
1359 x = arg->expr;
1360 if (x->ts.type != type || x->ts.kind != kind)
1362 if (x->ts.type == type)
1364 if (gfc_notify_std (GFC_STD_GNU,
1365 "Extension: Different type kinds at %L", &x->where)
1366 == FAILURE)
1367 return FAILURE;
1369 else
1371 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be %s(%d)",
1372 n, gfc_current_intrinsic, &x->where,
1373 gfc_basic_typename (type), kind);
1374 return FAILURE;
1379 return SUCCESS;
1384 gfc_check_min_max (gfc_actual_arglist * arg)
1386 gfc_expr *x;
1388 if (min_max_args (arg) == FAILURE)
1389 return FAILURE;
1391 x = arg->expr;
1393 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1395 gfc_error
1396 ("'a1' argument of '%s' intrinsic at %L must be INTEGER or REAL",
1397 gfc_current_intrinsic, &x->where);
1398 return FAILURE;
1401 return check_rest (x->ts.type, x->ts.kind, arg);
1406 gfc_check_min_max_integer (gfc_actual_arglist * arg)
1408 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1413 gfc_check_min_max_real (gfc_actual_arglist * arg)
1415 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1420 gfc_check_min_max_double (gfc_actual_arglist * arg)
1422 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1425 /* End of min/max family. */
1428 gfc_check_malloc (gfc_expr * size)
1430 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1431 return FAILURE;
1433 if (scalar_check (size, 0) == FAILURE)
1434 return FAILURE;
1436 return SUCCESS;
1441 gfc_check_matmul (gfc_expr * matrix_a, gfc_expr * matrix_b)
1443 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1445 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1446 "or LOGICAL", gfc_current_intrinsic_arg[0],
1447 gfc_current_intrinsic, &matrix_a->where);
1448 return FAILURE;
1451 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1453 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1454 "or LOGICAL", gfc_current_intrinsic_arg[1],
1455 gfc_current_intrinsic, &matrix_b->where);
1456 return FAILURE;
1459 switch (matrix_a->rank)
1461 case 1:
1462 if (rank_check (matrix_b, 1, 2) == FAILURE)
1463 return FAILURE;
1464 break;
1466 case 2:
1467 if (matrix_b->rank == 2)
1468 break;
1469 if (rank_check (matrix_b, 1, 1) == FAILURE)
1470 return FAILURE;
1471 break;
1473 default:
1474 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1475 "1 or 2", gfc_current_intrinsic_arg[0],
1476 gfc_current_intrinsic, &matrix_a->where);
1477 return FAILURE;
1480 return SUCCESS;
1484 /* Whoever came up with this interface was probably on something.
1485 The possibilities for the occupation of the second and third
1486 parameters are:
1488 Arg #2 Arg #3
1489 NULL NULL
1490 DIM NULL
1491 MASK NULL
1492 NULL MASK minloc(array, mask=m)
1493 DIM MASK
1495 I.e. in the case of minloc(array,mask), mask will be in the second
1496 position of the argument list and we'll have to fix that up. */
1499 gfc_check_minloc_maxloc (gfc_actual_arglist * ap)
1501 gfc_expr *a, *m, *d;
1503 a = ap->expr;
1504 if (int_or_real_check (a, 0) == FAILURE
1505 || array_check (a, 0) == FAILURE)
1506 return FAILURE;
1508 d = ap->next->expr;
1509 m = ap->next->next->expr;
1511 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1512 && ap->next->name == NULL)
1514 m = d;
1515 d = NULL;
1517 ap->next->expr = NULL;
1518 ap->next->next->expr = m;
1521 if (d != NULL
1522 && (scalar_check (d, 1) == FAILURE
1523 || type_check (d, 1, BT_INTEGER) == FAILURE))
1524 return FAILURE;
1526 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1527 return FAILURE;
1529 return SUCCESS;
1533 /* Similar to minloc/maxloc, the argument list might need to be
1534 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1535 difference is that MINLOC/MAXLOC take an additional KIND argument.
1536 The possibilities are:
1538 Arg #2 Arg #3
1539 NULL NULL
1540 DIM NULL
1541 MASK NULL
1542 NULL MASK minval(array, mask=m)
1543 DIM MASK
1545 I.e. in the case of minval(array,mask), mask will be in the second
1546 position of the argument list and we'll have to fix that up. */
1548 static try
1549 check_reduction (gfc_actual_arglist * ap)
1551 gfc_expr *m, *d;
1553 d = ap->next->expr;
1554 m = ap->next->next->expr;
1556 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1557 && ap->next->name == NULL)
1559 m = d;
1560 d = NULL;
1562 ap->next->expr = NULL;
1563 ap->next->next->expr = m;
1566 if (d != NULL
1567 && (scalar_check (d, 1) == FAILURE
1568 || type_check (d, 1, BT_INTEGER) == FAILURE))
1569 return FAILURE;
1571 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1572 return FAILURE;
1574 return SUCCESS;
1579 gfc_check_minval_maxval (gfc_actual_arglist * ap)
1581 if (int_or_real_check (ap->expr, 0) == FAILURE
1582 || array_check (ap->expr, 0) == FAILURE)
1583 return FAILURE;
1585 return check_reduction (ap);
1590 gfc_check_product_sum (gfc_actual_arglist * ap)
1592 if (numeric_check (ap->expr, 0) == FAILURE
1593 || array_check (ap->expr, 0) == FAILURE)
1594 return FAILURE;
1596 return check_reduction (ap);
1601 gfc_check_merge (gfc_expr * tsource, gfc_expr * fsource, gfc_expr * mask)
1603 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1604 return FAILURE;
1606 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1607 return FAILURE;
1609 return SUCCESS;
1614 gfc_check_nearest (gfc_expr * x, gfc_expr * s)
1616 if (type_check (x, 0, BT_REAL) == FAILURE)
1617 return FAILURE;
1619 if (type_check (s, 1, BT_REAL) == FAILURE)
1620 return FAILURE;
1622 return SUCCESS;
1627 gfc_check_null (gfc_expr * mold)
1629 symbol_attribute attr;
1631 if (mold == NULL)
1632 return SUCCESS;
1634 if (variable_check (mold, 0) == FAILURE)
1635 return FAILURE;
1637 attr = gfc_variable_attr (mold, NULL);
1639 if (!attr.pointer)
1641 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1642 gfc_current_intrinsic_arg[0],
1643 gfc_current_intrinsic, &mold->where);
1644 return FAILURE;
1647 return SUCCESS;
1652 gfc_check_pack (gfc_expr * array, gfc_expr * mask, gfc_expr * vector)
1654 if (array_check (array, 0) == FAILURE)
1655 return FAILURE;
1657 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1658 return FAILURE;
1660 if (mask->rank != 0 && mask->rank != array->rank)
1662 gfc_error ("'%s' argument of '%s' intrinsic at %L must be conformable "
1663 "with '%s' argument", gfc_current_intrinsic_arg[0],
1664 gfc_current_intrinsic, &array->where,
1665 gfc_current_intrinsic_arg[1]);
1666 return FAILURE;
1669 if (vector != NULL)
1671 if (same_type_check (array, 0, vector, 2) == FAILURE)
1672 return FAILURE;
1674 if (rank_check (vector, 2, 1) == FAILURE)
1675 return FAILURE;
1677 /* TODO: More constraints here. */
1680 return SUCCESS;
1685 gfc_check_precision (gfc_expr * x)
1687 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1689 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1690 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1691 gfc_current_intrinsic, &x->where);
1692 return FAILURE;
1695 return SUCCESS;
1700 gfc_check_present (gfc_expr * a)
1702 gfc_symbol *sym;
1704 if (variable_check (a, 0) == FAILURE)
1705 return FAILURE;
1707 sym = a->symtree->n.sym;
1708 if (!sym->attr.dummy)
1710 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1711 "dummy variable", gfc_current_intrinsic_arg[0],
1712 gfc_current_intrinsic, &a->where);
1713 return FAILURE;
1716 if (!sym->attr.optional)
1718 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
1719 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
1720 gfc_current_intrinsic, &a->where);
1721 return FAILURE;
1724 return SUCCESS;
1729 gfc_check_radix (gfc_expr * x)
1731 if (int_or_real_check (x, 0) == FAILURE)
1732 return FAILURE;
1734 return SUCCESS;
1739 gfc_check_range (gfc_expr * x)
1741 if (numeric_check (x, 0) == FAILURE)
1742 return FAILURE;
1744 return SUCCESS;
1748 /* real, float, sngl. */
1750 gfc_check_real (gfc_expr * a, gfc_expr * kind)
1752 if (numeric_check (a, 0) == FAILURE)
1753 return FAILURE;
1755 if (kind_check (kind, 1, BT_REAL) == FAILURE)
1756 return FAILURE;
1758 return SUCCESS;
1763 gfc_check_rename (gfc_expr * path1, gfc_expr * path2)
1765 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1766 return FAILURE;
1768 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1769 return FAILURE;
1771 return SUCCESS;
1776 gfc_check_rename_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1778 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1779 return FAILURE;
1781 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1782 return FAILURE;
1784 if (status == NULL)
1785 return SUCCESS;
1787 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1788 return FAILURE;
1790 if (scalar_check (status, 2) == FAILURE)
1791 return FAILURE;
1793 return SUCCESS;
1798 gfc_check_repeat (gfc_expr * x, gfc_expr * y)
1800 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1801 return FAILURE;
1803 if (scalar_check (x, 0) == FAILURE)
1804 return FAILURE;
1806 if (type_check (y, 0, BT_INTEGER) == FAILURE)
1807 return FAILURE;
1809 if (scalar_check (y, 1) == FAILURE)
1810 return FAILURE;
1812 return SUCCESS;
1817 gfc_check_reshape (gfc_expr * source, gfc_expr * shape,
1818 gfc_expr * pad, gfc_expr * order)
1820 mpz_t size;
1821 int m;
1823 if (array_check (source, 0) == FAILURE)
1824 return FAILURE;
1826 if (rank_check (shape, 1, 1) == FAILURE)
1827 return FAILURE;
1829 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
1830 return FAILURE;
1832 if (gfc_array_size (shape, &size) != SUCCESS)
1834 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
1835 "array of constant size", &shape->where);
1836 return FAILURE;
1839 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
1840 mpz_clear (size);
1842 if (m > 0)
1844 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
1845 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
1846 return FAILURE;
1849 if (pad != NULL)
1851 if (same_type_check (source, 0, pad, 2) == FAILURE)
1852 return FAILURE;
1853 if (array_check (pad, 2) == FAILURE)
1854 return FAILURE;
1857 if (order != NULL && array_check (order, 3) == FAILURE)
1858 return FAILURE;
1860 return SUCCESS;
1865 gfc_check_scale (gfc_expr * x, gfc_expr * i)
1867 if (type_check (x, 0, BT_REAL) == FAILURE)
1868 return FAILURE;
1870 if (type_check (i, 1, BT_INTEGER) == FAILURE)
1871 return FAILURE;
1873 return SUCCESS;
1878 gfc_check_scan (gfc_expr * x, gfc_expr * y, gfc_expr * z)
1880 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1881 return FAILURE;
1883 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
1884 return FAILURE;
1886 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
1887 return FAILURE;
1889 if (same_type_check (x, 0, y, 1) == FAILURE)
1890 return FAILURE;
1892 return SUCCESS;
1897 gfc_check_secnds (gfc_expr * r)
1900 if (type_check (r, 0, BT_REAL) == FAILURE)
1901 return FAILURE;
1903 if (kind_value_check (r, 0, 4) == FAILURE)
1904 return FAILURE;
1906 if (scalar_check (r, 0) == FAILURE)
1907 return FAILURE;
1909 return SUCCESS;
1914 gfc_check_selected_int_kind (gfc_expr * r)
1917 if (type_check (r, 0, BT_INTEGER) == FAILURE)
1918 return FAILURE;
1920 if (scalar_check (r, 0) == FAILURE)
1921 return FAILURE;
1923 return SUCCESS;
1928 gfc_check_selected_real_kind (gfc_expr * p, gfc_expr * r)
1930 if (p == NULL && r == NULL)
1932 gfc_error ("Missing arguments to %s intrinsic at %L",
1933 gfc_current_intrinsic, gfc_current_intrinsic_where);
1935 return FAILURE;
1938 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
1939 return FAILURE;
1941 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
1942 return FAILURE;
1944 return SUCCESS;
1949 gfc_check_set_exponent (gfc_expr * x, gfc_expr * i)
1951 if (type_check (x, 0, BT_REAL) == FAILURE)
1952 return FAILURE;
1954 if (type_check (i, 1, BT_INTEGER) == FAILURE)
1955 return FAILURE;
1957 return SUCCESS;
1962 gfc_check_shape (gfc_expr * source)
1964 gfc_array_ref *ar;
1966 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
1967 return SUCCESS;
1969 ar = gfc_find_array_ref (source);
1971 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
1973 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
1974 "an assumed size array", &source->where);
1975 return FAILURE;
1978 return SUCCESS;
1983 gfc_check_sign (gfc_expr * a, gfc_expr * b)
1985 if (int_or_real_check (a, 0) == FAILURE)
1986 return FAILURE;
1988 if (same_type_check (a, 0, b, 1) == FAILURE)
1989 return FAILURE;
1991 return SUCCESS;
1996 gfc_check_size (gfc_expr * array, gfc_expr * dim)
1998 if (array_check (array, 0) == FAILURE)
1999 return FAILURE;
2001 if (dim != NULL)
2003 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2004 return FAILURE;
2006 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2007 return FAILURE;
2009 if (dim_rank_check (dim, array, 0) == FAILURE)
2010 return FAILURE;
2013 return SUCCESS;
2018 gfc_check_sleep_sub (gfc_expr * seconds)
2020 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2021 return FAILURE;
2023 if (scalar_check (seconds, 0) == FAILURE)
2024 return FAILURE;
2026 return SUCCESS;
2031 gfc_check_spread (gfc_expr * source, gfc_expr * dim, gfc_expr * ncopies)
2033 if (source->rank >= GFC_MAX_DIMENSIONS)
2035 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2036 "than rank %d", gfc_current_intrinsic_arg[0],
2037 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2039 return FAILURE;
2042 if (dim_check (dim, 1, 0) == FAILURE)
2043 return FAILURE;
2045 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2046 return FAILURE;
2048 if (scalar_check (ncopies, 2) == FAILURE)
2049 return FAILURE;
2051 return SUCCESS;
2055 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2056 functions). */
2058 gfc_check_fgetputc_sub (gfc_expr * unit, gfc_expr * c, gfc_expr * status)
2060 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2061 return FAILURE;
2063 if (scalar_check (unit, 0) == FAILURE)
2064 return FAILURE;
2066 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2067 return FAILURE;
2069 if (status == NULL)
2070 return SUCCESS;
2072 if (type_check (status, 2, BT_INTEGER) == FAILURE
2073 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2074 || scalar_check (status, 2) == FAILURE)
2075 return FAILURE;
2077 return SUCCESS;
2082 gfc_check_fgetputc (gfc_expr * unit, gfc_expr * c)
2084 return gfc_check_fgetputc_sub (unit, c, NULL);
2089 gfc_check_fgetput_sub (gfc_expr * c, gfc_expr * status)
2091 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2092 return FAILURE;
2094 if (status == NULL)
2095 return SUCCESS;
2097 if (type_check (status, 1, BT_INTEGER) == FAILURE
2098 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2099 || scalar_check (status, 1) == FAILURE)
2100 return FAILURE;
2102 return SUCCESS;
2107 gfc_check_fgetput (gfc_expr * c)
2109 return gfc_check_fgetput_sub (c, NULL);
2114 gfc_check_fstat (gfc_expr * unit, gfc_expr * array)
2116 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2117 return FAILURE;
2119 if (scalar_check (unit, 0) == FAILURE)
2120 return FAILURE;
2122 if (type_check (array, 1, BT_INTEGER) == FAILURE
2123 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2124 return FAILURE;
2126 if (array_check (array, 1) == FAILURE)
2127 return FAILURE;
2129 return SUCCESS;
2134 gfc_check_fstat_sub (gfc_expr * unit, gfc_expr * array, gfc_expr * status)
2136 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2137 return FAILURE;
2139 if (scalar_check (unit, 0) == FAILURE)
2140 return FAILURE;
2142 if (type_check (array, 1, BT_INTEGER) == FAILURE
2143 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2144 return FAILURE;
2146 if (array_check (array, 1) == FAILURE)
2147 return FAILURE;
2149 if (status == NULL)
2150 return SUCCESS;
2152 if (type_check (status, 2, BT_INTEGER) == FAILURE
2153 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2154 return FAILURE;
2156 if (scalar_check (status, 2) == FAILURE)
2157 return FAILURE;
2159 return SUCCESS;
2164 gfc_check_ftell (gfc_expr * unit)
2166 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2167 return FAILURE;
2169 if (scalar_check (unit, 0) == FAILURE)
2170 return FAILURE;
2172 return SUCCESS;
2177 gfc_check_ftell_sub (gfc_expr * unit, gfc_expr * offset)
2179 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2180 return FAILURE;
2182 if (scalar_check (unit, 0) == FAILURE)
2183 return FAILURE;
2185 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2186 return FAILURE;
2188 if (scalar_check (offset, 1) == FAILURE)
2189 return FAILURE;
2191 return SUCCESS;
2196 gfc_check_stat (gfc_expr * name, gfc_expr * array)
2198 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2199 return FAILURE;
2201 if (type_check (array, 1, BT_INTEGER) == FAILURE
2202 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2203 return FAILURE;
2205 if (array_check (array, 1) == FAILURE)
2206 return FAILURE;
2208 return SUCCESS;
2213 gfc_check_stat_sub (gfc_expr * name, gfc_expr * array, gfc_expr * status)
2215 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2216 return FAILURE;
2218 if (type_check (array, 1, BT_INTEGER) == FAILURE
2219 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2220 return FAILURE;
2222 if (array_check (array, 1) == FAILURE)
2223 return FAILURE;
2225 if (status == NULL)
2226 return SUCCESS;
2228 if (type_check (status, 2, BT_INTEGER) == FAILURE
2229 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2230 return FAILURE;
2232 if (scalar_check (status, 2) == FAILURE)
2233 return FAILURE;
2235 return SUCCESS;
2240 gfc_check_transfer (gfc_expr * source ATTRIBUTE_UNUSED,
2241 gfc_expr * mold ATTRIBUTE_UNUSED,
2242 gfc_expr * size)
2244 if (size != NULL)
2246 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2247 return FAILURE;
2249 if (scalar_check (size, 2) == FAILURE)
2250 return FAILURE;
2252 if (nonoptional_check (size, 2) == FAILURE)
2253 return FAILURE;
2256 return SUCCESS;
2261 gfc_check_transpose (gfc_expr * matrix)
2263 if (rank_check (matrix, 0, 2) == FAILURE)
2264 return FAILURE;
2266 return SUCCESS;
2271 gfc_check_ubound (gfc_expr * array, gfc_expr * dim)
2273 if (array_check (array, 0) == FAILURE)
2274 return FAILURE;
2276 if (dim != NULL)
2278 if (dim_check (dim, 1, 1) == FAILURE)
2279 return FAILURE;
2281 if (dim_rank_check (dim, array, 0) == FAILURE)
2282 return FAILURE;
2285 return SUCCESS;
2290 gfc_check_unpack (gfc_expr * vector, gfc_expr * mask, gfc_expr * field)
2292 if (rank_check (vector, 0, 1) == FAILURE)
2293 return FAILURE;
2295 if (array_check (mask, 1) == FAILURE)
2296 return FAILURE;
2298 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2299 return FAILURE;
2301 if (same_type_check (vector, 0, field, 2) == FAILURE)
2302 return FAILURE;
2304 return SUCCESS;
2309 gfc_check_verify (gfc_expr * x, gfc_expr * y, gfc_expr * z)
2311 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2312 return FAILURE;
2314 if (same_type_check (x, 0, y, 1) == FAILURE)
2315 return FAILURE;
2317 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2318 return FAILURE;
2320 return SUCCESS;
2325 gfc_check_trim (gfc_expr * x)
2327 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2328 return FAILURE;
2330 if (scalar_check (x, 0) == FAILURE)
2331 return FAILURE;
2333 return SUCCESS;
2338 gfc_check_ttynam (gfc_expr * unit)
2340 if (scalar_check (unit, 0) == FAILURE)
2341 return FAILURE;
2343 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2344 return FAILURE;
2346 return SUCCESS;
2350 /* Common check function for the half a dozen intrinsics that have a
2351 single real argument. */
2354 gfc_check_x (gfc_expr * x)
2356 if (type_check (x, 0, BT_REAL) == FAILURE)
2357 return FAILURE;
2359 return SUCCESS;
2363 /************* Check functions for intrinsic subroutines *************/
2366 gfc_check_cpu_time (gfc_expr * time)
2368 if (scalar_check (time, 0) == FAILURE)
2369 return FAILURE;
2371 if (type_check (time, 0, BT_REAL) == FAILURE)
2372 return FAILURE;
2374 if (variable_check (time, 0) == FAILURE)
2375 return FAILURE;
2377 return SUCCESS;
2382 gfc_check_date_and_time (gfc_expr * date, gfc_expr * time,
2383 gfc_expr * zone, gfc_expr * values)
2385 if (date != NULL)
2387 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2388 return FAILURE;
2389 if (scalar_check (date, 0) == FAILURE)
2390 return FAILURE;
2391 if (variable_check (date, 0) == FAILURE)
2392 return FAILURE;
2395 if (time != NULL)
2397 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2398 return FAILURE;
2399 if (scalar_check (time, 1) == FAILURE)
2400 return FAILURE;
2401 if (variable_check (time, 1) == FAILURE)
2402 return FAILURE;
2405 if (zone != NULL)
2407 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2408 return FAILURE;
2409 if (scalar_check (zone, 2) == FAILURE)
2410 return FAILURE;
2411 if (variable_check (zone, 2) == FAILURE)
2412 return FAILURE;
2415 if (values != NULL)
2417 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2418 return FAILURE;
2419 if (array_check (values, 3) == FAILURE)
2420 return FAILURE;
2421 if (rank_check (values, 3, 1) == FAILURE)
2422 return FAILURE;
2423 if (variable_check (values, 3) == FAILURE)
2424 return FAILURE;
2427 return SUCCESS;
2432 gfc_check_mvbits (gfc_expr * from, gfc_expr * frompos, gfc_expr * len,
2433 gfc_expr * to, gfc_expr * topos)
2435 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2436 return FAILURE;
2438 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2439 return FAILURE;
2441 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2442 return FAILURE;
2444 if (same_type_check (from, 0, to, 3) == FAILURE)
2445 return FAILURE;
2447 if (variable_check (to, 3) == FAILURE)
2448 return FAILURE;
2450 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2451 return FAILURE;
2453 return SUCCESS;
2458 gfc_check_random_number (gfc_expr * harvest)
2460 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2461 return FAILURE;
2463 if (variable_check (harvest, 0) == FAILURE)
2464 return FAILURE;
2466 return SUCCESS;
2471 gfc_check_random_seed (gfc_expr * size, gfc_expr * put, gfc_expr * get)
2473 if (size != NULL)
2475 if (scalar_check (size, 0) == FAILURE)
2476 return FAILURE;
2478 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2479 return FAILURE;
2481 if (variable_check (size, 0) == FAILURE)
2482 return FAILURE;
2484 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2485 return FAILURE;
2488 if (put != NULL)
2491 if (size != NULL)
2492 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2493 &put->where);
2495 if (array_check (put, 1) == FAILURE)
2496 return FAILURE;
2498 if (rank_check (put, 1, 1) == FAILURE)
2499 return FAILURE;
2501 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2502 return FAILURE;
2504 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2505 return FAILURE;
2508 if (get != NULL)
2511 if (size != NULL || put != NULL)
2512 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2513 &get->where);
2515 if (array_check (get, 2) == FAILURE)
2516 return FAILURE;
2518 if (rank_check (get, 2, 1) == FAILURE)
2519 return FAILURE;
2521 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2522 return FAILURE;
2524 if (variable_check (get, 2) == FAILURE)
2525 return FAILURE;
2527 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2528 return FAILURE;
2531 return SUCCESS;
2535 gfc_check_second_sub (gfc_expr * time)
2537 if (scalar_check (time, 0) == FAILURE)
2538 return FAILURE;
2540 if (type_check (time, 0, BT_REAL) == FAILURE)
2541 return FAILURE;
2543 if (kind_value_check(time, 0, 4) == FAILURE)
2544 return FAILURE;
2546 return SUCCESS;
2550 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2551 count, count_rate, and count_max are all optional arguments */
2554 gfc_check_system_clock (gfc_expr * count, gfc_expr * count_rate,
2555 gfc_expr * count_max)
2557 if (count != NULL)
2559 if (scalar_check (count, 0) == FAILURE)
2560 return FAILURE;
2562 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2563 return FAILURE;
2565 if (variable_check (count, 0) == FAILURE)
2566 return FAILURE;
2569 if (count_rate != NULL)
2571 if (scalar_check (count_rate, 1) == FAILURE)
2572 return FAILURE;
2574 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2575 return FAILURE;
2577 if (variable_check (count_rate, 1) == FAILURE)
2578 return FAILURE;
2580 if (count != NULL
2581 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2582 return FAILURE;
2586 if (count_max != NULL)
2588 if (scalar_check (count_max, 2) == FAILURE)
2589 return FAILURE;
2591 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2592 return FAILURE;
2594 if (variable_check (count_max, 2) == FAILURE)
2595 return FAILURE;
2597 if (count != NULL
2598 && same_type_check (count, 0, count_max, 2) == FAILURE)
2599 return FAILURE;
2601 if (count_rate != NULL
2602 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2603 return FAILURE;
2606 return SUCCESS;
2610 gfc_check_irand (gfc_expr * x)
2612 if (x == NULL)
2613 return SUCCESS;
2615 if (scalar_check (x, 0) == FAILURE)
2616 return FAILURE;
2618 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2619 return FAILURE;
2621 if (kind_value_check(x, 0, 4) == FAILURE)
2622 return FAILURE;
2624 return SUCCESS;
2629 gfc_check_alarm_sub (gfc_expr * seconds, gfc_expr * handler, gfc_expr * status)
2631 if (scalar_check (seconds, 0) == FAILURE)
2632 return FAILURE;
2634 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2635 return FAILURE;
2637 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2639 gfc_error (
2640 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
2641 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
2642 return FAILURE;
2645 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2646 return FAILURE;
2648 if (status == NULL)
2649 return SUCCESS;
2651 if (scalar_check (status, 2) == FAILURE)
2652 return FAILURE;
2654 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2655 return FAILURE;
2657 return SUCCESS;
2662 gfc_check_rand (gfc_expr * x)
2664 if (x == NULL)
2665 return SUCCESS;
2667 if (scalar_check (x, 0) == FAILURE)
2668 return FAILURE;
2670 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2671 return FAILURE;
2673 if (kind_value_check(x, 0, 4) == FAILURE)
2674 return FAILURE;
2676 return SUCCESS;
2680 gfc_check_srand (gfc_expr * x)
2682 if (scalar_check (x, 0) == FAILURE)
2683 return FAILURE;
2685 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2686 return FAILURE;
2688 if (kind_value_check(x, 0, 4) == FAILURE)
2689 return FAILURE;
2691 return SUCCESS;
2695 gfc_check_ctime_sub (gfc_expr * time, gfc_expr * result)
2697 if (scalar_check (time, 0) == FAILURE)
2698 return FAILURE;
2700 if (type_check (time, 0, BT_INTEGER) == FAILURE)
2701 return FAILURE;
2703 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
2704 return FAILURE;
2706 return SUCCESS;
2710 gfc_check_etime (gfc_expr * x)
2712 if (array_check (x, 0) == FAILURE)
2713 return FAILURE;
2715 if (rank_check (x, 0, 1) == FAILURE)
2716 return FAILURE;
2718 if (variable_check (x, 0) == FAILURE)
2719 return FAILURE;
2721 if (type_check (x, 0, BT_REAL) == FAILURE)
2722 return FAILURE;
2724 if (kind_value_check(x, 0, 4) == FAILURE)
2725 return FAILURE;
2727 return SUCCESS;
2731 gfc_check_etime_sub (gfc_expr * values, gfc_expr * time)
2733 if (array_check (values, 0) == FAILURE)
2734 return FAILURE;
2736 if (rank_check (values, 0, 1) == FAILURE)
2737 return FAILURE;
2739 if (variable_check (values, 0) == FAILURE)
2740 return FAILURE;
2742 if (type_check (values, 0, BT_REAL) == FAILURE)
2743 return FAILURE;
2745 if (kind_value_check(values, 0, 4) == FAILURE)
2746 return FAILURE;
2748 if (scalar_check (time, 1) == FAILURE)
2749 return FAILURE;
2751 if (type_check (time, 1, BT_REAL) == FAILURE)
2752 return FAILURE;
2754 if (kind_value_check(time, 1, 4) == FAILURE)
2755 return FAILURE;
2757 return SUCCESS;
2762 gfc_check_fdate_sub (gfc_expr * date)
2764 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2765 return FAILURE;
2767 return SUCCESS;
2772 gfc_check_gerror (gfc_expr * msg)
2774 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
2775 return FAILURE;
2777 return SUCCESS;
2782 gfc_check_getcwd_sub (gfc_expr * cwd, gfc_expr * status)
2784 if (type_check (cwd, 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_getlog (gfc_expr * msg)
2803 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
2804 return FAILURE;
2806 return SUCCESS;
2811 gfc_check_exit (gfc_expr * status)
2813 if (status == NULL)
2814 return SUCCESS;
2816 if (type_check (status, 0, BT_INTEGER) == FAILURE)
2817 return FAILURE;
2819 if (scalar_check (status, 0) == FAILURE)
2820 return FAILURE;
2822 return SUCCESS;
2827 gfc_check_flush (gfc_expr * unit)
2829 if (unit == NULL)
2830 return SUCCESS;
2832 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2833 return FAILURE;
2835 if (scalar_check (unit, 0) == FAILURE)
2836 return FAILURE;
2838 return SUCCESS;
2843 gfc_check_free (gfc_expr * i)
2845 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2846 return FAILURE;
2848 if (scalar_check (i, 0) == FAILURE)
2849 return FAILURE;
2851 return SUCCESS;
2856 gfc_check_hostnm (gfc_expr * name)
2858 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2859 return FAILURE;
2861 return SUCCESS;
2866 gfc_check_hostnm_sub (gfc_expr * name, gfc_expr * status)
2868 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2869 return FAILURE;
2871 if (status == NULL)
2872 return SUCCESS;
2874 if (scalar_check (status, 1) == FAILURE)
2875 return FAILURE;
2877 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2878 return FAILURE;
2880 return SUCCESS;
2885 gfc_check_ttynam_sub (gfc_expr * unit, gfc_expr * name)
2887 if (scalar_check (unit, 0) == FAILURE)
2888 return FAILURE;
2890 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2891 return FAILURE;
2893 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
2894 return FAILURE;
2896 return SUCCESS;
2901 gfc_check_isatty (gfc_expr * unit)
2903 if (unit == NULL)
2904 return FAILURE;
2906 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2907 return FAILURE;
2909 if (scalar_check (unit, 0) == FAILURE)
2910 return FAILURE;
2912 return SUCCESS;
2917 gfc_check_perror (gfc_expr * string)
2919 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
2920 return FAILURE;
2922 return SUCCESS;
2927 gfc_check_umask (gfc_expr * mask)
2929 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
2930 return FAILURE;
2932 if (scalar_check (mask, 0) == FAILURE)
2933 return FAILURE;
2935 return SUCCESS;
2940 gfc_check_umask_sub (gfc_expr * mask, gfc_expr * old)
2942 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
2943 return FAILURE;
2945 if (scalar_check (mask, 0) == FAILURE)
2946 return FAILURE;
2948 if (old == NULL)
2949 return SUCCESS;
2951 if (scalar_check (old, 1) == FAILURE)
2952 return FAILURE;
2954 if (type_check (old, 1, BT_INTEGER) == FAILURE)
2955 return FAILURE;
2957 return SUCCESS;
2962 gfc_check_unlink (gfc_expr * name)
2964 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2965 return FAILURE;
2967 return SUCCESS;
2972 gfc_check_unlink_sub (gfc_expr * name, gfc_expr * status)
2974 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2975 return FAILURE;
2977 if (status == NULL)
2978 return SUCCESS;
2980 if (scalar_check (status, 1) == FAILURE)
2981 return FAILURE;
2983 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2984 return FAILURE;
2986 return SUCCESS;
2991 gfc_check_signal (gfc_expr * number, gfc_expr * handler)
2993 if (scalar_check (number, 0) == FAILURE)
2994 return FAILURE;
2996 if (type_check (number, 0, BT_INTEGER) == FAILURE)
2997 return FAILURE;
2999 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3001 gfc_error (
3002 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
3003 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
3004 return FAILURE;
3007 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3008 return FAILURE;
3010 return SUCCESS;
3015 gfc_check_signal_sub (gfc_expr * number, gfc_expr * handler, gfc_expr * status)
3017 if (scalar_check (number, 0) == FAILURE)
3018 return FAILURE;
3020 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3021 return FAILURE;
3023 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3025 gfc_error (
3026 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
3027 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
3028 return FAILURE;
3031 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3032 return FAILURE;
3034 if (status == NULL)
3035 return SUCCESS;
3037 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3038 return FAILURE;
3040 if (scalar_check (status, 2) == FAILURE)
3041 return FAILURE;
3043 return SUCCESS;
3048 gfc_check_system_sub (gfc_expr * cmd, gfc_expr * status)
3050 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3051 return FAILURE;
3053 if (scalar_check (status, 1) == FAILURE)
3054 return FAILURE;
3056 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3057 return FAILURE;
3059 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3060 return FAILURE;
3062 return SUCCESS;
3066 /* This is used for the GNU intrinsics AND, OR and XOR. */
3068 gfc_check_and (gfc_expr * i, gfc_expr * j)
3070 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3072 gfc_error (
3073 "'%s' argument of '%s' intrinsic at %L must be INTEGER or LOGICAL",
3074 gfc_current_intrinsic_arg[0], gfc_current_intrinsic, &i->where);
3075 return FAILURE;
3078 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3080 gfc_error (
3081 "'%s' argument of '%s' intrinsic at %L must be INTEGER or LOGICAL",
3082 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &j->where);
3083 return FAILURE;
3086 if (i->ts.type != j->ts.type)
3088 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3089 "have the same type", gfc_current_intrinsic_arg[0],
3090 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3091 &j->where);
3092 return FAILURE;
3095 if (scalar_check (i, 0) == FAILURE)
3096 return FAILURE;
3098 if (scalar_check (j, 1) == FAILURE)
3099 return FAILURE;
3101 return SUCCESS;