]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Check functions |
23a5b65a | 2 | Copyright (C) 2002-2014 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Andy Vaught & Katherine Holcomb |
4 | ||
9fc4d79b | 5 | This file is part of GCC. |
6de9cd9a | 6 | |
9fc4d79b TS |
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 | |
d234d788 | 9 | Software Foundation; either version 3, or (at your option) any later |
9fc4d79b | 10 | version. |
6de9cd9a | 11 | |
9fc4d79b TS |
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. | |
6de9cd9a DN |
16 | |
17 | You should have received a copy of the GNU General Public License | |
d234d788 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a DN |
20 | |
21 | ||
22 | /* These functions check to see if an argument list is compatible with | |
23 | a particular intrinsic function or subroutine. Presence of | |
24 | required arguments has already been established, the argument list | |
25 | has been sorted into the right order and has NULL arguments in the | |
26 | correct places for missing optional arguments. */ | |
27 | ||
6de9cd9a DN |
28 | #include "config.h" |
29 | #include "system.h" | |
953bee7c | 30 | #include "coretypes.h" |
6de9cd9a DN |
31 | #include "flags.h" |
32 | #include "gfortran.h" | |
33 | #include "intrinsic.h" | |
b7e75771 | 34 | #include "constructor.h" |
86dbed7d | 35 | #include "target-memory.h" |
6de9cd9a DN |
36 | |
37 | ||
7ab88654 TB |
38 | /* Make sure an expression is a scalar. */ |
39 | ||
524af0d6 | 40 | static bool |
7ab88654 TB |
41 | scalar_check (gfc_expr *e, int n) |
42 | { | |
43 | if (e->rank == 0) | |
524af0d6 | 44 | return true; |
7ab88654 TB |
45 | |
46 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar", | |
c4aa95f8 JW |
47 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
48 | &e->where); | |
7ab88654 | 49 | |
524af0d6 | 50 | return false; |
7ab88654 TB |
51 | } |
52 | ||
53 | ||
6de9cd9a DN |
54 | /* Check the type of an expression. */ |
55 | ||
524af0d6 | 56 | static bool |
65f8144a | 57 | type_check (gfc_expr *e, int n, bt type) |
6de9cd9a | 58 | { |
6de9cd9a | 59 | if (e->ts.type == type) |
524af0d6 | 60 | return true; |
6de9cd9a | 61 | |
4c93c95a | 62 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s", |
c4aa95f8 JW |
63 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
64 | &e->where, gfc_basic_typename (type)); | |
6de9cd9a | 65 | |
524af0d6 | 66 | return false; |
6de9cd9a DN |
67 | } |
68 | ||
69 | ||
70 | /* Check that the expression is a numeric type. */ | |
71 | ||
524af0d6 | 72 | static bool |
65f8144a | 73 | numeric_check (gfc_expr *e, int n) |
6de9cd9a | 74 | { |
6de9cd9a | 75 | if (gfc_numeric_ts (&e->ts)) |
524af0d6 | 76 | return true; |
6de9cd9a | 77 | |
909a3e38 PT |
78 | /* If the expression has not got a type, check if its namespace can |
79 | offer a default type. */ | |
fc2655fb | 80 | if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_FUNCTION) |
909a3e38 | 81 | && e->symtree->n.sym->ts.type == BT_UNKNOWN |
524af0d6 | 82 | && gfc_set_default_type (e->symtree->n.sym, 0, e->symtree->n.sym->ns) |
909a3e38 PT |
83 | && gfc_numeric_ts (&e->symtree->n.sym->ts)) |
84 | { | |
85 | e->ts = e->symtree->n.sym->ts; | |
524af0d6 | 86 | return true; |
909a3e38 PT |
87 | } |
88 | ||
4c93c95a | 89 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type", |
c4aa95f8 JW |
90 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
91 | &e->where); | |
6de9cd9a | 92 | |
524af0d6 | 93 | return false; |
6de9cd9a DN |
94 | } |
95 | ||
96 | ||
97 | /* Check that an expression is integer or real. */ | |
98 | ||
524af0d6 | 99 | static bool |
65f8144a | 100 | int_or_real_check (gfc_expr *e, int n) |
6de9cd9a | 101 | { |
6de9cd9a DN |
102 | if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL) |
103 | { | |
65f8144a | 104 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER " |
c4aa95f8 | 105 | "or REAL", gfc_current_intrinsic_arg[n]->name, |
65f8144a | 106 | gfc_current_intrinsic, &e->where); |
524af0d6 | 107 | return false; |
6de9cd9a DN |
108 | } |
109 | ||
524af0d6 | 110 | return true; |
6de9cd9a DN |
111 | } |
112 | ||
113 | ||
985aff9c PB |
114 | /* Check that an expression is real or complex. */ |
115 | ||
524af0d6 | 116 | static bool |
65f8144a | 117 | real_or_complex_check (gfc_expr *e, int n) |
985aff9c PB |
118 | { |
119 | if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX) | |
120 | { | |
65f8144a | 121 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL " |
c4aa95f8 JW |
122 | "or COMPLEX", gfc_current_intrinsic_arg[n]->name, |
123 | gfc_current_intrinsic, &e->where); | |
524af0d6 | 124 | return false; |
c4aa95f8 JW |
125 | } |
126 | ||
524af0d6 | 127 | return true; |
c4aa95f8 JW |
128 | } |
129 | ||
130 | ||
131 | /* Check that an expression is INTEGER or PROCEDURE. */ | |
132 | ||
524af0d6 | 133 | static bool |
c4aa95f8 JW |
134 | int_or_proc_check (gfc_expr *e, int n) |
135 | { | |
136 | if (e->ts.type != BT_INTEGER && e->ts.type != BT_PROCEDURE) | |
137 | { | |
138 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER " | |
139 | "or PROCEDURE", gfc_current_intrinsic_arg[n]->name, | |
65f8144a | 140 | gfc_current_intrinsic, &e->where); |
524af0d6 | 141 | return false; |
985aff9c PB |
142 | } |
143 | ||
524af0d6 | 144 | return true; |
985aff9c PB |
145 | } |
146 | ||
147 | ||
6de9cd9a DN |
148 | /* Check that the expression is an optional constant integer |
149 | and that it specifies a valid kind for that type. */ | |
150 | ||
524af0d6 | 151 | static bool |
65f8144a | 152 | kind_check (gfc_expr *k, int n, bt type) |
6de9cd9a DN |
153 | { |
154 | int kind; | |
155 | ||
156 | if (k == NULL) | |
524af0d6 | 157 | return true; |
6de9cd9a | 158 | |
524af0d6 JB |
159 | if (!type_check (k, n, BT_INTEGER)) |
160 | return false; | |
6de9cd9a | 161 | |
524af0d6 JB |
162 | if (!scalar_check (k, n)) |
163 | return false; | |
7ab88654 | 164 | |
524af0d6 | 165 | if (!gfc_check_init_expr (k)) |
6de9cd9a | 166 | { |
65f8144a | 167 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant", |
c4aa95f8 | 168 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
65f8144a | 169 | &k->where); |
524af0d6 | 170 | return false; |
6de9cd9a DN |
171 | } |
172 | ||
173 | if (gfc_extract_int (k, &kind) != NULL | |
e7a2d5fb | 174 | || gfc_validate_kind (type, kind, true) < 0) |
6de9cd9a DN |
175 | { |
176 | gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type), | |
177 | &k->where); | |
524af0d6 | 178 | return false; |
6de9cd9a DN |
179 | } |
180 | ||
524af0d6 | 181 | return true; |
6de9cd9a DN |
182 | } |
183 | ||
184 | ||
185 | /* Make sure the expression is a double precision real. */ | |
186 | ||
524af0d6 | 187 | static bool |
65f8144a | 188 | double_check (gfc_expr *d, int n) |
6de9cd9a | 189 | { |
524af0d6 JB |
190 | if (!type_check (d, n, BT_REAL)) |
191 | return false; | |
6de9cd9a | 192 | |
9d64df18 | 193 | if (d->ts.kind != gfc_default_double_kind) |
6de9cd9a | 194 | { |
65f8144a | 195 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be double " |
c4aa95f8 | 196 | "precision", gfc_current_intrinsic_arg[n]->name, |
65f8144a | 197 | gfc_current_intrinsic, &d->where); |
524af0d6 | 198 | return false; |
6de9cd9a DN |
199 | } |
200 | ||
524af0d6 | 201 | return true; |
6de9cd9a DN |
202 | } |
203 | ||
204 | ||
524af0d6 | 205 | static bool |
c4aa95f8 JW |
206 | coarray_check (gfc_expr *e, int n) |
207 | { | |
fac665b2 TB |
208 | if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok |
209 | && CLASS_DATA (e)->attr.codimension | |
210 | && CLASS_DATA (e)->as->corank) | |
211 | { | |
212 | gfc_add_class_array_ref (e); | |
524af0d6 | 213 | return true; |
fac665b2 TB |
214 | } |
215 | ||
266edc7e | 216 | if (!gfc_is_coarray (e)) |
c4aa95f8 JW |
217 | { |
218 | gfc_error ("Expected coarray variable as '%s' argument to the %s " | |
219 | "intrinsic at %L", gfc_current_intrinsic_arg[n]->name, | |
220 | gfc_current_intrinsic, &e->where); | |
524af0d6 | 221 | return false; |
c4aa95f8 JW |
222 | } |
223 | ||
524af0d6 | 224 | return true; |
8b704316 | 225 | } |
c4aa95f8 JW |
226 | |
227 | ||
6de9cd9a DN |
228 | /* Make sure the expression is a logical array. */ |
229 | ||
524af0d6 | 230 | static bool |
65f8144a | 231 | logical_array_check (gfc_expr *array, int n) |
6de9cd9a | 232 | { |
6de9cd9a DN |
233 | if (array->ts.type != BT_LOGICAL || array->rank == 0) |
234 | { | |
65f8144a | 235 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical " |
c4aa95f8 JW |
236 | "array", gfc_current_intrinsic_arg[n]->name, |
237 | gfc_current_intrinsic, &array->where); | |
524af0d6 | 238 | return false; |
6de9cd9a DN |
239 | } |
240 | ||
524af0d6 | 241 | return true; |
6de9cd9a DN |
242 | } |
243 | ||
244 | ||
245 | /* Make sure an expression is an array. */ | |
246 | ||
524af0d6 | 247 | static bool |
65f8144a | 248 | array_check (gfc_expr *e, int n) |
6de9cd9a | 249 | { |
fac665b2 | 250 | if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok |
c49ea23d PT |
251 | && CLASS_DATA (e)->attr.dimension |
252 | && CLASS_DATA (e)->as->rank) | |
253 | { | |
254 | gfc_add_class_array_ref (e); | |
524af0d6 | 255 | return true; |
c49ea23d PT |
256 | } |
257 | ||
52880d11 | 258 | if (e->rank != 0 && e->ts.type != BT_PROCEDURE) |
524af0d6 | 259 | return true; |
6de9cd9a | 260 | |
4c93c95a | 261 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array", |
c4aa95f8 JW |
262 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
263 | &e->where); | |
6de9cd9a | 264 | |
524af0d6 | 265 | return false; |
6de9cd9a DN |
266 | } |
267 | ||
268 | ||
289e52fd SK |
269 | /* If expr is a constant, then check to ensure that it is greater than |
270 | of equal to zero. */ | |
271 | ||
524af0d6 | 272 | static bool |
289e52fd SK |
273 | nonnegative_check (const char *arg, gfc_expr *expr) |
274 | { | |
275 | int i; | |
276 | ||
277 | if (expr->expr_type == EXPR_CONSTANT) | |
278 | { | |
279 | gfc_extract_int (expr, &i); | |
280 | if (i < 0) | |
281 | { | |
282 | gfc_error ("'%s' at %L must be nonnegative", arg, &expr->where); | |
524af0d6 | 283 | return false; |
289e52fd SK |
284 | } |
285 | } | |
286 | ||
524af0d6 | 287 | return true; |
289e52fd SK |
288 | } |
289 | ||
290 | ||
291 | /* If expr2 is constant, then check that the value is less than | |
88a95a11 | 292 | (less than or equal to, if 'or_equal' is true) bit_size(expr1). */ |
289e52fd | 293 | |
524af0d6 | 294 | static bool |
289e52fd | 295 | less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2, |
88a95a11 | 296 | gfc_expr *expr2, bool or_equal) |
289e52fd SK |
297 | { |
298 | int i2, i3; | |
299 | ||
300 | if (expr2->expr_type == EXPR_CONSTANT) | |
301 | { | |
302 | gfc_extract_int (expr2, &i2); | |
303 | i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false); | |
8b704316 | 304 | |
0019028b SK |
305 | /* For ISHFT[C], check that |shift| <= bit_size(i). */ |
306 | if (arg2 == NULL) | |
307 | { | |
308 | if (i2 < 0) | |
309 | i2 = -i2; | |
310 | ||
311 | if (i2 > gfc_integer_kinds[i3].bit_size) | |
312 | { | |
313 | gfc_error ("The absolute value of SHIFT at %L must be less " | |
314 | "than or equal to BIT_SIZE('%s')", | |
315 | &expr2->where, arg1); | |
524af0d6 | 316 | return false; |
0019028b SK |
317 | } |
318 | } | |
319 | ||
88a95a11 | 320 | if (or_equal) |
289e52fd | 321 | { |
88a95a11 FXC |
322 | if (i2 > gfc_integer_kinds[i3].bit_size) |
323 | { | |
324 | gfc_error ("'%s' at %L must be less than " | |
325 | "or equal to BIT_SIZE('%s')", | |
326 | arg2, &expr2->where, arg1); | |
524af0d6 | 327 | return false; |
88a95a11 FXC |
328 | } |
329 | } | |
330 | else | |
331 | { | |
332 | if (i2 >= gfc_integer_kinds[i3].bit_size) | |
333 | { | |
334 | gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')", | |
335 | arg2, &expr2->where, arg1); | |
524af0d6 | 336 | return false; |
88a95a11 | 337 | } |
289e52fd SK |
338 | } |
339 | } | |
340 | ||
524af0d6 | 341 | return true; |
289e52fd SK |
342 | } |
343 | ||
344 | ||
88a95a11 FXC |
345 | /* If expr is constant, then check that the value is less than or equal |
346 | to the bit_size of the kind k. */ | |
347 | ||
524af0d6 | 348 | static bool |
88a95a11 FXC |
349 | less_than_bitsizekind (const char *arg, gfc_expr *expr, int k) |
350 | { | |
351 | int i, val; | |
352 | ||
353 | if (expr->expr_type != EXPR_CONSTANT) | |
524af0d6 | 354 | return true; |
8b704316 | 355 | |
88a95a11 FXC |
356 | i = gfc_validate_kind (BT_INTEGER, k, false); |
357 | gfc_extract_int (expr, &val); | |
358 | ||
359 | if (val > gfc_integer_kinds[i].bit_size) | |
360 | { | |
361 | gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of " | |
362 | "INTEGER(KIND=%d)", arg, &expr->where, k); | |
524af0d6 | 363 | return false; |
88a95a11 FXC |
364 | } |
365 | ||
524af0d6 | 366 | return true; |
88a95a11 FXC |
367 | } |
368 | ||
369 | ||
289e52fd SK |
370 | /* If expr2 and expr3 are constants, then check that the value is less than |
371 | or equal to bit_size(expr1). */ | |
372 | ||
524af0d6 | 373 | static bool |
289e52fd SK |
374 | less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2, |
375 | gfc_expr *expr2, const char *arg3, gfc_expr *expr3) | |
376 | { | |
377 | int i2, i3; | |
378 | ||
379 | if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT) | |
380 | { | |
381 | gfc_extract_int (expr2, &i2); | |
382 | gfc_extract_int (expr3, &i3); | |
383 | i2 += i3; | |
384 | i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false); | |
385 | if (i2 > gfc_integer_kinds[i3].bit_size) | |
386 | { | |
387 | gfc_error ("'%s + %s' at %L must be less than or equal " | |
388 | "to BIT_SIZE('%s')", | |
389 | arg2, arg3, &expr2->where, arg1); | |
524af0d6 | 390 | return false; |
289e52fd SK |
391 | } |
392 | } | |
393 | ||
524af0d6 | 394 | return true; |
289e52fd SK |
395 | } |
396 | ||
f5bf550c | 397 | /* Make sure two expressions have the same type. */ |
6de9cd9a | 398 | |
524af0d6 | 399 | static bool |
65f8144a | 400 | same_type_check (gfc_expr *e, int n, gfc_expr *f, int m) |
6de9cd9a | 401 | { |
6de9cd9a | 402 | if (gfc_compare_types (&e->ts, &f->ts)) |
524af0d6 | 403 | return true; |
6de9cd9a | 404 | |
4c93c95a | 405 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type " |
c4aa95f8 JW |
406 | "and kind as '%s'", gfc_current_intrinsic_arg[m]->name, |
407 | gfc_current_intrinsic, &f->where, | |
408 | gfc_current_intrinsic_arg[n]->name); | |
65f8144a | 409 | |
524af0d6 | 410 | return false; |
6de9cd9a DN |
411 | } |
412 | ||
413 | ||
414 | /* Make sure that an expression has a certain (nonzero) rank. */ | |
415 | ||
524af0d6 | 416 | static bool |
65f8144a | 417 | rank_check (gfc_expr *e, int n, int rank) |
6de9cd9a | 418 | { |
6de9cd9a | 419 | if (e->rank == rank) |
524af0d6 | 420 | return true; |
6de9cd9a | 421 | |
4c93c95a | 422 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d", |
c4aa95f8 | 423 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
4c93c95a | 424 | &e->where, rank); |
65f8144a | 425 | |
524af0d6 | 426 | return false; |
6de9cd9a DN |
427 | } |
428 | ||
429 | ||
430 | /* Make sure a variable expression is not an optional dummy argument. */ | |
431 | ||
524af0d6 | 432 | static bool |
65f8144a | 433 | nonoptional_check (gfc_expr *e, int n) |
6de9cd9a | 434 | { |
6de9cd9a DN |
435 | if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional) |
436 | { | |
437 | gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL", | |
c4aa95f8 | 438 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
6de9cd9a | 439 | &e->where); |
6de9cd9a DN |
440 | } |
441 | ||
442 | /* TODO: Recursive check on nonoptional variables? */ | |
443 | ||
524af0d6 | 444 | return true; |
6de9cd9a DN |
445 | } |
446 | ||
447 | ||
c4aa95f8 JW |
448 | /* Check for ALLOCATABLE attribute. */ |
449 | ||
524af0d6 | 450 | static bool |
c4aa95f8 JW |
451 | allocatable_check (gfc_expr *e, int n) |
452 | { | |
453 | symbol_attribute attr; | |
454 | ||
455 | attr = gfc_variable_attr (e, NULL); | |
aa271860 | 456 | if (!attr.allocatable || attr.associate_var) |
c4aa95f8 JW |
457 | { |
458 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE", | |
459 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, | |
460 | &e->where); | |
524af0d6 | 461 | return false; |
c4aa95f8 JW |
462 | } |
463 | ||
524af0d6 | 464 | return true; |
c4aa95f8 JW |
465 | } |
466 | ||
467 | ||
6de9cd9a DN |
468 | /* Check that an expression has a particular kind. */ |
469 | ||
524af0d6 | 470 | static bool |
65f8144a | 471 | kind_value_check (gfc_expr *e, int n, int k) |
6de9cd9a | 472 | { |
6de9cd9a | 473 | if (e->ts.kind == k) |
524af0d6 | 474 | return true; |
6de9cd9a | 475 | |
4c93c95a | 476 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d", |
c4aa95f8 | 477 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, |
4c93c95a | 478 | &e->where, k); |
65f8144a | 479 | |
524af0d6 | 480 | return false; |
6de9cd9a DN |
481 | } |
482 | ||
483 | ||
484 | /* Make sure an expression is a variable. */ | |
485 | ||
524af0d6 | 486 | static bool |
11746b92 | 487 | variable_check (gfc_expr *e, int n, bool allow_proc) |
6de9cd9a | 488 | { |
6de9cd9a | 489 | if (e->expr_type == EXPR_VARIABLE |
c4aa95f8 JW |
490 | && e->symtree->n.sym->attr.intent == INTENT_IN |
491 | && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT | |
492 | || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT)) | |
6de9cd9a | 493 | { |
f9fcedbd TB |
494 | gfc_ref *ref; |
495 | bool pointer = e->symtree->n.sym->ts.type == BT_CLASS | |
496 | && CLASS_DATA (e->symtree->n.sym) | |
497 | ? CLASS_DATA (e->symtree->n.sym)->attr.class_pointer | |
498 | : e->symtree->n.sym->attr.pointer; | |
499 | ||
500 | for (ref = e->ref; ref; ref = ref->next) | |
501 | { | |
502 | if (pointer && ref->type == REF_COMPONENT) | |
503 | break; | |
504 | if (ref->type == REF_COMPONENT | |
505 | && ((ref->u.c.component->ts.type == BT_CLASS | |
506 | && CLASS_DATA (ref->u.c.component)->attr.class_pointer) | |
507 | || (ref->u.c.component->ts.type != BT_CLASS | |
508 | && ref->u.c.component->attr.pointer))) | |
509 | break; | |
8b704316 | 510 | } |
f9fcedbd TB |
511 | |
512 | if (!ref) | |
513 | { | |
514 | gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be " | |
515 | "INTENT(IN)", gfc_current_intrinsic_arg[n]->name, | |
516 | gfc_current_intrinsic, &e->where); | |
524af0d6 | 517 | return false; |
f9fcedbd | 518 | } |
6de9cd9a DN |
519 | } |
520 | ||
11746b92 TB |
521 | if (e->expr_type == EXPR_VARIABLE |
522 | && e->symtree->n.sym->attr.flavor != FL_PARAMETER | |
04803728 | 523 | && (allow_proc || !e->symtree->n.sym->attr.function)) |
524af0d6 | 524 | return true; |
c4aa95f8 | 525 | |
04803728 TB |
526 | if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.function |
527 | && e->symtree->n.sym == e->symtree->n.sym->result) | |
528 | { | |
529 | gfc_namespace *ns; | |
530 | for (ns = gfc_current_ns; ns; ns = ns->parent) | |
531 | if (ns->proc_name == e->symtree->n.sym) | |
524af0d6 | 532 | return true; |
04803728 TB |
533 | } |
534 | ||
4c93c95a | 535 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable", |
c4aa95f8 | 536 | gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where); |
6de9cd9a | 537 | |
524af0d6 | 538 | return false; |
6de9cd9a DN |
539 | } |
540 | ||
541 | ||
542 | /* Check the common DIM parameter for correctness. */ | |
543 | ||
524af0d6 | 544 | static bool |
7ab88654 | 545 | dim_check (gfc_expr *dim, int n, bool optional) |
6de9cd9a | 546 | { |
7ab88654 | 547 | if (dim == NULL) |
524af0d6 | 548 | return true; |
6de9cd9a | 549 | |
524af0d6 JB |
550 | if (!type_check (dim, n, BT_INTEGER)) |
551 | return false; | |
6de9cd9a | 552 | |
524af0d6 JB |
553 | if (!scalar_check (dim, n)) |
554 | return false; | |
6de9cd9a | 555 | |
524af0d6 JB |
556 | if (!optional && !nonoptional_check (dim, n)) |
557 | return false; | |
ce99d594 | 558 | |
524af0d6 | 559 | return true; |
6de9cd9a DN |
560 | } |
561 | ||
562 | ||
64f002ed TB |
563 | /* If a coarray DIM parameter is a constant, make sure that it is greater than |
564 | zero and less than or equal to the corank of the given array. */ | |
565 | ||
524af0d6 | 566 | static bool |
64f002ed TB |
567 | dim_corank_check (gfc_expr *dim, gfc_expr *array) |
568 | { | |
64f002ed TB |
569 | int corank; |
570 | ||
571 | gcc_assert (array->expr_type == EXPR_VARIABLE); | |
572 | ||
573 | if (dim->expr_type != EXPR_CONSTANT) | |
524af0d6 | 574 | return true; |
8b704316 | 575 | |
c49ea23d | 576 | if (array->ts.type == BT_CLASS) |
524af0d6 | 577 | return true; |
64f002ed | 578 | |
66b23e93 | 579 | corank = gfc_get_corank (array); |
64f002ed TB |
580 | |
581 | if (mpz_cmp_ui (dim->value.integer, 1) < 0 | |
582 | || mpz_cmp_ui (dim->value.integer, corank) > 0) | |
583 | { | |
584 | gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid " | |
585 | "codimension index", gfc_current_intrinsic, &dim->where); | |
586 | ||
524af0d6 | 587 | return false; |
64f002ed TB |
588 | } |
589 | ||
524af0d6 | 590 | return true; |
64f002ed TB |
591 | } |
592 | ||
593 | ||
6de9cd9a DN |
594 | /* If a DIM parameter is a constant, make sure that it is greater than |
595 | zero and less than or equal to the rank of the given array. If | |
596 | allow_assumed is zero then dim must be less than the rank of the array | |
597 | for assumed size arrays. */ | |
598 | ||
524af0d6 | 599 | static bool |
65f8144a | 600 | dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed) |
6de9cd9a DN |
601 | { |
602 | gfc_array_ref *ar; | |
603 | int rank; | |
604 | ||
ca8a8795 | 605 | if (dim == NULL) |
524af0d6 | 606 | return true; |
ca8a8795 | 607 | |
7114ab45 | 608 | if (dim->expr_type != EXPR_CONSTANT) |
524af0d6 | 609 | return true; |
6de9cd9a | 610 | |
7114ab45 TK |
611 | if (array->expr_type == EXPR_FUNCTION && array->value.function.isym |
612 | && array->value.function.isym->id == GFC_ISYM_SPREAD) | |
613 | rank = array->rank + 1; | |
614 | else | |
615 | rank = array->rank; | |
616 | ||
c62c6622 TB |
617 | /* Assumed-rank array. */ |
618 | if (rank == -1) | |
619 | rank = GFC_MAX_DIMENSIONS; | |
620 | ||
f8df0eb8 DF |
621 | if (array->expr_type == EXPR_VARIABLE) |
622 | { | |
623 | ar = gfc_find_array_ref (array); | |
624 | if (ar->as->type == AS_ASSUMED_SIZE | |
625 | && !allow_assumed | |
626 | && ar->type != AR_ELEMENT | |
627 | && ar->type != AR_SECTION) | |
628 | rank--; | |
629 | } | |
6de9cd9a DN |
630 | |
631 | if (mpz_cmp_ui (dim->value.integer, 1) < 0 | |
632 | || mpz_cmp_ui (dim->value.integer, rank) > 0) | |
633 | { | |
634 | gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid " | |
635 | "dimension index", gfc_current_intrinsic, &dim->where); | |
636 | ||
524af0d6 | 637 | return false; |
6de9cd9a DN |
638 | } |
639 | ||
524af0d6 | 640 | return true; |
6de9cd9a DN |
641 | } |
642 | ||
65f8144a | 643 | |
a8999235 TK |
644 | /* Compare the size of a along dimension ai with the size of b along |
645 | dimension bi, returning 0 if they are known not to be identical, | |
646 | and 1 if they are identical, or if this cannot be determined. */ | |
647 | ||
648 | static int | |
649 | identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi) | |
650 | { | |
651 | mpz_t a_size, b_size; | |
652 | int ret; | |
653 | ||
654 | gcc_assert (a->rank > ai); | |
655 | gcc_assert (b->rank > bi); | |
656 | ||
657 | ret = 1; | |
658 | ||
524af0d6 | 659 | if (gfc_array_dimen_size (a, ai, &a_size)) |
a8999235 | 660 | { |
524af0d6 | 661 | if (gfc_array_dimen_size (b, bi, &b_size)) |
a8999235 TK |
662 | { |
663 | if (mpz_cmp (a_size, b_size) != 0) | |
664 | ret = 0; | |
8b704316 | 665 | |
a8999235 TK |
666 | mpz_clear (b_size); |
667 | } | |
668 | mpz_clear (a_size); | |
669 | } | |
670 | return ret; | |
671 | } | |
6de9cd9a | 672 | |
07818af4 TK |
673 | /* Calculate the length of a character variable, including substrings. |
674 | Strip away parentheses if necessary. Return -1 if no length could | |
675 | be determined. */ | |
676 | ||
677 | static long | |
678 | gfc_var_strlen (const gfc_expr *a) | |
679 | { | |
680 | gfc_ref *ra; | |
681 | ||
682 | while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES) | |
683 | a = a->value.op.op1; | |
684 | ||
685 | for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next) | |
686 | ; | |
687 | ||
688 | if (ra) | |
689 | { | |
690 | long start_a, end_a; | |
691 | ||
cadddfdd TB |
692 | if (!ra->u.ss.end) |
693 | return -1; | |
694 | ||
695 | if ((!ra->u.ss.start || ra->u.ss.start->expr_type == EXPR_CONSTANT) | |
07818af4 TK |
696 | && ra->u.ss.end->expr_type == EXPR_CONSTANT) |
697 | { | |
cadddfdd TB |
698 | start_a = ra->u.ss.start ? mpz_get_si (ra->u.ss.start->value.integer) |
699 | : 1; | |
07818af4 | 700 | end_a = mpz_get_si (ra->u.ss.end->value.integer); |
cadddfdd | 701 | return (end_a < start_a) ? 0 : end_a - start_a + 1; |
07818af4 | 702 | } |
cadddfdd TB |
703 | else if (ra->u.ss.start |
704 | && gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0) | |
07818af4 TK |
705 | return 1; |
706 | else | |
707 | return -1; | |
708 | } | |
709 | ||
710 | if (a->ts.u.cl && a->ts.u.cl->length | |
711 | && a->ts.u.cl->length->expr_type == EXPR_CONSTANT) | |
712 | return mpz_get_si (a->ts.u.cl->length->value.integer); | |
713 | else if (a->expr_type == EXPR_CONSTANT | |
714 | && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL)) | |
715 | return a->value.character.length; | |
716 | else | |
717 | return -1; | |
718 | ||
719 | } | |
65f8144a | 720 | |
90d31126 | 721 | /* Check whether two character expressions have the same length; |
524af0d6 JB |
722 | returns true if they have or if the length cannot be determined, |
723 | otherwise return false and raise a gfc_error. */ | |
90d31126 | 724 | |
524af0d6 | 725 | bool |
fb5bc08b | 726 | gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name) |
90d31126 TB |
727 | { |
728 | long len_a, len_b; | |
90d31126 | 729 | |
07818af4 TK |
730 | len_a = gfc_var_strlen(a); |
731 | len_b = gfc_var_strlen(b); | |
90d31126 | 732 | |
07818af4 | 733 | if (len_a == -1 || len_b == -1 || len_a == len_b) |
524af0d6 | 734 | return true; |
07818af4 TK |
735 | else |
736 | { | |
737 | gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L", | |
738 | len_a, len_b, name, &a->where); | |
524af0d6 | 739 | return false; |
07818af4 | 740 | } |
90d31126 TB |
741 | } |
742 | ||
743 | ||
6de9cd9a DN |
744 | /***** Check functions *****/ |
745 | ||
746 | /* Check subroutine suitable for intrinsics taking a real argument and | |
747 | a kind argument for the result. */ | |
748 | ||
524af0d6 | 749 | static bool |
65f8144a | 750 | check_a_kind (gfc_expr *a, gfc_expr *kind, bt type) |
6de9cd9a | 751 | { |
524af0d6 JB |
752 | if (!type_check (a, 0, BT_REAL)) |
753 | return false; | |
754 | if (!kind_check (kind, 1, type)) | |
755 | return false; | |
6de9cd9a | 756 | |
524af0d6 | 757 | return true; |
6de9cd9a DN |
758 | } |
759 | ||
65f8144a | 760 | |
6de9cd9a DN |
761 | /* Check subroutine suitable for ceiling, floor and nint. */ |
762 | ||
524af0d6 | 763 | bool |
65f8144a | 764 | gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 765 | { |
6de9cd9a DN |
766 | return check_a_kind (a, kind, BT_INTEGER); |
767 | } | |
768 | ||
65f8144a | 769 | |
6de9cd9a DN |
770 | /* Check subroutine suitable for aint, anint. */ |
771 | ||
524af0d6 | 772 | bool |
65f8144a | 773 | gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 774 | { |
6de9cd9a DN |
775 | return check_a_kind (a, kind, BT_REAL); |
776 | } | |
777 | ||
65f8144a | 778 | |
524af0d6 | 779 | bool |
65f8144a | 780 | gfc_check_abs (gfc_expr *a) |
6de9cd9a | 781 | { |
524af0d6 JB |
782 | if (!numeric_check (a, 0)) |
783 | return false; | |
6de9cd9a | 784 | |
524af0d6 | 785 | return true; |
6de9cd9a DN |
786 | } |
787 | ||
65f8144a | 788 | |
524af0d6 | 789 | bool |
719e72fb | 790 | gfc_check_achar (gfc_expr *a, gfc_expr *kind) |
332e7efe | 791 | { |
524af0d6 JB |
792 | if (!type_check (a, 0, BT_INTEGER)) |
793 | return false; | |
794 | if (!kind_check (kind, 1, BT_CHARACTER)) | |
795 | return false; | |
332e7efe | 796 | |
524af0d6 | 797 | return true; |
332e7efe SK |
798 | } |
799 | ||
6de9cd9a | 800 | |
524af0d6 | 801 | bool |
65f8144a | 802 | gfc_check_access_func (gfc_expr *name, gfc_expr *mode) |
a119fc1c | 803 | { |
524af0d6 JB |
804 | if (!type_check (name, 0, BT_CHARACTER) |
805 | || !scalar_check (name, 0)) | |
806 | return false; | |
807 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
808 | return false; | |
a119fc1c | 809 | |
524af0d6 JB |
810 | if (!type_check (mode, 1, BT_CHARACTER) |
811 | || !scalar_check (mode, 1)) | |
812 | return false; | |
813 | if (!kind_value_check (mode, 1, gfc_default_character_kind)) | |
814 | return false; | |
a119fc1c | 815 | |
524af0d6 | 816 | return true; |
a119fc1c FXC |
817 | } |
818 | ||
819 | ||
524af0d6 | 820 | bool |
65f8144a | 821 | gfc_check_all_any (gfc_expr *mask, gfc_expr *dim) |
6de9cd9a | 822 | { |
524af0d6 JB |
823 | if (!logical_array_check (mask, 0)) |
824 | return false; | |
6de9cd9a | 825 | |
524af0d6 JB |
826 | if (!dim_check (dim, 1, false)) |
827 | return false; | |
6de9cd9a | 828 | |
524af0d6 JB |
829 | if (!dim_rank_check (dim, mask, 0)) |
830 | return false; | |
a16d978f | 831 | |
524af0d6 | 832 | return true; |
6de9cd9a DN |
833 | } |
834 | ||
835 | ||
524af0d6 | 836 | bool |
65f8144a | 837 | gfc_check_allocated (gfc_expr *array) |
6de9cd9a | 838 | { |
524af0d6 JB |
839 | if (!variable_check (array, 0, false)) |
840 | return false; | |
841 | if (!allocatable_check (array, 0)) | |
842 | return false; | |
8b704316 | 843 | |
524af0d6 | 844 | return true; |
6de9cd9a DN |
845 | } |
846 | ||
847 | ||
848 | /* Common check function where the first argument must be real or | |
849 | integer and the second argument must be the same as the first. */ | |
850 | ||
524af0d6 | 851 | bool |
65f8144a | 852 | gfc_check_a_p (gfc_expr *a, gfc_expr *p) |
6de9cd9a | 853 | { |
524af0d6 JB |
854 | if (!int_or_real_check (a, 0)) |
855 | return false; | |
6de9cd9a | 856 | |
991bb832 FXC |
857 | if (a->ts.type != p->ts.type) |
858 | { | |
859 | gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must " | |
c4aa95f8 JW |
860 | "have the same type", gfc_current_intrinsic_arg[0]->name, |
861 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
65f8144a | 862 | &p->where); |
524af0d6 | 863 | return false; |
991bb832 FXC |
864 | } |
865 | ||
866 | if (a->ts.kind != p->ts.kind) | |
867 | { | |
524af0d6 JB |
868 | if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L", |
869 | &p->where)) | |
870 | return false; | |
991bb832 | 871 | } |
6de9cd9a | 872 | |
524af0d6 | 873 | return true; |
6de9cd9a DN |
874 | } |
875 | ||
876 | ||
524af0d6 | 877 | bool |
15ead859 JD |
878 | gfc_check_x_yd (gfc_expr *x, gfc_expr *y) |
879 | { | |
524af0d6 JB |
880 | if (!double_check (x, 0) || !double_check (y, 1)) |
881 | return false; | |
15ead859 | 882 | |
524af0d6 | 883 | return true; |
15ead859 JD |
884 | } |
885 | ||
886 | ||
524af0d6 | 887 | bool |
65f8144a | 888 | gfc_check_associated (gfc_expr *pointer, gfc_expr *target) |
6de9cd9a | 889 | { |
8fb74da4 | 890 | symbol_attribute attr1, attr2; |
6de9cd9a | 891 | int i; |
524af0d6 | 892 | bool t; |
6690a9e0 PT |
893 | locus *where; |
894 | ||
895 | where = &pointer->where; | |
6de9cd9a | 896 | |
5fabac29 | 897 | if (pointer->expr_type == EXPR_NULL) |
6690a9e0 | 898 | goto null_arg; |
5fabac29 JW |
899 | |
900 | attr1 = gfc_expr_attr (pointer); | |
6de9cd9a | 901 | |
8fb74da4 | 902 | if (!attr1.pointer && !attr1.proc_pointer) |
6de9cd9a | 903 | { |
4c93c95a | 904 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER", |
c4aa95f8 | 905 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, |
4c93c95a | 906 | &pointer->where); |
524af0d6 | 907 | return false; |
6de9cd9a DN |
908 | } |
909 | ||
5aacb11e TB |
910 | /* F2008, C1242. */ |
911 | if (attr1.pointer && gfc_is_coindexed (pointer)) | |
912 | { | |
913 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be " | |
0c133211 | 914 | "coindexed", gfc_current_intrinsic_arg[0]->name, |
5aacb11e | 915 | gfc_current_intrinsic, &pointer->where); |
524af0d6 | 916 | return false; |
5aacb11e TB |
917 | } |
918 | ||
58c0774f | 919 | /* Target argument is optional. */ |
6de9cd9a | 920 | if (target == NULL) |
524af0d6 | 921 | return true; |
6de9cd9a | 922 | |
6690a9e0 | 923 | where = &target->where; |
6de9cd9a | 924 | if (target->expr_type == EXPR_NULL) |
6690a9e0 | 925 | goto null_arg; |
6de9cd9a | 926 | |
e6524a51 TB |
927 | if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION) |
928 | attr2 = gfc_expr_attr (target); | |
58c0774f | 929 | else |
476220e7 PT |
930 | { |
931 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer " | |
c4aa95f8 JW |
932 | "or target VARIABLE or FUNCTION", |
933 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
934 | &target->where); | |
524af0d6 | 935 | return false; |
476220e7 | 936 | } |
58c0774f | 937 | |
8fb74da4 | 938 | if (attr1.pointer && !attr2.pointer && !attr2.target) |
6de9cd9a | 939 | { |
4c93c95a | 940 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER " |
c4aa95f8 | 941 | "or a TARGET", gfc_current_intrinsic_arg[1]->name, |
4c93c95a | 942 | gfc_current_intrinsic, &target->where); |
524af0d6 | 943 | return false; |
6de9cd9a DN |
944 | } |
945 | ||
5aacb11e TB |
946 | /* F2008, C1242. */ |
947 | if (attr1.pointer && gfc_is_coindexed (target)) | |
948 | { | |
949 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be " | |
0c133211 | 950 | "coindexed", gfc_current_intrinsic_arg[1]->name, |
5aacb11e | 951 | gfc_current_intrinsic, &target->where); |
524af0d6 | 952 | return false; |
5aacb11e TB |
953 | } |
954 | ||
524af0d6 JB |
955 | t = true; |
956 | if (!same_type_check (pointer, 0, target, 1)) | |
957 | t = false; | |
958 | if (!rank_check (target, 0, pointer->rank)) | |
959 | t = false; | |
6de9cd9a DN |
960 | if (target->rank > 0) |
961 | { | |
962 | for (i = 0; i < target->rank; i++) | |
65f8144a SK |
963 | if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR) |
964 | { | |
965 | gfc_error ("Array section with a vector subscript at %L shall not " | |
31043f6c | 966 | "be the target of a pointer", |
65f8144a | 967 | &target->where); |
524af0d6 | 968 | t = false; |
65f8144a SK |
969 | break; |
970 | } | |
6de9cd9a DN |
971 | } |
972 | return t; | |
6690a9e0 PT |
973 | |
974 | null_arg: | |
975 | ||
976 | gfc_error ("NULL pointer at %L is not permitted as actual argument " | |
977 | "of '%s' intrinsic function", where, gfc_current_intrinsic); | |
524af0d6 | 978 | return false; |
6690a9e0 | 979 | |
6de9cd9a DN |
980 | } |
981 | ||
982 | ||
524af0d6 | 983 | bool |
ddf67998 TB |
984 | gfc_check_atan_2 (gfc_expr *y, gfc_expr *x) |
985 | { | |
58a9e3c4 | 986 | /* gfc_notify_std would be a waste of time as the return value |
ddf67998 TB |
987 | is seemingly used only for the generic resolution. The error |
988 | will be: Too many arguments. */ | |
989 | if ((gfc_option.allow_std & GFC_STD_F2008) == 0) | |
524af0d6 | 990 | return false; |
ddf67998 TB |
991 | |
992 | return gfc_check_atan2 (y, x); | |
993 | } | |
994 | ||
995 | ||
524af0d6 | 996 | bool |
65f8144a | 997 | gfc_check_atan2 (gfc_expr *y, gfc_expr *x) |
a1bab9ea | 998 | { |
524af0d6 JB |
999 | if (!type_check (y, 0, BT_REAL)) |
1000 | return false; | |
1001 | if (!same_type_check (y, 0, x, 1)) | |
1002 | return false; | |
a1bab9ea | 1003 | |
524af0d6 | 1004 | return true; |
a1bab9ea TS |
1005 | } |
1006 | ||
27dfc9c4 | 1007 | |
524af0d6 | 1008 | static bool |
7f4aaf91 TB |
1009 | gfc_check_atomic (gfc_expr *atom, int atom_no, gfc_expr *value, int val_no, |
1010 | gfc_expr *stat, int stat_no) | |
da661a58 | 1011 | { |
7f4aaf91 TB |
1012 | if (!scalar_check (atom, atom_no) || !scalar_check (value, val_no)) |
1013 | return false; | |
b5116268 | 1014 | |
da661a58 TB |
1015 | if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind) |
1016 | && !(atom->ts.type == BT_LOGICAL | |
1017 | && atom->ts.kind == gfc_atomic_logical_kind)) | |
1018 | { | |
1019 | gfc_error ("ATOM argument at %L to intrinsic function %s shall be an " | |
1020 | "integer of ATOMIC_INT_KIND or a logical of " | |
1021 | "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic); | |
524af0d6 | 1022 | return false; |
da661a58 TB |
1023 | } |
1024 | ||
1025 | if (!gfc_expr_attr (atom).codimension) | |
1026 | { | |
1027 | gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a " | |
1028 | "coarray or coindexed", &atom->where, gfc_current_intrinsic); | |
524af0d6 | 1029 | return false; |
da661a58 TB |
1030 | } |
1031 | ||
1032 | if (atom->ts.type != value->ts.type) | |
1033 | { | |
7f4aaf91 TB |
1034 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall have the same " |
1035 | "type as '%s' at %L", gfc_current_intrinsic_arg[val_no]->name, | |
1036 | gfc_current_intrinsic, &value->where, | |
1037 | gfc_current_intrinsic_arg[atom_no]->name, &atom->where); | |
524af0d6 | 1038 | return false; |
da661a58 TB |
1039 | } |
1040 | ||
7f4aaf91 TB |
1041 | if (stat != NULL) |
1042 | { | |
1043 | if (!type_check (stat, stat_no, BT_INTEGER)) | |
1044 | return false; | |
1045 | if (!scalar_check (stat, stat_no)) | |
1046 | return false; | |
1047 | if (!variable_check (stat, stat_no, false)) | |
1048 | return false; | |
1049 | if (!kind_value_check (stat, stat_no, gfc_default_integer_kind)) | |
1050 | return false; | |
1051 | ||
1052 | if (!gfc_notify_std (GFC_STD_F2008_TS, "STAT= argument to %s at %L", | |
1053 | gfc_current_intrinsic, &stat->where)) | |
1054 | return false; | |
1055 | } | |
1056 | ||
524af0d6 | 1057 | return true; |
da661a58 TB |
1058 | } |
1059 | ||
1060 | ||
524af0d6 | 1061 | bool |
7f4aaf91 | 1062 | gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value, gfc_expr *stat) |
da661a58 | 1063 | { |
b5116268 TB |
1064 | if (atom->expr_type == EXPR_FUNCTION |
1065 | && atom->value.function.isym | |
1066 | && atom->value.function.isym->id == GFC_ISYM_CAF_GET) | |
1067 | atom = atom->value.function.actual->expr; | |
1068 | ||
524af0d6 | 1069 | if (!gfc_check_vardef_context (atom, false, false, false, NULL)) |
da661a58 TB |
1070 | { |
1071 | gfc_error ("ATOM argument of the %s intrinsic function at %L shall be " | |
1072 | "definable", gfc_current_intrinsic, &atom->where); | |
524af0d6 | 1073 | return false; |
da661a58 TB |
1074 | } |
1075 | ||
7f4aaf91 | 1076 | return gfc_check_atomic (atom, 0, value, 1, stat, 2); |
da661a58 TB |
1077 | } |
1078 | ||
1079 | ||
524af0d6 | 1080 | bool |
7f4aaf91 | 1081 | gfc_check_atomic_op (gfc_expr *atom, gfc_expr *value, gfc_expr *stat) |
da661a58 | 1082 | { |
7f4aaf91 TB |
1083 | if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind) |
1084 | { | |
1085 | gfc_error ("ATOM argument at %L to intrinsic function %s shall be an " | |
1086 | "integer of ATOMIC_INT_KIND", &atom->where, | |
1087 | gfc_current_intrinsic); | |
1088 | return false; | |
1089 | } | |
1090 | ||
1091 | return gfc_check_atomic_def (atom, value, stat); | |
1092 | } | |
1093 | ||
1094 | ||
1095 | bool | |
1096 | gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom, gfc_expr *stat) | |
1097 | { | |
1098 | if (atom->expr_type == EXPR_FUNCTION | |
1099 | && atom->value.function.isym | |
1100 | && atom->value.function.isym->id == GFC_ISYM_CAF_GET) | |
1101 | atom = atom->value.function.actual->expr; | |
da661a58 | 1102 | |
524af0d6 | 1103 | if (!gfc_check_vardef_context (value, false, false, false, NULL)) |
da661a58 TB |
1104 | { |
1105 | gfc_error ("VALUE argument of the %s intrinsic function at %L shall be " | |
1106 | "definable", gfc_current_intrinsic, &value->where); | |
524af0d6 | 1107 | return false; |
da661a58 TB |
1108 | } |
1109 | ||
7f4aaf91 TB |
1110 | return gfc_check_atomic (atom, 1, value, 0, stat, 2); |
1111 | } | |
1112 | ||
1113 | ||
1114 | bool | |
1115 | gfc_check_atomic_cas (gfc_expr *atom, gfc_expr *old, gfc_expr *compare, | |
1116 | gfc_expr *new_val, gfc_expr *stat) | |
1117 | { | |
1118 | if (atom->expr_type == EXPR_FUNCTION | |
1119 | && atom->value.function.isym | |
1120 | && atom->value.function.isym->id == GFC_ISYM_CAF_GET) | |
1121 | atom = atom->value.function.actual->expr; | |
1122 | ||
1123 | if (!gfc_check_atomic (atom, 0, new_val, 3, stat, 4)) | |
1124 | return false; | |
1125 | ||
1126 | if (!scalar_check (old, 1) || !scalar_check (compare, 2)) | |
1127 | return false; | |
1128 | ||
1129 | if (!same_type_check (atom, 0, old, 1)) | |
1130 | return false; | |
1131 | ||
1132 | if (!same_type_check (atom, 0, compare, 2)) | |
1133 | return false; | |
1134 | ||
1135 | if (!gfc_check_vardef_context (atom, false, false, false, NULL)) | |
1136 | { | |
1137 | gfc_error ("ATOM argument of the %s intrinsic function at %L shall be " | |
1138 | "definable", gfc_current_intrinsic, &atom->where); | |
1139 | return false; | |
1140 | } | |
1141 | ||
1142 | if (!gfc_check_vardef_context (old, false, false, false, NULL)) | |
1143 | { | |
1144 | gfc_error ("OLD argument of the %s intrinsic function at %L shall be " | |
1145 | "definable", gfc_current_intrinsic, &old->where); | |
1146 | return false; | |
1147 | } | |
1148 | ||
1149 | return true; | |
1150 | } | |
1151 | ||
1152 | ||
1153 | bool | |
1154 | gfc_check_atomic_fetch_op (gfc_expr *atom, gfc_expr *value, gfc_expr *old, | |
1155 | gfc_expr *stat) | |
1156 | { | |
1157 | if (atom->expr_type == EXPR_FUNCTION | |
1158 | && atom->value.function.isym | |
1159 | && atom->value.function.isym->id == GFC_ISYM_CAF_GET) | |
1160 | atom = atom->value.function.actual->expr; | |
1161 | ||
1162 | if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind) | |
1163 | { | |
1164 | gfc_error ("ATOM argument at %L to intrinsic function %s shall be an " | |
1165 | "integer of ATOMIC_INT_KIND", &atom->where, | |
1166 | gfc_current_intrinsic); | |
1167 | return false; | |
1168 | } | |
1169 | ||
1170 | if (!gfc_check_atomic (atom, 0, value, 1, stat, 3)) | |
1171 | return false; | |
1172 | ||
1173 | if (!scalar_check (old, 2)) | |
1174 | return false; | |
1175 | ||
1176 | if (!same_type_check (atom, 0, old, 2)) | |
1177 | return false; | |
1178 | ||
1179 | if (!gfc_check_vardef_context (atom, false, false, false, NULL)) | |
1180 | { | |
1181 | gfc_error ("ATOM argument of the %s intrinsic function at %L shall be " | |
1182 | "definable", gfc_current_intrinsic, &atom->where); | |
1183 | return false; | |
1184 | } | |
1185 | ||
1186 | if (!gfc_check_vardef_context (old, false, false, false, NULL)) | |
1187 | { | |
1188 | gfc_error ("OLD argument of the %s intrinsic function at %L shall be " | |
1189 | "definable", gfc_current_intrinsic, &old->where); | |
1190 | return false; | |
1191 | } | |
1192 | ||
1193 | return true; | |
da661a58 TB |
1194 | } |
1195 | ||
1196 | ||
e8525382 SK |
1197 | /* BESJN and BESYN functions. */ |
1198 | ||
524af0d6 | 1199 | bool |
65f8144a | 1200 | gfc_check_besn (gfc_expr *n, gfc_expr *x) |
e8525382 | 1201 | { |
524af0d6 JB |
1202 | if (!type_check (n, 0, BT_INTEGER)) |
1203 | return false; | |
29698e0f TB |
1204 | if (n->expr_type == EXPR_CONSTANT) |
1205 | { | |
1206 | int i; | |
1207 | gfc_extract_int (n, &i); | |
524af0d6 JB |
1208 | if (i < 0 && !gfc_notify_std (GFC_STD_GNU, "Negative argument " |
1209 | "N at %L", &n->where)) | |
1210 | return false; | |
29698e0f | 1211 | } |
e8525382 | 1212 | |
524af0d6 JB |
1213 | if (!type_check (x, 1, BT_REAL)) |
1214 | return false; | |
e8525382 | 1215 | |
524af0d6 | 1216 | return true; |
e8525382 SK |
1217 | } |
1218 | ||
1219 | ||
29698e0f TB |
1220 | /* Transformational version of the Bessel JN and YN functions. */ |
1221 | ||
524af0d6 | 1222 | bool |
29698e0f TB |
1223 | gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x) |
1224 | { | |
524af0d6 JB |
1225 | if (!type_check (n1, 0, BT_INTEGER)) |
1226 | return false; | |
1227 | if (!scalar_check (n1, 0)) | |
1228 | return false; | |
1229 | if (!nonnegative_check ("N1", n1)) | |
1230 | return false; | |
1231 | ||
1232 | if (!type_check (n2, 1, BT_INTEGER)) | |
1233 | return false; | |
1234 | if (!scalar_check (n2, 1)) | |
1235 | return false; | |
1236 | if (!nonnegative_check ("N2", n2)) | |
1237 | return false; | |
1238 | ||
1239 | if (!type_check (x, 2, BT_REAL)) | |
1240 | return false; | |
1241 | if (!scalar_check (x, 2)) | |
1242 | return false; | |
29698e0f | 1243 | |
524af0d6 | 1244 | return true; |
29698e0f TB |
1245 | } |
1246 | ||
1247 | ||
524af0d6 | 1248 | bool |
88a95a11 FXC |
1249 | gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j) |
1250 | { | |
524af0d6 JB |
1251 | if (!type_check (i, 0, BT_INTEGER)) |
1252 | return false; | |
88a95a11 | 1253 | |
524af0d6 JB |
1254 | if (!type_check (j, 1, BT_INTEGER)) |
1255 | return false; | |
88a95a11 | 1256 | |
524af0d6 | 1257 | return true; |
88a95a11 FXC |
1258 | } |
1259 | ||
1260 | ||
524af0d6 | 1261 | bool |
289e52fd | 1262 | gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos) |
6de9cd9a | 1263 | { |
524af0d6 JB |
1264 | if (!type_check (i, 0, BT_INTEGER)) |
1265 | return false; | |
289e52fd | 1266 | |
524af0d6 JB |
1267 | if (!type_check (pos, 1, BT_INTEGER)) |
1268 | return false; | |
6de9cd9a | 1269 | |
524af0d6 JB |
1270 | if (!nonnegative_check ("pos", pos)) |
1271 | return false; | |
289e52fd | 1272 | |
524af0d6 JB |
1273 | if (!less_than_bitsize1 ("i", i, "pos", pos, false)) |
1274 | return false; | |
289e52fd | 1275 | |
524af0d6 | 1276 | return true; |
6de9cd9a DN |
1277 | } |
1278 | ||
1279 | ||
524af0d6 | 1280 | bool |
65f8144a | 1281 | gfc_check_char (gfc_expr *i, gfc_expr *kind) |
6de9cd9a | 1282 | { |
524af0d6 JB |
1283 | if (!type_check (i, 0, BT_INTEGER)) |
1284 | return false; | |
1285 | if (!kind_check (kind, 1, BT_CHARACTER)) | |
1286 | return false; | |
6de9cd9a | 1287 | |
524af0d6 | 1288 | return true; |
6de9cd9a DN |
1289 | } |
1290 | ||
1291 | ||
524af0d6 | 1292 | bool |
65f8144a | 1293 | gfc_check_chdir (gfc_expr *dir) |
f77b6ca3 | 1294 | { |
524af0d6 JB |
1295 | if (!type_check (dir, 0, BT_CHARACTER)) |
1296 | return false; | |
1297 | if (!kind_value_check (dir, 0, gfc_default_character_kind)) | |
1298 | return false; | |
f77b6ca3 | 1299 | |
524af0d6 | 1300 | return true; |
f77b6ca3 FXC |
1301 | } |
1302 | ||
1303 | ||
524af0d6 | 1304 | bool |
65f8144a | 1305 | gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status) |
f77b6ca3 | 1306 | { |
524af0d6 JB |
1307 | if (!type_check (dir, 0, BT_CHARACTER)) |
1308 | return false; | |
1309 | if (!kind_value_check (dir, 0, gfc_default_character_kind)) | |
1310 | return false; | |
f77b6ca3 FXC |
1311 | |
1312 | if (status == NULL) | |
524af0d6 | 1313 | return true; |
f77b6ca3 | 1314 | |
524af0d6 JB |
1315 | if (!type_check (status, 1, BT_INTEGER)) |
1316 | return false; | |
1317 | if (!scalar_check (status, 1)) | |
1318 | return false; | |
f77b6ca3 | 1319 | |
524af0d6 | 1320 | return true; |
f77b6ca3 FXC |
1321 | } |
1322 | ||
1323 | ||
524af0d6 | 1324 | bool |
65f8144a | 1325 | gfc_check_chmod (gfc_expr *name, gfc_expr *mode) |
a119fc1c | 1326 | { |
524af0d6 JB |
1327 | if (!type_check (name, 0, BT_CHARACTER)) |
1328 | return false; | |
1329 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
1330 | return false; | |
a119fc1c | 1331 | |
524af0d6 JB |
1332 | if (!type_check (mode, 1, BT_CHARACTER)) |
1333 | return false; | |
1334 | if (!kind_value_check (mode, 1, gfc_default_character_kind)) | |
1335 | return false; | |
a119fc1c | 1336 | |
524af0d6 | 1337 | return true; |
a119fc1c FXC |
1338 | } |
1339 | ||
1340 | ||
524af0d6 | 1341 | bool |
65f8144a | 1342 | gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status) |
a119fc1c | 1343 | { |
524af0d6 JB |
1344 | if (!type_check (name, 0, BT_CHARACTER)) |
1345 | return false; | |
1346 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
1347 | return false; | |
a119fc1c | 1348 | |
524af0d6 JB |
1349 | if (!type_check (mode, 1, BT_CHARACTER)) |
1350 | return false; | |
1351 | if (!kind_value_check (mode, 1, gfc_default_character_kind)) | |
1352 | return false; | |
a119fc1c FXC |
1353 | |
1354 | if (status == NULL) | |
524af0d6 | 1355 | return true; |
a119fc1c | 1356 | |
524af0d6 JB |
1357 | if (!type_check (status, 2, BT_INTEGER)) |
1358 | return false; | |
a119fc1c | 1359 | |
524af0d6 JB |
1360 | if (!scalar_check (status, 2)) |
1361 | return false; | |
a119fc1c | 1362 | |
524af0d6 | 1363 | return true; |
a119fc1c FXC |
1364 | } |
1365 | ||
1366 | ||
524af0d6 | 1367 | bool |
65f8144a | 1368 | gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind) |
6de9cd9a | 1369 | { |
524af0d6 JB |
1370 | if (!numeric_check (x, 0)) |
1371 | return false; | |
6de9cd9a DN |
1372 | |
1373 | if (y != NULL) | |
1374 | { | |
524af0d6 JB |
1375 | if (!numeric_check (y, 1)) |
1376 | return false; | |
6de9cd9a DN |
1377 | |
1378 | if (x->ts.type == BT_COMPLEX) | |
1379 | { | |
4c93c95a | 1380 | gfc_error ("'%s' argument of '%s' intrinsic at %L must not be " |
c4aa95f8 JW |
1381 | "present if 'x' is COMPLEX", |
1382 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
1383 | &y->where); | |
524af0d6 | 1384 | return false; |
6de9cd9a | 1385 | } |
20562de4 SK |
1386 | |
1387 | if (y->ts.type == BT_COMPLEX) | |
1388 | { | |
1389 | gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type " | |
c4aa95f8 JW |
1390 | "of either REAL or INTEGER", |
1391 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
1392 | &y->where); | |
524af0d6 | 1393 | return false; |
20562de4 SK |
1394 | } |
1395 | ||
6de9cd9a DN |
1396 | } |
1397 | ||
524af0d6 JB |
1398 | if (!kind_check (kind, 2, BT_COMPLEX)) |
1399 | return false; | |
6de9cd9a | 1400 | |
2e60cfaa TB |
1401 | if (!kind && gfc_option.gfc_warn_conversion |
1402 | && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind) | |
1403 | gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L " | |
3e0da29a | 1404 | "might lose precision, consider using the KIND argument", |
2e60cfaa TB |
1405 | gfc_typename (&x->ts), gfc_default_real_kind, &x->where); |
1406 | else if (y && !kind && gfc_option.gfc_warn_conversion | |
1407 | && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind) | |
1408 | gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L " | |
3e0da29a | 1409 | "might lose precision, consider using the KIND argument", |
2e60cfaa TB |
1410 | gfc_typename (&y->ts), gfc_default_real_kind, &y->where); |
1411 | ||
524af0d6 | 1412 | return true; |
6de9cd9a DN |
1413 | } |
1414 | ||
1415 | ||
d62cf3df | 1416 | static bool |
a16ee379 TB |
1417 | check_co_collective (gfc_expr *a, gfc_expr *image_idx, gfc_expr *stat, |
1418 | gfc_expr *errmsg, bool co_reduce) | |
d62cf3df TB |
1419 | { |
1420 | if (!variable_check (a, 0, false)) | |
1421 | return false; | |
1422 | ||
aa9ca5ca TB |
1423 | if (!gfc_check_vardef_context (a, false, false, false, "argument 'A' with " |
1424 | "INTENT(INOUT)")) | |
1425 | return false; | |
1426 | ||
a16ee379 | 1427 | /* Fortran 2008, 12.5.2.4, paragraph 18. */ |
aa9ca5ca TB |
1428 | if (gfc_has_vector_subscript (a)) |
1429 | { | |
1430 | gfc_error ("Argument 'A' with INTENT(INOUT) at %L of the intrinsic " | |
1431 | "subroutine %s shall not have a vector subscript", | |
1432 | &a->where, gfc_current_intrinsic); | |
1433 | return false; | |
1434 | } | |
1435 | ||
a16ee379 | 1436 | if (image_idx != NULL) |
d62cf3df | 1437 | { |
a16ee379 | 1438 | if (!type_check (image_idx, co_reduce ? 2 : 1, BT_INTEGER)) |
d62cf3df | 1439 | return false; |
a16ee379 | 1440 | if (!scalar_check (image_idx, co_reduce ? 2 : 1)) |
d62cf3df TB |
1441 | return false; |
1442 | } | |
1443 | ||
1444 | if (stat != NULL) | |
1445 | { | |
a16ee379 | 1446 | if (!type_check (stat, co_reduce ? 3 : 2, BT_INTEGER)) |
d62cf3df | 1447 | return false; |
a16ee379 | 1448 | if (!scalar_check (stat, co_reduce ? 3 : 2)) |
d62cf3df | 1449 | return false; |
a16ee379 | 1450 | if (!variable_check (stat, co_reduce ? 3 : 2, false)) |
d62cf3df TB |
1451 | return false; |
1452 | if (stat->ts.kind != 4) | |
1453 | { | |
1454 | gfc_error ("The stat= argument at %L must be a kind=4 integer " | |
1455 | "variable", &stat->where); | |
1456 | return false; | |
1457 | } | |
1458 | } | |
1459 | ||
1460 | if (errmsg != NULL) | |
1461 | { | |
a16ee379 | 1462 | if (!type_check (errmsg, co_reduce ? 4 : 3, BT_CHARACTER)) |
d62cf3df | 1463 | return false; |
a16ee379 | 1464 | if (!scalar_check (errmsg, co_reduce ? 4 : 3)) |
d62cf3df | 1465 | return false; |
a16ee379 | 1466 | if (!variable_check (errmsg, co_reduce ? 4 : 3, false)) |
d62cf3df TB |
1467 | return false; |
1468 | if (errmsg->ts.kind != 1) | |
1469 | { | |
1470 | gfc_error ("The errmsg= argument at %L must be a default-kind " | |
1471 | "character variable", &errmsg->where); | |
1472 | return false; | |
1473 | } | |
1474 | } | |
1475 | ||
1476 | if (gfc_option.coarray == GFC_FCOARRAY_NONE) | |
1477 | { | |
1478 | gfc_fatal_error ("Coarrays disabled at %L, use -fcoarray= to enable", | |
1479 | &a->where); | |
1480 | return false; | |
1481 | } | |
1482 | ||
1483 | return true; | |
1484 | } | |
1485 | ||
1486 | ||
a16ee379 TB |
1487 | bool |
1488 | gfc_check_co_broadcast (gfc_expr *a, gfc_expr *source_image, gfc_expr *stat, | |
1489 | gfc_expr *errmsg) | |
1490 | { | |
1491 | if (a->ts.type == BT_CLASS || gfc_expr_attr (a).alloc_comp) | |
1492 | { | |
1493 | gfc_error ("Support for the A argument at %L which is polymorphic A " | |
1494 | "argument or has allocatable components is not yet " | |
1495 | "implemented", &a->where); | |
1496 | return false; | |
1497 | } | |
1498 | return check_co_collective (a, source_image, stat, errmsg, false); | |
1499 | } | |
1500 | ||
1501 | ||
1502 | bool | |
1503 | gfc_check_co_reduce (gfc_expr *a, gfc_expr *op, gfc_expr *result_image, | |
1504 | gfc_expr *stat, gfc_expr *errmsg) | |
1505 | { | |
1506 | symbol_attribute attr; | |
1507 | ||
1508 | if (a->ts.type == BT_CLASS) | |
1509 | { | |
1510 | gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic", | |
1511 | &a->where); | |
1512 | return false; | |
1513 | } | |
1514 | ||
1515 | if (gfc_expr_attr (a).alloc_comp) | |
1516 | { | |
1517 | gfc_error ("Support for the A argument at %L with allocatable components" | |
1518 | " is not yet implemented", &a->where); | |
1519 | return false; | |
1520 | } | |
1521 | ||
1522 | attr = gfc_expr_attr (op); | |
1523 | if (!attr.pure || !attr.function) | |
1524 | { | |
1525 | gfc_error ("OPERATOR argument at %L must be a PURE function", | |
1526 | &op->where); | |
1527 | return false; | |
1528 | } | |
1529 | ||
1530 | if (!check_co_collective (a, result_image, stat, errmsg, true)) | |
1531 | return false; | |
1532 | ||
1533 | /* FIXME: After J3/WG5 has decided what they actually exactly want, more | |
1534 | checks such as same-argument checks have to be added, implemented and | |
1535 | intrinsic.texi upated. */ | |
1536 | ||
1537 | gfc_error("CO_REDUCE at %L is not yet implemented", &a->where); | |
1538 | return false; | |
1539 | } | |
1540 | ||
1541 | ||
d62cf3df TB |
1542 | bool |
1543 | gfc_check_co_minmax (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat, | |
1544 | gfc_expr *errmsg) | |
1545 | { | |
1546 | if (a->ts.type != BT_INTEGER && a->ts.type != BT_REAL | |
1547 | && a->ts.type != BT_CHARACTER) | |
1548 | { | |
1549 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall be of type " | |
1550 | "integer, real or character", | |
1551 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, | |
1552 | &a->where); | |
1553 | return false; | |
1554 | } | |
a16ee379 | 1555 | return check_co_collective (a, result_image, stat, errmsg, false); |
d62cf3df TB |
1556 | } |
1557 | ||
1558 | ||
1559 | bool | |
1560 | gfc_check_co_sum (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat, | |
1561 | gfc_expr *errmsg) | |
1562 | { | |
1563 | if (!numeric_check (a, 0)) | |
1564 | return false; | |
a16ee379 | 1565 | return check_co_collective (a, result_image, stat, errmsg, false); |
d62cf3df TB |
1566 | } |
1567 | ||
1568 | ||
524af0d6 | 1569 | bool |
65f8144a | 1570 | gfc_check_complex (gfc_expr *x, gfc_expr *y) |
5d723e54 | 1571 | { |
524af0d6 JB |
1572 | if (!int_or_real_check (x, 0)) |
1573 | return false; | |
1574 | if (!scalar_check (x, 0)) | |
1575 | return false; | |
5d723e54 | 1576 | |
524af0d6 JB |
1577 | if (!int_or_real_check (y, 1)) |
1578 | return false; | |
1579 | if (!scalar_check (y, 1)) | |
1580 | return false; | |
5d723e54 | 1581 | |
524af0d6 | 1582 | return true; |
5d723e54 FXC |
1583 | } |
1584 | ||
1585 | ||
524af0d6 | 1586 | bool |
5cda5098 | 1587 | gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind) |
6de9cd9a | 1588 | { |
524af0d6 JB |
1589 | if (!logical_array_check (mask, 0)) |
1590 | return false; | |
1591 | if (!dim_check (dim, 1, false)) | |
1592 | return false; | |
1593 | if (!dim_rank_check (dim, mask, 0)) | |
1594 | return false; | |
1595 | if (!kind_check (kind, 2, BT_INTEGER)) | |
1596 | return false; | |
1597 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
1598 | "with KIND argument at %L", | |
1599 | gfc_current_intrinsic, &kind->where)) | |
1600 | return false; | |
6de9cd9a | 1601 | |
524af0d6 | 1602 | return true; |
6de9cd9a DN |
1603 | } |
1604 | ||
1605 | ||
524af0d6 | 1606 | bool |
65f8144a | 1607 | gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim) |
6de9cd9a | 1608 | { |
524af0d6 JB |
1609 | if (!array_check (array, 0)) |
1610 | return false; | |
6de9cd9a | 1611 | |
524af0d6 JB |
1612 | if (!type_check (shift, 1, BT_INTEGER)) |
1613 | return false; | |
62ee27a4 | 1614 | |
524af0d6 JB |
1615 | if (!dim_check (dim, 2, true)) |
1616 | return false; | |
ca8a8795 | 1617 | |
524af0d6 JB |
1618 | if (!dim_rank_check (dim, array, false)) |
1619 | return false; | |
ca8a8795 DF |
1620 | |
1621 | if (array->rank == 1 || shift->rank == 0) | |
6de9cd9a | 1622 | { |
524af0d6 JB |
1623 | if (!scalar_check (shift, 1)) |
1624 | return false; | |
6de9cd9a | 1625 | } |
ca8a8795 | 1626 | else if (shift->rank == array->rank - 1) |
6de9cd9a | 1627 | { |
ca8a8795 DF |
1628 | int d; |
1629 | if (!dim) | |
1630 | d = 1; | |
1631 | else if (dim->expr_type == EXPR_CONSTANT) | |
1632 | gfc_extract_int (dim, &d); | |
1633 | else | |
1634 | d = -1; | |
1635 | ||
1636 | if (d > 0) | |
1637 | { | |
1638 | int i, j; | |
1639 | for (i = 0, j = 0; i < array->rank; i++) | |
1640 | if (i != d - 1) | |
1641 | { | |
1642 | if (!identical_dimen_shape (array, i, shift, j)) | |
1643 | { | |
1644 | gfc_error ("'%s' argument of '%s' intrinsic at %L has " | |
1645 | "invalid shape in dimension %d (%ld/%ld)", | |
c4aa95f8 | 1646 | gfc_current_intrinsic_arg[1]->name, |
ca8a8795 DF |
1647 | gfc_current_intrinsic, &shift->where, i + 1, |
1648 | mpz_get_si (array->shape[i]), | |
1649 | mpz_get_si (shift->shape[j])); | |
524af0d6 | 1650 | return false; |
ca8a8795 DF |
1651 | } |
1652 | ||
1653 | j += 1; | |
1654 | } | |
1655 | } | |
1656 | } | |
1657 | else | |
1658 | { | |
1659 | gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank " | |
c4aa95f8 | 1660 | "%d or be a scalar", gfc_current_intrinsic_arg[1]->name, |
ca8a8795 | 1661 | gfc_current_intrinsic, &shift->where, array->rank - 1); |
524af0d6 | 1662 | return false; |
6de9cd9a DN |
1663 | } |
1664 | ||
524af0d6 | 1665 | return true; |
6de9cd9a DN |
1666 | } |
1667 | ||
1668 | ||
524af0d6 | 1669 | bool |
65f8144a | 1670 | gfc_check_ctime (gfc_expr *time) |
35059811 | 1671 | { |
524af0d6 JB |
1672 | if (!scalar_check (time, 0)) |
1673 | return false; | |
35059811 | 1674 | |
524af0d6 JB |
1675 | if (!type_check (time, 0, BT_INTEGER)) |
1676 | return false; | |
35059811 | 1677 | |
524af0d6 | 1678 | return true; |
35059811 FXC |
1679 | } |
1680 | ||
1681 | ||
524af0d6 | 1682 | bool gfc_check_datan2 (gfc_expr *y, gfc_expr *x) |
15ead859 | 1683 | { |
524af0d6 JB |
1684 | if (!double_check (y, 0) || !double_check (x, 1)) |
1685 | return false; | |
15ead859 | 1686 | |
524af0d6 | 1687 | return true; |
15ead859 JD |
1688 | } |
1689 | ||
524af0d6 | 1690 | bool |
65f8144a | 1691 | gfc_check_dcmplx (gfc_expr *x, gfc_expr *y) |
6de9cd9a | 1692 | { |
524af0d6 JB |
1693 | if (!numeric_check (x, 0)) |
1694 | return false; | |
6de9cd9a DN |
1695 | |
1696 | if (y != NULL) | |
1697 | { | |
524af0d6 JB |
1698 | if (!numeric_check (y, 1)) |
1699 | return false; | |
6de9cd9a DN |
1700 | |
1701 | if (x->ts.type == BT_COMPLEX) | |
1702 | { | |
4c93c95a | 1703 | gfc_error ("'%s' argument of '%s' intrinsic at %L must not be " |
c4aa95f8 JW |
1704 | "present if 'x' is COMPLEX", |
1705 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
1706 | &y->where); | |
524af0d6 | 1707 | return false; |
6de9cd9a | 1708 | } |
20562de4 SK |
1709 | |
1710 | if (y->ts.type == BT_COMPLEX) | |
1711 | { | |
1712 | gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type " | |
c4aa95f8 JW |
1713 | "of either REAL or INTEGER", |
1714 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
1715 | &y->where); | |
524af0d6 | 1716 | return false; |
20562de4 | 1717 | } |
6de9cd9a DN |
1718 | } |
1719 | ||
524af0d6 | 1720 | return true; |
6de9cd9a DN |
1721 | } |
1722 | ||
1723 | ||
524af0d6 | 1724 | bool |
65f8144a | 1725 | gfc_check_dble (gfc_expr *x) |
6de9cd9a | 1726 | { |
524af0d6 JB |
1727 | if (!numeric_check (x, 0)) |
1728 | return false; | |
6de9cd9a | 1729 | |
524af0d6 | 1730 | return true; |
6de9cd9a DN |
1731 | } |
1732 | ||
1733 | ||
524af0d6 | 1734 | bool |
65f8144a | 1735 | gfc_check_digits (gfc_expr *x) |
6de9cd9a | 1736 | { |
524af0d6 JB |
1737 | if (!int_or_real_check (x, 0)) |
1738 | return false; | |
6de9cd9a | 1739 | |
524af0d6 | 1740 | return true; |
6de9cd9a DN |
1741 | } |
1742 | ||
1743 | ||
524af0d6 | 1744 | bool |
65f8144a | 1745 | gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b) |
6de9cd9a | 1746 | { |
6de9cd9a DN |
1747 | switch (vector_a->ts.type) |
1748 | { | |
1749 | case BT_LOGICAL: | |
524af0d6 JB |
1750 | if (!type_check (vector_b, 1, BT_LOGICAL)) |
1751 | return false; | |
6de9cd9a DN |
1752 | break; |
1753 | ||
1754 | case BT_INTEGER: | |
1755 | case BT_REAL: | |
1756 | case BT_COMPLEX: | |
524af0d6 JB |
1757 | if (!numeric_check (vector_b, 1)) |
1758 | return false; | |
6de9cd9a DN |
1759 | break; |
1760 | ||
1761 | default: | |
4c93c95a | 1762 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric " |
c4aa95f8 | 1763 | "or LOGICAL", gfc_current_intrinsic_arg[0]->name, |
4c93c95a | 1764 | gfc_current_intrinsic, &vector_a->where); |
524af0d6 | 1765 | return false; |
6de9cd9a DN |
1766 | } |
1767 | ||
524af0d6 JB |
1768 | if (!rank_check (vector_a, 0, 1)) |
1769 | return false; | |
6de9cd9a | 1770 | |
524af0d6 JB |
1771 | if (!rank_check (vector_b, 1, 1)) |
1772 | return false; | |
6de9cd9a | 1773 | |
a8999235 TK |
1774 | if (! identical_dimen_shape (vector_a, 0, vector_b, 0)) |
1775 | { | |
7e49f965 | 1776 | gfc_error ("Different shape for arguments '%s' and '%s' at %L for " |
c4aa95f8 JW |
1777 | "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0]->name, |
1778 | gfc_current_intrinsic_arg[1]->name, &vector_a->where); | |
524af0d6 | 1779 | return false; |
a8999235 TK |
1780 | } |
1781 | ||
524af0d6 | 1782 | return true; |
6de9cd9a DN |
1783 | } |
1784 | ||
1785 | ||
524af0d6 | 1786 | bool |
15ead859 JD |
1787 | gfc_check_dprod (gfc_expr *x, gfc_expr *y) |
1788 | { | |
524af0d6 JB |
1789 | if (!type_check (x, 0, BT_REAL) |
1790 | || !type_check (y, 1, BT_REAL)) | |
1791 | return false; | |
15ead859 JD |
1792 | |
1793 | if (x->ts.kind != gfc_default_real_kind) | |
1794 | { | |
1795 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be default " | |
c4aa95f8 | 1796 | "real", gfc_current_intrinsic_arg[0]->name, |
15ead859 | 1797 | gfc_current_intrinsic, &x->where); |
524af0d6 | 1798 | return false; |
15ead859 JD |
1799 | } |
1800 | ||
1801 | if (y->ts.kind != gfc_default_real_kind) | |
1802 | { | |
1803 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be default " | |
c4aa95f8 | 1804 | "real", gfc_current_intrinsic_arg[1]->name, |
15ead859 | 1805 | gfc_current_intrinsic, &y->where); |
524af0d6 | 1806 | return false; |
15ead859 JD |
1807 | } |
1808 | ||
524af0d6 | 1809 | return true; |
15ead859 JD |
1810 | } |
1811 | ||
1812 | ||
524af0d6 | 1813 | bool |
88a95a11 FXC |
1814 | gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift) |
1815 | { | |
524af0d6 JB |
1816 | if (!type_check (i, 0, BT_INTEGER)) |
1817 | return false; | |
88a95a11 | 1818 | |
524af0d6 JB |
1819 | if (!type_check (j, 1, BT_INTEGER)) |
1820 | return false; | |
88a95a11 | 1821 | |
05168bb7 SK |
1822 | if (i->is_boz && j->is_boz) |
1823 | { | |
1824 | gfc_error ("'I' at %L and 'J' at %L cannot both be BOZ literal " | |
1825 | "constants", &i->where, &j->where); | |
524af0d6 | 1826 | return false; |
05168bb7 SK |
1827 | } |
1828 | ||
524af0d6 JB |
1829 | if (!i->is_boz && !j->is_boz && !same_type_check (i, 0, j, 1)) |
1830 | return false; | |
88a95a11 | 1831 | |
524af0d6 JB |
1832 | if (!type_check (shift, 2, BT_INTEGER)) |
1833 | return false; | |
88a95a11 | 1834 | |
524af0d6 JB |
1835 | if (!nonnegative_check ("SHIFT", shift)) |
1836 | return false; | |
88a95a11 | 1837 | |
05168bb7 SK |
1838 | if (i->is_boz) |
1839 | { | |
524af0d6 JB |
1840 | if (!less_than_bitsize1 ("J", j, "SHIFT", shift, true)) |
1841 | return false; | |
05168bb7 SK |
1842 | i->ts.kind = j->ts.kind; |
1843 | } | |
1844 | else | |
1845 | { | |
524af0d6 JB |
1846 | if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true)) |
1847 | return false; | |
05168bb7 SK |
1848 | j->ts.kind = i->ts.kind; |
1849 | } | |
88a95a11 | 1850 | |
524af0d6 | 1851 | return true; |
88a95a11 FXC |
1852 | } |
1853 | ||
1854 | ||
524af0d6 | 1855 | bool |
65f8144a SK |
1856 | gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary, |
1857 | gfc_expr *dim) | |
6de9cd9a | 1858 | { |
524af0d6 JB |
1859 | if (!array_check (array, 0)) |
1860 | return false; | |
6de9cd9a | 1861 | |
524af0d6 JB |
1862 | if (!type_check (shift, 1, BT_INTEGER)) |
1863 | return false; | |
6de9cd9a | 1864 | |
524af0d6 JB |
1865 | if (!dim_check (dim, 3, true)) |
1866 | return false; | |
ca8a8795 | 1867 | |
524af0d6 JB |
1868 | if (!dim_rank_check (dim, array, false)) |
1869 | return false; | |
ca8a8795 DF |
1870 | |
1871 | if (array->rank == 1 || shift->rank == 0) | |
6de9cd9a | 1872 | { |
524af0d6 JB |
1873 | if (!scalar_check (shift, 1)) |
1874 | return false; | |
6de9cd9a | 1875 | } |
ca8a8795 | 1876 | else if (shift->rank == array->rank - 1) |
6de9cd9a | 1877 | { |
ca8a8795 DF |
1878 | int d; |
1879 | if (!dim) | |
1880 | d = 1; | |
1881 | else if (dim->expr_type == EXPR_CONSTANT) | |
1882 | gfc_extract_int (dim, &d); | |
1883 | else | |
1884 | d = -1; | |
1885 | ||
1886 | if (d > 0) | |
1887 | { | |
1888 | int i, j; | |
1889 | for (i = 0, j = 0; i < array->rank; i++) | |
1890 | if (i != d - 1) | |
1891 | { | |
1892 | if (!identical_dimen_shape (array, i, shift, j)) | |
1893 | { | |
1894 | gfc_error ("'%s' argument of '%s' intrinsic at %L has " | |
1895 | "invalid shape in dimension %d (%ld/%ld)", | |
c4aa95f8 | 1896 | gfc_current_intrinsic_arg[1]->name, |
ca8a8795 DF |
1897 | gfc_current_intrinsic, &shift->where, i + 1, |
1898 | mpz_get_si (array->shape[i]), | |
1899 | mpz_get_si (shift->shape[j])); | |
524af0d6 | 1900 | return false; |
ca8a8795 DF |
1901 | } |
1902 | ||
1903 | j += 1; | |
1904 | } | |
1905 | } | |
1906 | } | |
1907 | else | |
1908 | { | |
1909 | gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank " | |
c4aa95f8 | 1910 | "%d or be a scalar", gfc_current_intrinsic_arg[1]->name, |
ca8a8795 | 1911 | gfc_current_intrinsic, &shift->where, array->rank - 1); |
524af0d6 | 1912 | return false; |
6de9cd9a DN |
1913 | } |
1914 | ||
1915 | if (boundary != NULL) | |
1916 | { | |
524af0d6 JB |
1917 | if (!same_type_check (array, 0, boundary, 2)) |
1918 | return false; | |
6de9cd9a | 1919 | |
ca8a8795 | 1920 | if (array->rank == 1 || boundary->rank == 0) |
d1a296c1 | 1921 | { |
524af0d6 JB |
1922 | if (!scalar_check (boundary, 2)) |
1923 | return false; | |
d1a296c1 | 1924 | } |
ca8a8795 | 1925 | else if (boundary->rank == array->rank - 1) |
d1a296c1 | 1926 | { |
524af0d6 JB |
1927 | if (!gfc_check_conformance (shift, boundary, |
1928 | "arguments '%s' and '%s' for " | |
1929 | "intrinsic %s", | |
1930 | gfc_current_intrinsic_arg[1]->name, | |
1931 | gfc_current_intrinsic_arg[2]->name, | |
1932 | gfc_current_intrinsic)) | |
1933 | return false; | |
d1a296c1 | 1934 | } |
ca8a8795 | 1935 | else |
d1a296c1 | 1936 | { |
ca8a8795 | 1937 | gfc_error ("'%s' argument of intrinsic '%s' at %L of must have " |
c4aa95f8 JW |
1938 | "rank %d or be a scalar", |
1939 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
1940 | &shift->where, array->rank - 1); | |
524af0d6 | 1941 | return false; |
d1a296c1 | 1942 | } |
6de9cd9a DN |
1943 | } |
1944 | ||
524af0d6 | 1945 | return true; |
6de9cd9a DN |
1946 | } |
1947 | ||
524af0d6 | 1948 | bool |
c9018c71 DF |
1949 | gfc_check_float (gfc_expr *a) |
1950 | { | |
524af0d6 JB |
1951 | if (!type_check (a, 0, BT_INTEGER)) |
1952 | return false; | |
c9018c71 DF |
1953 | |
1954 | if ((a->ts.kind != gfc_default_integer_kind) | |
524af0d6 JB |
1955 | && !gfc_notify_std (GFC_STD_GNU, "non-default INTEGER " |
1956 | "kind argument to %s intrinsic at %L", | |
1957 | gfc_current_intrinsic, &a->where)) | |
1958 | return false; | |
c9018c71 | 1959 | |
524af0d6 | 1960 | return true; |
c9018c71 | 1961 | } |
6de9cd9a | 1962 | |
985aff9c PB |
1963 | /* A single complex argument. */ |
1964 | ||
524af0d6 | 1965 | bool |
65f8144a | 1966 | gfc_check_fn_c (gfc_expr *a) |
985aff9c | 1967 | { |
524af0d6 JB |
1968 | if (!type_check (a, 0, BT_COMPLEX)) |
1969 | return false; | |
985aff9c | 1970 | |
524af0d6 | 1971 | return true; |
985aff9c PB |
1972 | } |
1973 | ||
985aff9c PB |
1974 | /* A single real argument. */ |
1975 | ||
524af0d6 | 1976 | bool |
65f8144a | 1977 | gfc_check_fn_r (gfc_expr *a) |
985aff9c | 1978 | { |
524af0d6 JB |
1979 | if (!type_check (a, 0, BT_REAL)) |
1980 | return false; | |
985aff9c | 1981 | |
524af0d6 | 1982 | return true; |
985aff9c PB |
1983 | } |
1984 | ||
15ead859 JD |
1985 | /* A single double argument. */ |
1986 | ||
524af0d6 | 1987 | bool |
15ead859 JD |
1988 | gfc_check_fn_d (gfc_expr *a) |
1989 | { | |
524af0d6 JB |
1990 | if (!double_check (a, 0)) |
1991 | return false; | |
15ead859 | 1992 | |
524af0d6 | 1993 | return true; |
15ead859 | 1994 | } |
985aff9c PB |
1995 | |
1996 | /* A single real or complex argument. */ | |
1997 | ||
524af0d6 | 1998 | bool |
65f8144a | 1999 | gfc_check_fn_rc (gfc_expr *a) |
985aff9c | 2000 | { |
524af0d6 JB |
2001 | if (!real_or_complex_check (a, 0)) |
2002 | return false; | |
985aff9c | 2003 | |
524af0d6 | 2004 | return true; |
985aff9c PB |
2005 | } |
2006 | ||
2007 | ||
524af0d6 | 2008 | bool |
8d3681f9 TB |
2009 | gfc_check_fn_rc2008 (gfc_expr *a) |
2010 | { | |
524af0d6 JB |
2011 | if (!real_or_complex_check (a, 0)) |
2012 | return false; | |
8d3681f9 TB |
2013 | |
2014 | if (a->ts.type == BT_COMPLEX | |
b5704581 DH |
2015 | && !gfc_notify_std (GFC_STD_F2008, "COMPLEX argument '%s' " |
2016 | "of '%s' intrinsic at %L", | |
524af0d6 JB |
2017 | gfc_current_intrinsic_arg[0]->name, |
2018 | gfc_current_intrinsic, &a->where)) | |
2019 | return false; | |
8d3681f9 | 2020 | |
524af0d6 | 2021 | return true; |
8d3681f9 TB |
2022 | } |
2023 | ||
2024 | ||
524af0d6 | 2025 | bool |
65f8144a | 2026 | gfc_check_fnum (gfc_expr *unit) |
df65f093 | 2027 | { |
524af0d6 JB |
2028 | if (!type_check (unit, 0, BT_INTEGER)) |
2029 | return false; | |
df65f093 | 2030 | |
524af0d6 JB |
2031 | if (!scalar_check (unit, 0)) |
2032 | return false; | |
df65f093 | 2033 | |
524af0d6 | 2034 | return true; |
df65f093 SK |
2035 | } |
2036 | ||
2037 | ||
524af0d6 | 2038 | bool |
65f8144a | 2039 | gfc_check_huge (gfc_expr *x) |
6de9cd9a | 2040 | { |
524af0d6 JB |
2041 | if (!int_or_real_check (x, 0)) |
2042 | return false; | |
6de9cd9a | 2043 | |
524af0d6 | 2044 | return true; |
6de9cd9a DN |
2045 | } |
2046 | ||
2047 | ||
524af0d6 | 2048 | bool |
f489fba1 FXC |
2049 | gfc_check_hypot (gfc_expr *x, gfc_expr *y) |
2050 | { | |
524af0d6 JB |
2051 | if (!type_check (x, 0, BT_REAL)) |
2052 | return false; | |
2053 | if (!same_type_check (x, 0, y, 1)) | |
2054 | return false; | |
f489fba1 | 2055 | |
524af0d6 | 2056 | return true; |
f489fba1 FXC |
2057 | } |
2058 | ||
2059 | ||
6de9cd9a DN |
2060 | /* Check that the single argument is an integer. */ |
2061 | ||
524af0d6 | 2062 | bool |
65f8144a | 2063 | gfc_check_i (gfc_expr *i) |
6de9cd9a | 2064 | { |
524af0d6 JB |
2065 | if (!type_check (i, 0, BT_INTEGER)) |
2066 | return false; | |
6de9cd9a | 2067 | |
524af0d6 | 2068 | return true; |
6de9cd9a DN |
2069 | } |
2070 | ||
2071 | ||
524af0d6 | 2072 | bool |
65f8144a | 2073 | gfc_check_iand (gfc_expr *i, gfc_expr *j) |
6de9cd9a | 2074 | { |
524af0d6 JB |
2075 | if (!type_check (i, 0, BT_INTEGER)) |
2076 | return false; | |
6de9cd9a | 2077 | |
524af0d6 JB |
2078 | if (!type_check (j, 1, BT_INTEGER)) |
2079 | return false; | |
6de9cd9a | 2080 | |
c3d003d2 SK |
2081 | if (i->ts.kind != j->ts.kind) |
2082 | { | |
524af0d6 JB |
2083 | if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L", |
2084 | &i->where)) | |
2085 | return false; | |
c3d003d2 SK |
2086 | } |
2087 | ||
524af0d6 | 2088 | return true; |
6de9cd9a DN |
2089 | } |
2090 | ||
2091 | ||
524af0d6 | 2092 | bool |
65f8144a | 2093 | gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len) |
6de9cd9a | 2094 | { |
524af0d6 JB |
2095 | if (!type_check (i, 0, BT_INTEGER)) |
2096 | return false; | |
c3d003d2 | 2097 | |
524af0d6 JB |
2098 | if (!type_check (pos, 1, BT_INTEGER)) |
2099 | return false; | |
c3d003d2 | 2100 | |
524af0d6 JB |
2101 | if (!type_check (len, 2, BT_INTEGER)) |
2102 | return false; | |
6de9cd9a | 2103 | |
524af0d6 JB |
2104 | if (!nonnegative_check ("pos", pos)) |
2105 | return false; | |
6de9cd9a | 2106 | |
524af0d6 JB |
2107 | if (!nonnegative_check ("len", len)) |
2108 | return false; | |
c3d003d2 | 2109 | |
524af0d6 JB |
2110 | if (!less_than_bitsize2 ("i", i, "pos", pos, "len", len)) |
2111 | return false; | |
6de9cd9a | 2112 | |
524af0d6 | 2113 | return true; |
6de9cd9a DN |
2114 | } |
2115 | ||
2116 | ||
524af0d6 | 2117 | bool |
5cda5098 | 2118 | gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind) |
860c8f3b PB |
2119 | { |
2120 | int i; | |
2121 | ||
524af0d6 JB |
2122 | if (!type_check (c, 0, BT_CHARACTER)) |
2123 | return false; | |
860c8f3b | 2124 | |
524af0d6 JB |
2125 | if (!kind_check (kind, 1, BT_INTEGER)) |
2126 | return false; | |
5cda5098 | 2127 | |
524af0d6 JB |
2128 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " |
2129 | "with KIND argument at %L", | |
2130 | gfc_current_intrinsic, &kind->where)) | |
2131 | return false; | |
5cda5098 | 2132 | |
78bd27f6 | 2133 | if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING) |
860c8f3b PB |
2134 | { |
2135 | gfc_expr *start; | |
2136 | gfc_expr *end; | |
2137 | gfc_ref *ref; | |
2138 | ||
2139 | /* Substring references don't have the charlength set. */ | |
2140 | ref = c->ref; | |
2141 | while (ref && ref->type != REF_SUBSTRING) | |
2142 | ref = ref->next; | |
2143 | ||
2144 | gcc_assert (ref == NULL || ref->type == REF_SUBSTRING); | |
2145 | ||
2146 | if (!ref) | |
78bd27f6 | 2147 | { |
65f8144a | 2148 | /* Check that the argument is length one. Non-constant lengths |
e2ae1407 | 2149 | can't be checked here, so assume they are ok. */ |
bc21d315 | 2150 | if (c->ts.u.cl && c->ts.u.cl->length) |
78bd27f6 AP |
2151 | { |
2152 | /* If we already have a length for this expression then use it. */ | |
bc21d315 | 2153 | if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT) |
524af0d6 | 2154 | return true; |
bc21d315 | 2155 | i = mpz_get_si (c->ts.u.cl->length->value.integer); |
78bd27f6 | 2156 | } |
8b704316 | 2157 | else |
524af0d6 | 2158 | return true; |
78bd27f6 AP |
2159 | } |
2160 | else | |
2161 | { | |
2162 | start = ref->u.ss.start; | |
2163 | end = ref->u.ss.end; | |
860c8f3b | 2164 | |
78bd27f6 AP |
2165 | gcc_assert (start); |
2166 | if (end == NULL || end->expr_type != EXPR_CONSTANT | |
2167 | || start->expr_type != EXPR_CONSTANT) | |
524af0d6 | 2168 | return true; |
860c8f3b | 2169 | |
78bd27f6 | 2170 | i = mpz_get_si (end->value.integer) + 1 |
65f8144a | 2171 | - mpz_get_si (start->value.integer); |
78bd27f6 | 2172 | } |
860c8f3b PB |
2173 | } |
2174 | else | |
524af0d6 | 2175 | return true; |
860c8f3b PB |
2176 | |
2177 | if (i != 1) | |
2178 | { | |
8b704316 | 2179 | gfc_error ("Argument of %s at %L must be of length one", |
860c8f3b | 2180 | gfc_current_intrinsic, &c->where); |
524af0d6 | 2181 | return false; |
860c8f3b PB |
2182 | } |
2183 | ||
524af0d6 | 2184 | return true; |
860c8f3b PB |
2185 | } |
2186 | ||
2187 | ||
524af0d6 | 2188 | bool |
65f8144a | 2189 | gfc_check_idnint (gfc_expr *a) |
6de9cd9a | 2190 | { |
524af0d6 JB |
2191 | if (!double_check (a, 0)) |
2192 | return false; | |
6de9cd9a | 2193 | |
524af0d6 | 2194 | return true; |
6de9cd9a DN |
2195 | } |
2196 | ||
2197 | ||
524af0d6 | 2198 | bool |
65f8144a | 2199 | gfc_check_ieor (gfc_expr *i, gfc_expr *j) |
6de9cd9a | 2200 | { |
524af0d6 JB |
2201 | if (!type_check (i, 0, BT_INTEGER)) |
2202 | return false; | |
6de9cd9a | 2203 | |
524af0d6 JB |
2204 | if (!type_check (j, 1, BT_INTEGER)) |
2205 | return false; | |
6de9cd9a | 2206 | |
c3d003d2 SK |
2207 | if (i->ts.kind != j->ts.kind) |
2208 | { | |
524af0d6 JB |
2209 | if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L", |
2210 | &i->where)) | |
2211 | return false; | |
c3d003d2 SK |
2212 | } |
2213 | ||
524af0d6 | 2214 | return true; |
6de9cd9a DN |
2215 | } |
2216 | ||
2217 | ||
524af0d6 | 2218 | bool |
5cda5098 FXC |
2219 | gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back, |
2220 | gfc_expr *kind) | |
6de9cd9a | 2221 | { |
524af0d6 JB |
2222 | if (!type_check (string, 0, BT_CHARACTER) |
2223 | || !type_check (substring, 1, BT_CHARACTER)) | |
2224 | return false; | |
6de9cd9a | 2225 | |
524af0d6 JB |
2226 | if (back != NULL && !type_check (back, 2, BT_LOGICAL)) |
2227 | return false; | |
6de9cd9a | 2228 | |
524af0d6 JB |
2229 | if (!kind_check (kind, 3, BT_INTEGER)) |
2230 | return false; | |
2231 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
2232 | "with KIND argument at %L", | |
2233 | gfc_current_intrinsic, &kind->where)) | |
2234 | return false; | |
5cda5098 | 2235 | |
6de9cd9a DN |
2236 | if (string->ts.kind != substring->ts.kind) |
2237 | { | |
4c93c95a | 2238 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same " |
c4aa95f8 | 2239 | "kind as '%s'", gfc_current_intrinsic_arg[1]->name, |
4c93c95a | 2240 | gfc_current_intrinsic, &substring->where, |
c4aa95f8 | 2241 | gfc_current_intrinsic_arg[0]->name); |
524af0d6 | 2242 | return false; |
6de9cd9a DN |
2243 | } |
2244 | ||
524af0d6 | 2245 | return true; |
6de9cd9a DN |
2246 | } |
2247 | ||
2248 | ||
524af0d6 | 2249 | bool |
65f8144a | 2250 | gfc_check_int (gfc_expr *x, gfc_expr *kind) |
6de9cd9a | 2251 | { |
524af0d6 JB |
2252 | if (!numeric_check (x, 0)) |
2253 | return false; | |
c60d77d4 | 2254 | |
524af0d6 JB |
2255 | if (!kind_check (kind, 1, BT_INTEGER)) |
2256 | return false; | |
c60d77d4 | 2257 | |
524af0d6 | 2258 | return true; |
6de9cd9a DN |
2259 | } |
2260 | ||
2261 | ||
524af0d6 | 2262 | bool |
65f8144a | 2263 | gfc_check_intconv (gfc_expr *x) |
bf3fb7e4 | 2264 | { |
524af0d6 JB |
2265 | if (!numeric_check (x, 0)) |
2266 | return false; | |
bf3fb7e4 | 2267 | |
524af0d6 | 2268 | return true; |
bf3fb7e4 FXC |
2269 | } |
2270 | ||
2271 | ||
524af0d6 | 2272 | bool |
65f8144a | 2273 | gfc_check_ior (gfc_expr *i, gfc_expr *j) |
6de9cd9a | 2274 | { |
524af0d6 JB |
2275 | if (!type_check (i, 0, BT_INTEGER)) |
2276 | return false; | |
6de9cd9a | 2277 | |
524af0d6 JB |
2278 | if (!type_check (j, 1, BT_INTEGER)) |
2279 | return false; | |
6de9cd9a | 2280 | |
c3d003d2 SK |
2281 | if (i->ts.kind != j->ts.kind) |
2282 | { | |
524af0d6 JB |
2283 | if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L", |
2284 | &i->where)) | |
2285 | return false; | |
c3d003d2 SK |
2286 | } |
2287 | ||
524af0d6 | 2288 | return true; |
6de9cd9a DN |
2289 | } |
2290 | ||
2291 | ||
524af0d6 | 2292 | bool |
65f8144a | 2293 | gfc_check_ishft (gfc_expr *i, gfc_expr *shift) |
6de9cd9a | 2294 | { |
524af0d6 JB |
2295 | if (!type_check (i, 0, BT_INTEGER) |
2296 | || !type_check (shift, 1, BT_INTEGER)) | |
2297 | return false; | |
6de9cd9a | 2298 | |
524af0d6 JB |
2299 | if (!less_than_bitsize1 ("I", i, NULL, shift, true)) |
2300 | return false; | |
0019028b | 2301 | |
524af0d6 | 2302 | return true; |
6de9cd9a DN |
2303 | } |
2304 | ||
2305 | ||
524af0d6 | 2306 | bool |
65f8144a | 2307 | gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size) |
6de9cd9a | 2308 | { |
524af0d6 JB |
2309 | if (!type_check (i, 0, BT_INTEGER) |
2310 | || !type_check (shift, 1, BT_INTEGER)) | |
2311 | return false; | |
6de9cd9a | 2312 | |
8b704316 | 2313 | if (size != NULL) |
0019028b SK |
2314 | { |
2315 | int i2, i3; | |
2316 | ||
524af0d6 JB |
2317 | if (!type_check (size, 2, BT_INTEGER)) |
2318 | return false; | |
0019028b | 2319 | |
524af0d6 JB |
2320 | if (!less_than_bitsize1 ("I", i, "SIZE", size, true)) |
2321 | return false; | |
0019028b | 2322 | |
6d8c9e5c | 2323 | if (size->expr_type == EXPR_CONSTANT) |
0019028b | 2324 | { |
6d8c9e5c SK |
2325 | gfc_extract_int (size, &i3); |
2326 | if (i3 <= 0) | |
2327 | { | |
2328 | gfc_error ("SIZE at %L must be positive", &size->where); | |
524af0d6 | 2329 | return false; |
6d8c9e5c | 2330 | } |
0019028b | 2331 | |
6d8c9e5c SK |
2332 | if (shift->expr_type == EXPR_CONSTANT) |
2333 | { | |
2334 | gfc_extract_int (shift, &i2); | |
2335 | if (i2 < 0) | |
2336 | i2 = -i2; | |
2337 | ||
2338 | if (i2 > i3) | |
2339 | { | |
2340 | gfc_error ("The absolute value of SHIFT at %L must be less " | |
2341 | "than or equal to SIZE at %L", &shift->where, | |
2342 | &size->where); | |
524af0d6 | 2343 | return false; |
6d8c9e5c SK |
2344 | } |
2345 | } | |
0019028b SK |
2346 | } |
2347 | } | |
524af0d6 JB |
2348 | else if (!less_than_bitsize1 ("I", i, NULL, shift, true)) |
2349 | return false; | |
6de9cd9a | 2350 | |
524af0d6 | 2351 | return true; |
6de9cd9a DN |
2352 | } |
2353 | ||
2354 | ||
524af0d6 | 2355 | bool |
65f8144a | 2356 | gfc_check_kill (gfc_expr *pid, gfc_expr *sig) |
f77b6ca3 | 2357 | { |
524af0d6 JB |
2358 | if (!type_check (pid, 0, BT_INTEGER)) |
2359 | return false; | |
f77b6ca3 | 2360 | |
524af0d6 JB |
2361 | if (!type_check (sig, 1, BT_INTEGER)) |
2362 | return false; | |
f77b6ca3 | 2363 | |
524af0d6 | 2364 | return true; |
f77b6ca3 FXC |
2365 | } |
2366 | ||
2367 | ||
524af0d6 | 2368 | bool |
65f8144a | 2369 | gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status) |
f77b6ca3 | 2370 | { |
524af0d6 JB |
2371 | if (!type_check (pid, 0, BT_INTEGER)) |
2372 | return false; | |
f77b6ca3 | 2373 | |
524af0d6 JB |
2374 | if (!scalar_check (pid, 0)) |
2375 | return false; | |
c7944152 | 2376 | |
524af0d6 JB |
2377 | if (!type_check (sig, 1, BT_INTEGER)) |
2378 | return false; | |
f77b6ca3 | 2379 | |
524af0d6 JB |
2380 | if (!scalar_check (sig, 1)) |
2381 | return false; | |
c7944152 | 2382 | |
f77b6ca3 | 2383 | if (status == NULL) |
524af0d6 | 2384 | return true; |
f77b6ca3 | 2385 | |
524af0d6 JB |
2386 | if (!type_check (status, 2, BT_INTEGER)) |
2387 | return false; | |
f77b6ca3 | 2388 | |
524af0d6 JB |
2389 | if (!scalar_check (status, 2)) |
2390 | return false; | |
f77b6ca3 | 2391 | |
524af0d6 | 2392 | return true; |
f77b6ca3 FXC |
2393 | } |
2394 | ||
2395 | ||
524af0d6 | 2396 | bool |
65f8144a | 2397 | gfc_check_kind (gfc_expr *x) |
6de9cd9a | 2398 | { |
6de9cd9a DN |
2399 | if (x->ts.type == BT_DERIVED) |
2400 | { | |
4c93c95a | 2401 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a " |
c4aa95f8 | 2402 | "non-derived type", gfc_current_intrinsic_arg[0]->name, |
4c93c95a | 2403 | gfc_current_intrinsic, &x->where); |
524af0d6 | 2404 | return false; |
6de9cd9a DN |
2405 | } |
2406 | ||
524af0d6 | 2407 | return true; |
6de9cd9a DN |
2408 | } |
2409 | ||
2410 | ||
524af0d6 | 2411 | bool |
5cda5098 | 2412 | gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
6de9cd9a | 2413 | { |
524af0d6 JB |
2414 | if (!array_check (array, 0)) |
2415 | return false; | |
6de9cd9a | 2416 | |
524af0d6 JB |
2417 | if (!dim_check (dim, 1, false)) |
2418 | return false; | |
6de9cd9a | 2419 | |
524af0d6 JB |
2420 | if (!dim_rank_check (dim, array, 1)) |
2421 | return false; | |
5cda5098 | 2422 | |
524af0d6 JB |
2423 | if (!kind_check (kind, 2, BT_INTEGER)) |
2424 | return false; | |
2425 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
2426 | "with KIND argument at %L", | |
2427 | gfc_current_intrinsic, &kind->where)) | |
2428 | return false; | |
5cda5098 | 2429 | |
524af0d6 | 2430 | return true; |
5cda5098 FXC |
2431 | } |
2432 | ||
2433 | ||
524af0d6 | 2434 | bool |
64f002ed TB |
2435 | gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind) |
2436 | { | |
2437 | if (gfc_option.coarray == GFC_FCOARRAY_NONE) | |
2438 | { | |
2439 | gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable"); | |
524af0d6 | 2440 | return false; |
64f002ed TB |
2441 | } |
2442 | ||
524af0d6 JB |
2443 | if (!coarray_check (coarray, 0)) |
2444 | return false; | |
64f002ed TB |
2445 | |
2446 | if (dim != NULL) | |
2447 | { | |
524af0d6 JB |
2448 | if (!dim_check (dim, 1, false)) |
2449 | return false; | |
64f002ed | 2450 | |
524af0d6 JB |
2451 | if (!dim_corank_check (dim, coarray)) |
2452 | return false; | |
64f002ed TB |
2453 | } |
2454 | ||
524af0d6 JB |
2455 | if (!kind_check (kind, 2, BT_INTEGER)) |
2456 | return false; | |
64f002ed | 2457 | |
524af0d6 | 2458 | return true; |
64f002ed TB |
2459 | } |
2460 | ||
2461 | ||
524af0d6 | 2462 | bool |
5cda5098 FXC |
2463 | gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind) |
2464 | { | |
524af0d6 JB |
2465 | if (!type_check (s, 0, BT_CHARACTER)) |
2466 | return false; | |
5cda5098 | 2467 | |
524af0d6 JB |
2468 | if (!kind_check (kind, 1, BT_INTEGER)) |
2469 | return false; | |
2470 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
2471 | "with KIND argument at %L", | |
2472 | gfc_current_intrinsic, &kind->where)) | |
2473 | return false; | |
5cda5098 | 2474 | |
524af0d6 | 2475 | return true; |
6de9cd9a DN |
2476 | } |
2477 | ||
2478 | ||
524af0d6 | 2479 | bool |
d393bbd7 FXC |
2480 | gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b) |
2481 | { | |
524af0d6 JB |
2482 | if (!type_check (a, 0, BT_CHARACTER)) |
2483 | return false; | |
2484 | if (!kind_value_check (a, 0, gfc_default_character_kind)) | |
2485 | return false; | |
d393bbd7 | 2486 | |
524af0d6 JB |
2487 | if (!type_check (b, 1, BT_CHARACTER)) |
2488 | return false; | |
2489 | if (!kind_value_check (b, 1, gfc_default_character_kind)) | |
2490 | return false; | |
d393bbd7 | 2491 | |
524af0d6 | 2492 | return true; |
d393bbd7 FXC |
2493 | } |
2494 | ||
2495 | ||
524af0d6 | 2496 | bool |
65f8144a | 2497 | gfc_check_link (gfc_expr *path1, gfc_expr *path2) |
f77b6ca3 | 2498 | { |
524af0d6 JB |
2499 | if (!type_check (path1, 0, BT_CHARACTER)) |
2500 | return false; | |
2501 | if (!kind_value_check (path1, 0, gfc_default_character_kind)) | |
2502 | return false; | |
f77b6ca3 | 2503 | |
524af0d6 JB |
2504 | if (!type_check (path2, 1, BT_CHARACTER)) |
2505 | return false; | |
2506 | if (!kind_value_check (path2, 1, gfc_default_character_kind)) | |
2507 | return false; | |
f77b6ca3 | 2508 | |
524af0d6 | 2509 | return true; |
f77b6ca3 FXC |
2510 | } |
2511 | ||
2512 | ||
524af0d6 | 2513 | bool |
65f8144a | 2514 | gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status) |
f77b6ca3 | 2515 | { |
524af0d6 JB |
2516 | if (!type_check (path1, 0, BT_CHARACTER)) |
2517 | return false; | |
2518 | if (!kind_value_check (path1, 0, gfc_default_character_kind)) | |
2519 | return false; | |
f77b6ca3 | 2520 | |
524af0d6 JB |
2521 | if (!type_check (path2, 1, BT_CHARACTER)) |
2522 | return false; | |
2523 | if (!kind_value_check (path2, 0, gfc_default_character_kind)) | |
2524 | return false; | |
f77b6ca3 FXC |
2525 | |
2526 | if (status == NULL) | |
524af0d6 | 2527 | return true; |
f77b6ca3 | 2528 | |
524af0d6 JB |
2529 | if (!type_check (status, 2, BT_INTEGER)) |
2530 | return false; | |
f77b6ca3 | 2531 | |
524af0d6 JB |
2532 | if (!scalar_check (status, 2)) |
2533 | return false; | |
f77b6ca3 | 2534 | |
524af0d6 | 2535 | return true; |
f77b6ca3 FXC |
2536 | } |
2537 | ||
65f8144a | 2538 | |
524af0d6 | 2539 | bool |
83d890b9 AL |
2540 | gfc_check_loc (gfc_expr *expr) |
2541 | { | |
11746b92 | 2542 | return variable_check (expr, 0, true); |
83d890b9 AL |
2543 | } |
2544 | ||
f77b6ca3 | 2545 | |
524af0d6 | 2546 | bool |
65f8144a | 2547 | gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2) |
f77b6ca3 | 2548 | { |
524af0d6 JB |
2549 | if (!type_check (path1, 0, BT_CHARACTER)) |
2550 | return false; | |
2551 | if (!kind_value_check (path1, 0, gfc_default_character_kind)) | |
2552 | return false; | |
f77b6ca3 | 2553 | |
524af0d6 JB |
2554 | if (!type_check (path2, 1, BT_CHARACTER)) |
2555 | return false; | |
2556 | if (!kind_value_check (path2, 1, gfc_default_character_kind)) | |
2557 | return false; | |
f77b6ca3 | 2558 | |
524af0d6 | 2559 | return true; |
f77b6ca3 FXC |
2560 | } |
2561 | ||
2562 | ||
524af0d6 | 2563 | bool |
65f8144a | 2564 | gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status) |
f77b6ca3 | 2565 | { |
524af0d6 JB |
2566 | if (!type_check (path1, 0, BT_CHARACTER)) |
2567 | return false; | |
2568 | if (!kind_value_check (path1, 0, gfc_default_character_kind)) | |
2569 | return false; | |
f77b6ca3 | 2570 | |
524af0d6 JB |
2571 | if (!type_check (path2, 1, BT_CHARACTER)) |
2572 | return false; | |
2573 | if (!kind_value_check (path2, 1, gfc_default_character_kind)) | |
2574 | return false; | |
f77b6ca3 FXC |
2575 | |
2576 | if (status == NULL) | |
524af0d6 | 2577 | return true; |
f77b6ca3 | 2578 | |
524af0d6 JB |
2579 | if (!type_check (status, 2, BT_INTEGER)) |
2580 | return false; | |
f77b6ca3 | 2581 | |
524af0d6 JB |
2582 | if (!scalar_check (status, 2)) |
2583 | return false; | |
f77b6ca3 | 2584 | |
524af0d6 | 2585 | return true; |
f77b6ca3 FXC |
2586 | } |
2587 | ||
2588 | ||
524af0d6 | 2589 | bool |
65f8144a | 2590 | gfc_check_logical (gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 2591 | { |
524af0d6 JB |
2592 | if (!type_check (a, 0, BT_LOGICAL)) |
2593 | return false; | |
2594 | if (!kind_check (kind, 1, BT_LOGICAL)) | |
2595 | return false; | |
6de9cd9a | 2596 | |
524af0d6 | 2597 | return true; |
6de9cd9a DN |
2598 | } |
2599 | ||
2600 | ||
2601 | /* Min/max family. */ | |
2602 | ||
524af0d6 | 2603 | static bool |
3b833dcd | 2604 | min_max_args (gfc_actual_arglist *args) |
6de9cd9a | 2605 | { |
3b833dcd TB |
2606 | gfc_actual_arglist *arg; |
2607 | int i, j, nargs, *nlabels, nlabelless; | |
2608 | bool a1 = false, a2 = false; | |
2609 | ||
2610 | if (args == NULL || args->next == NULL) | |
6de9cd9a DN |
2611 | { |
2612 | gfc_error ("Intrinsic '%s' at %L must have at least two arguments", | |
2613 | gfc_current_intrinsic, gfc_current_intrinsic_where); | |
524af0d6 | 2614 | return false; |
6de9cd9a DN |
2615 | } |
2616 | ||
3b833dcd TB |
2617 | if (!args->name) |
2618 | a1 = true; | |
2619 | ||
2620 | if (!args->next->name) | |
2621 | a2 = true; | |
2622 | ||
2623 | nargs = 0; | |
2624 | for (arg = args; arg; arg = arg->next) | |
2625 | if (arg->name) | |
2626 | nargs++; | |
2627 | ||
2628 | if (nargs == 0) | |
2629 | return true; | |
2630 | ||
2631 | /* Note: Having a keywordless argument after an "arg=" is checked before. */ | |
2632 | nlabelless = 0; | |
2633 | nlabels = XALLOCAVEC (int, nargs); | |
2634 | for (arg = args, i = 0; arg; arg = arg->next, i++) | |
2635 | if (arg->name) | |
2636 | { | |
2637 | int n; | |
2638 | char *endp; | |
2639 | ||
2640 | if (arg->name[0] != 'a' || arg->name[1] < '1' || arg->name[1] > '9') | |
2641 | goto unknown; | |
2642 | n = strtol (&arg->name[1], &endp, 10); | |
2643 | if (endp[0] != '\0') | |
2644 | goto unknown; | |
2645 | if (n <= 0) | |
2646 | goto unknown; | |
2647 | if (n <= nlabelless) | |
2648 | goto duplicate; | |
2649 | nlabels[i] = n; | |
2650 | if (n == 1) | |
2651 | a1 = true; | |
2652 | if (n == 2) | |
2653 | a2 = true; | |
2654 | } | |
2655 | else | |
2656 | nlabelless++; | |
2657 | ||
2658 | if (!a1 || !a2) | |
2659 | { | |
2660 | gfc_error ("Missing '%s' argument to the %s intrinsic at %L", | |
2661 | !a1 ? "a1" : "a2", gfc_current_intrinsic, | |
2662 | gfc_current_intrinsic_where); | |
2663 | return false; | |
2664 | } | |
2665 | ||
2666 | /* Check for duplicates. */ | |
2667 | for (i = 0; i < nargs; i++) | |
2668 | for (j = i + 1; j < nargs; j++) | |
2669 | if (nlabels[i] == nlabels[j]) | |
2670 | goto duplicate; | |
2671 | ||
524af0d6 | 2672 | return true; |
3b833dcd TB |
2673 | |
2674 | duplicate: | |
2675 | gfc_error ("Duplicate argument '%s' at %L to intrinsic %s", arg->name, | |
2676 | &arg->expr->where, gfc_current_intrinsic); | |
2677 | return false; | |
2678 | ||
2679 | unknown: | |
2680 | gfc_error ("Unknown argument '%s' at %L to intrinsic %s", arg->name, | |
2681 | &arg->expr->where, gfc_current_intrinsic); | |
2682 | return false; | |
6de9cd9a DN |
2683 | } |
2684 | ||
2685 | ||
524af0d6 | 2686 | static bool |
6495bc0b | 2687 | check_rest (bt type, int kind, gfc_actual_arglist *arglist) |
6de9cd9a | 2688 | { |
6495bc0b | 2689 | gfc_actual_arglist *arg, *tmp; |
6495bc0b DF |
2690 | gfc_expr *x; |
2691 | int m, n; | |
6de9cd9a | 2692 | |
524af0d6 JB |
2693 | if (!min_max_args (arglist)) |
2694 | return false; | |
6de9cd9a | 2695 | |
6495bc0b | 2696 | for (arg = arglist, n=1; arg; arg = arg->next, n++) |
6de9cd9a DN |
2697 | { |
2698 | x = arg->expr; | |
2699 | if (x->ts.type != type || x->ts.kind != kind) | |
2700 | { | |
65f8144a SK |
2701 | if (x->ts.type == type) |
2702 | { | |
524af0d6 JB |
2703 | if (!gfc_notify_std (GFC_STD_GNU, "Different type " |
2704 | "kinds at %L", &x->where)) | |
2705 | return false; | |
65f8144a SK |
2706 | } |
2707 | else | |
2708 | { | |
2709 | gfc_error ("'a%d' argument of '%s' intrinsic at %L must be " | |
2710 | "%s(%d)", n, gfc_current_intrinsic, &x->where, | |
2711 | gfc_basic_typename (type), kind); | |
524af0d6 | 2712 | return false; |
65f8144a | 2713 | } |
6de9cd9a | 2714 | } |
0881653c | 2715 | |
6495bc0b | 2716 | for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++) |
524af0d6 JB |
2717 | if (!gfc_check_conformance (tmp->expr, x, |
2718 | "arguments 'a%d' and 'a%d' for " | |
2719 | "intrinsic '%s'", m, n, | |
2720 | gfc_current_intrinsic)) | |
2721 | return false; | |
6de9cd9a DN |
2722 | } |
2723 | ||
524af0d6 | 2724 | return true; |
6de9cd9a DN |
2725 | } |
2726 | ||
2727 | ||
524af0d6 | 2728 | bool |
65f8144a | 2729 | gfc_check_min_max (gfc_actual_arglist *arg) |
6de9cd9a DN |
2730 | { |
2731 | gfc_expr *x; | |
2732 | ||
524af0d6 JB |
2733 | if (!min_max_args (arg)) |
2734 | return false; | |
6de9cd9a DN |
2735 | |
2736 | x = arg->expr; | |
2737 | ||
2263c775 FXC |
2738 | if (x->ts.type == BT_CHARACTER) |
2739 | { | |
524af0d6 JB |
2740 | if (!gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " |
2741 | "with CHARACTER argument at %L", | |
2742 | gfc_current_intrinsic, &x->where)) | |
2743 | return false; | |
2263c775 FXC |
2744 | } |
2745 | else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL) | |
6de9cd9a | 2746 | { |
2263c775 FXC |
2747 | gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, " |
2748 | "REAL or CHARACTER", gfc_current_intrinsic, &x->where); | |
524af0d6 | 2749 | return false; |
6de9cd9a DN |
2750 | } |
2751 | ||
2752 | return check_rest (x->ts.type, x->ts.kind, arg); | |
2753 | } | |
2754 | ||
2755 | ||
524af0d6 | 2756 | bool |
65f8144a | 2757 | gfc_check_min_max_integer (gfc_actual_arglist *arg) |
6de9cd9a | 2758 | { |
9d64df18 | 2759 | return check_rest (BT_INTEGER, gfc_default_integer_kind, arg); |
6de9cd9a DN |
2760 | } |
2761 | ||
2762 | ||
524af0d6 | 2763 | bool |
65f8144a | 2764 | gfc_check_min_max_real (gfc_actual_arglist *arg) |
6de9cd9a | 2765 | { |
9d64df18 | 2766 | return check_rest (BT_REAL, gfc_default_real_kind, arg); |
6de9cd9a DN |
2767 | } |
2768 | ||
2769 | ||
524af0d6 | 2770 | bool |
65f8144a | 2771 | gfc_check_min_max_double (gfc_actual_arglist *arg) |
6de9cd9a | 2772 | { |
9d64df18 | 2773 | return check_rest (BT_REAL, gfc_default_double_kind, arg); |
6de9cd9a DN |
2774 | } |
2775 | ||
65f8144a | 2776 | |
6de9cd9a DN |
2777 | /* End of min/max family. */ |
2778 | ||
524af0d6 | 2779 | bool |
65f8144a | 2780 | gfc_check_malloc (gfc_expr *size) |
0d519038 | 2781 | { |
524af0d6 JB |
2782 | if (!type_check (size, 0, BT_INTEGER)) |
2783 | return false; | |
0d519038 | 2784 | |
524af0d6 JB |
2785 | if (!scalar_check (size, 0)) |
2786 | return false; | |
0d519038 | 2787 | |
524af0d6 | 2788 | return true; |
0d519038 FXC |
2789 | } |
2790 | ||
6de9cd9a | 2791 | |
524af0d6 | 2792 | bool |
65f8144a | 2793 | gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b) |
6de9cd9a | 2794 | { |
bf4f96e6 | 2795 | if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts)) |
6de9cd9a | 2796 | { |
4c93c95a | 2797 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric " |
c4aa95f8 | 2798 | "or LOGICAL", gfc_current_intrinsic_arg[0]->name, |
4c93c95a | 2799 | gfc_current_intrinsic, &matrix_a->where); |
524af0d6 | 2800 | return false; |
6de9cd9a DN |
2801 | } |
2802 | ||
bf4f96e6 | 2803 | if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts)) |
6de9cd9a | 2804 | { |
4c93c95a | 2805 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric " |
c4aa95f8 | 2806 | "or LOGICAL", gfc_current_intrinsic_arg[1]->name, |
4c93c95a | 2807 | gfc_current_intrinsic, &matrix_b->where); |
524af0d6 | 2808 | return false; |
6de9cd9a DN |
2809 | } |
2810 | ||
bf4f96e6 DF |
2811 | if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts)) |
2812 | || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL)) | |
2813 | { | |
2814 | gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)", | |
2815 | gfc_current_intrinsic, &matrix_a->where, | |
2816 | gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts)); | |
524af0d6 | 2817 | return false; |
bf4f96e6 DF |
2818 | } |
2819 | ||
6de9cd9a DN |
2820 | switch (matrix_a->rank) |
2821 | { | |
2822 | case 1: | |
524af0d6 JB |
2823 | if (!rank_check (matrix_b, 1, 2)) |
2824 | return false; | |
a8999235 | 2825 | /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */ |
65f8144a | 2826 | if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0)) |
a8999235 | 2827 | { |
7e49f965 | 2828 | gfc_error ("Different shape on dimension 1 for arguments '%s' " |
a8999235 | 2829 | "and '%s' at %L for intrinsic matmul", |
c4aa95f8 JW |
2830 | gfc_current_intrinsic_arg[0]->name, |
2831 | gfc_current_intrinsic_arg[1]->name, &matrix_a->where); | |
524af0d6 | 2832 | return false; |
a8999235 | 2833 | } |
6de9cd9a DN |
2834 | break; |
2835 | ||
2836 | case 2: | |
a8999235 TK |
2837 | if (matrix_b->rank != 2) |
2838 | { | |
524af0d6 JB |
2839 | if (!rank_check (matrix_b, 1, 1)) |
2840 | return false; | |
a8999235 TK |
2841 | } |
2842 | /* matrix_b has rank 1 or 2 here. Common check for the cases | |
2843 | - matrix_a has shape (n,m) and matrix_b has shape (m, k) | |
2844 | - matrix_a has shape (n,m) and matrix_b has shape (m). */ | |
65f8144a | 2845 | if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0)) |
a8999235 | 2846 | { |
7e49f965 | 2847 | gfc_error ("Different shape on dimension 2 for argument '%s' and " |
a8999235 | 2848 | "dimension 1 for argument '%s' at %L for intrinsic " |
c4aa95f8 JW |
2849 | "matmul", gfc_current_intrinsic_arg[0]->name, |
2850 | gfc_current_intrinsic_arg[1]->name, &matrix_a->where); | |
524af0d6 | 2851 | return false; |
a8999235 | 2852 | } |
6de9cd9a DN |
2853 | break; |
2854 | ||
2855 | default: | |
4c93c95a | 2856 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank " |
c4aa95f8 | 2857 | "1 or 2", gfc_current_intrinsic_arg[0]->name, |
4c93c95a | 2858 | gfc_current_intrinsic, &matrix_a->where); |
524af0d6 | 2859 | return false; |
6de9cd9a DN |
2860 | } |
2861 | ||
524af0d6 | 2862 | return true; |
6de9cd9a DN |
2863 | } |
2864 | ||
2865 | ||
2866 | /* Whoever came up with this interface was probably on something. | |
2867 | The possibilities for the occupation of the second and third | |
2868 | parameters are: | |
2869 | ||
65f8144a SK |
2870 | Arg #2 Arg #3 |
2871 | NULL NULL | |
2872 | DIM NULL | |
2873 | MASK NULL | |
2874 | NULL MASK minloc(array, mask=m) | |
2875 | DIM MASK | |
f3207b37 TS |
2876 | |
2877 | I.e. in the case of minloc(array,mask), mask will be in the second | |
2878 | position of the argument list and we'll have to fix that up. */ | |
6de9cd9a | 2879 | |
524af0d6 | 2880 | bool |
65f8144a | 2881 | gfc_check_minloc_maxloc (gfc_actual_arglist *ap) |
6de9cd9a | 2882 | { |
f3207b37 | 2883 | gfc_expr *a, *m, *d; |
6de9cd9a | 2884 | |
f3207b37 | 2885 | a = ap->expr; |
524af0d6 JB |
2886 | if (!int_or_real_check (a, 0) || !array_check (a, 0)) |
2887 | return false; | |
6de9cd9a | 2888 | |
f3207b37 TS |
2889 | d = ap->next->expr; |
2890 | m = ap->next->next->expr; | |
6de9cd9a | 2891 | |
f3207b37 | 2892 | if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL |
cb9e4f55 | 2893 | && ap->next->name == NULL) |
6de9cd9a | 2894 | { |
f3207b37 TS |
2895 | m = d; |
2896 | d = NULL; | |
f3207b37 TS |
2897 | ap->next->expr = NULL; |
2898 | ap->next->next->expr = m; | |
6de9cd9a | 2899 | } |
6de9cd9a | 2900 | |
524af0d6 JB |
2901 | if (!dim_check (d, 1, false)) |
2902 | return false; | |
ce99d594 | 2903 | |
524af0d6 JB |
2904 | if (!dim_rank_check (d, a, 0)) |
2905 | return false; | |
6de9cd9a | 2906 | |
524af0d6 JB |
2907 | if (m != NULL && !type_check (m, 2, BT_LOGICAL)) |
2908 | return false; | |
6de9cd9a | 2909 | |
ca8a8795 | 2910 | if (m != NULL |
524af0d6 JB |
2911 | && !gfc_check_conformance (a, m, |
2912 | "arguments '%s' and '%s' for intrinsic %s", | |
2913 | gfc_current_intrinsic_arg[0]->name, | |
2914 | gfc_current_intrinsic_arg[2]->name, | |
2915 | gfc_current_intrinsic)) | |
2916 | return false; | |
17d761bb | 2917 | |
524af0d6 | 2918 | return true; |
6de9cd9a DN |
2919 | } |
2920 | ||
2921 | ||
7551270e ES |
2922 | /* Similar to minloc/maxloc, the argument list might need to be |
2923 | reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The | |
2924 | difference is that MINLOC/MAXLOC take an additional KIND argument. | |
2925 | The possibilities are: | |
2926 | ||
65f8144a SK |
2927 | Arg #2 Arg #3 |
2928 | NULL NULL | |
2929 | DIM NULL | |
2930 | MASK NULL | |
2931 | NULL MASK minval(array, mask=m) | |
2932 | DIM MASK | |
7551270e ES |
2933 | |
2934 | I.e. in the case of minval(array,mask), mask will be in the second | |
2935 | position of the argument list and we'll have to fix that up. */ | |
2936 | ||
524af0d6 | 2937 | static bool |
65f8144a | 2938 | check_reduction (gfc_actual_arglist *ap) |
6de9cd9a | 2939 | { |
17d761bb | 2940 | gfc_expr *a, *m, *d; |
6de9cd9a | 2941 | |
17d761bb | 2942 | a = ap->expr; |
7551270e ES |
2943 | d = ap->next->expr; |
2944 | m = ap->next->next->expr; | |
6de9cd9a | 2945 | |
7551270e | 2946 | if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL |
cb9e4f55 | 2947 | && ap->next->name == NULL) |
7551270e ES |
2948 | { |
2949 | m = d; | |
2950 | d = NULL; | |
7551270e ES |
2951 | ap->next->expr = NULL; |
2952 | ap->next->next->expr = m; | |
2953 | } | |
2954 | ||
524af0d6 JB |
2955 | if (!dim_check (d, 1, false)) |
2956 | return false; | |
ce99d594 | 2957 | |
524af0d6 JB |
2958 | if (!dim_rank_check (d, a, 0)) |
2959 | return false; | |
6de9cd9a | 2960 | |
524af0d6 JB |
2961 | if (m != NULL && !type_check (m, 2, BT_LOGICAL)) |
2962 | return false; | |
6de9cd9a | 2963 | |
ca8a8795 | 2964 | if (m != NULL |
524af0d6 JB |
2965 | && !gfc_check_conformance (a, m, |
2966 | "arguments '%s' and '%s' for intrinsic %s", | |
2967 | gfc_current_intrinsic_arg[0]->name, | |
2968 | gfc_current_intrinsic_arg[2]->name, | |
2969 | gfc_current_intrinsic)) | |
2970 | return false; | |
17d761bb | 2971 | |
524af0d6 | 2972 | return true; |
6de9cd9a DN |
2973 | } |
2974 | ||
2975 | ||
524af0d6 | 2976 | bool |
65f8144a | 2977 | gfc_check_minval_maxval (gfc_actual_arglist *ap) |
617097a3 | 2978 | { |
524af0d6 JB |
2979 | if (!int_or_real_check (ap->expr, 0) |
2980 | || !array_check (ap->expr, 0)) | |
2981 | return false; | |
27dfc9c4 | 2982 | |
617097a3 TS |
2983 | return check_reduction (ap); |
2984 | } | |
2985 | ||
2986 | ||
524af0d6 | 2987 | bool |
65f8144a | 2988 | gfc_check_product_sum (gfc_actual_arglist *ap) |
617097a3 | 2989 | { |
524af0d6 JB |
2990 | if (!numeric_check (ap->expr, 0) |
2991 | || !array_check (ap->expr, 0)) | |
2992 | return false; | |
27dfc9c4 | 2993 | |
617097a3 TS |
2994 | return check_reduction (ap); |
2995 | } | |
2996 | ||
2997 | ||
195a95c4 TB |
2998 | /* For IANY, IALL and IPARITY. */ |
2999 | ||
524af0d6 | 3000 | bool |
88a95a11 FXC |
3001 | gfc_check_mask (gfc_expr *i, gfc_expr *kind) |
3002 | { | |
3003 | int k; | |
3004 | ||
524af0d6 JB |
3005 | if (!type_check (i, 0, BT_INTEGER)) |
3006 | return false; | |
88a95a11 | 3007 | |
524af0d6 JB |
3008 | if (!nonnegative_check ("I", i)) |
3009 | return false; | |
88a95a11 | 3010 | |
524af0d6 JB |
3011 | if (!kind_check (kind, 1, BT_INTEGER)) |
3012 | return false; | |
88a95a11 FXC |
3013 | |
3014 | if (kind) | |
3015 | gfc_extract_int (kind, &k); | |
3016 | else | |
3017 | k = gfc_default_integer_kind; | |
3018 | ||
524af0d6 JB |
3019 | if (!less_than_bitsizekind ("I", i, k)) |
3020 | return false; | |
88a95a11 | 3021 | |
524af0d6 | 3022 | return true; |
88a95a11 FXC |
3023 | } |
3024 | ||
3025 | ||
524af0d6 | 3026 | bool |
195a95c4 TB |
3027 | gfc_check_transf_bit_intrins (gfc_actual_arglist *ap) |
3028 | { | |
3029 | if (ap->expr->ts.type != BT_INTEGER) | |
3030 | { | |
3031 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER", | |
3032 | gfc_current_intrinsic_arg[0]->name, | |
3033 | gfc_current_intrinsic, &ap->expr->where); | |
524af0d6 | 3034 | return false; |
195a95c4 TB |
3035 | } |
3036 | ||
524af0d6 JB |
3037 | if (!array_check (ap->expr, 0)) |
3038 | return false; | |
195a95c4 TB |
3039 | |
3040 | return check_reduction (ap); | |
3041 | } | |
3042 | ||
3043 | ||
524af0d6 | 3044 | bool |
65f8144a | 3045 | gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask) |
6de9cd9a | 3046 | { |
524af0d6 JB |
3047 | if (!same_type_check (tsource, 0, fsource, 1)) |
3048 | return false; | |
6de9cd9a | 3049 | |
524af0d6 JB |
3050 | if (!type_check (mask, 2, BT_LOGICAL)) |
3051 | return false; | |
6de9cd9a | 3052 | |
90d31126 | 3053 | if (tsource->ts.type == BT_CHARACTER) |
fb5bc08b | 3054 | return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic"); |
90d31126 | 3055 | |
524af0d6 | 3056 | return true; |
6de9cd9a DN |
3057 | } |
3058 | ||
90d31126 | 3059 | |
524af0d6 | 3060 | bool |
88a95a11 FXC |
3061 | gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask) |
3062 | { | |
524af0d6 JB |
3063 | if (!type_check (i, 0, BT_INTEGER)) |
3064 | return false; | |
88a95a11 | 3065 | |
524af0d6 JB |
3066 | if (!type_check (j, 1, BT_INTEGER)) |
3067 | return false; | |
88a95a11 | 3068 | |
524af0d6 JB |
3069 | if (!type_check (mask, 2, BT_INTEGER)) |
3070 | return false; | |
88a95a11 | 3071 | |
524af0d6 JB |
3072 | if (!same_type_check (i, 0, j, 1)) |
3073 | return false; | |
88a95a11 | 3074 | |
524af0d6 JB |
3075 | if (!same_type_check (i, 0, mask, 2)) |
3076 | return false; | |
88a95a11 | 3077 | |
524af0d6 | 3078 | return true; |
88a95a11 FXC |
3079 | } |
3080 | ||
3081 | ||
524af0d6 | 3082 | bool |
65f8144a | 3083 | gfc_check_move_alloc (gfc_expr *from, gfc_expr *to) |
5046aff5 | 3084 | { |
524af0d6 JB |
3085 | if (!variable_check (from, 0, false)) |
3086 | return false; | |
3087 | if (!allocatable_check (from, 0)) | |
3088 | return false; | |
284943b0 TB |
3089 | if (gfc_is_coindexed (from)) |
3090 | { | |
3091 | gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be " | |
3092 | "coindexed", &from->where); | |
524af0d6 | 3093 | return false; |
284943b0 | 3094 | } |
5046aff5 | 3095 | |
524af0d6 JB |
3096 | if (!variable_check (to, 1, false)) |
3097 | return false; | |
3098 | if (!allocatable_check (to, 1)) | |
3099 | return false; | |
284943b0 TB |
3100 | if (gfc_is_coindexed (to)) |
3101 | { | |
3102 | gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be " | |
3103 | "coindexed", &to->where); | |
524af0d6 | 3104 | return false; |
284943b0 | 3105 | } |
5046aff5 | 3106 | |
fde50fe6 | 3107 | if (from->ts.type == BT_CLASS && to->ts.type == BT_DERIVED) |
e0516b05 | 3108 | { |
fde50fe6 TB |
3109 | gfc_error ("The TO arguments in MOVE_ALLOC at %L must be " |
3110 | "polymorphic if FROM is polymorphic", | |
284943b0 | 3111 | &to->where); |
524af0d6 | 3112 | return false; |
e0516b05 TB |
3113 | } |
3114 | ||
524af0d6 JB |
3115 | if (!same_type_check (to, 1, from, 0)) |
3116 | return false; | |
fde50fe6 | 3117 | |
5046aff5 PT |
3118 | if (to->rank != from->rank) |
3119 | { | |
284943b0 TB |
3120 | gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L " |
3121 | "must have the same rank %d/%d", &to->where, from->rank, | |
3122 | to->rank); | |
524af0d6 | 3123 | return false; |
284943b0 TB |
3124 | } |
3125 | ||
3126 | /* IR F08/0040; cf. 12-006A. */ | |
3127 | if (gfc_get_corank (to) != gfc_get_corank (from)) | |
3128 | { | |
3129 | gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L " | |
3130 | "must have the same corank %d/%d", &to->where, | |
3131 | gfc_get_corank (from), gfc_get_corank (to)); | |
524af0d6 | 3132 | return false; |
5046aff5 PT |
3133 | } |
3134 | ||
f968d60b TB |
3135 | /* CLASS arguments: Make sure the vtab of from is present. */ |
3136 | if (to->ts.type == BT_CLASS && !UNLIMITED_POLY (from)) | |
7289d1c9 | 3137 | gfc_find_vtab (&from->ts); |
5046aff5 | 3138 | |
524af0d6 | 3139 | return true; |
5046aff5 | 3140 | } |
6de9cd9a | 3141 | |
65f8144a | 3142 | |
524af0d6 | 3143 | bool |
65f8144a | 3144 | gfc_check_nearest (gfc_expr *x, gfc_expr *s) |
6de9cd9a | 3145 | { |
524af0d6 JB |
3146 | if (!type_check (x, 0, BT_REAL)) |
3147 | return false; | |
6de9cd9a | 3148 | |
524af0d6 JB |
3149 | if (!type_check (s, 1, BT_REAL)) |
3150 | return false; | |
6de9cd9a | 3151 | |
58a9e3c4 SK |
3152 | if (s->expr_type == EXPR_CONSTANT) |
3153 | { | |
3154 | if (mpfr_sgn (s->value.real) == 0) | |
3155 | { | |
3156 | gfc_error ("Argument 'S' of NEAREST at %L shall not be zero", | |
3157 | &s->where); | |
524af0d6 | 3158 | return false; |
58a9e3c4 SK |
3159 | } |
3160 | } | |
3161 | ||
524af0d6 | 3162 | return true; |
6de9cd9a DN |
3163 | } |
3164 | ||
65f8144a | 3165 | |
524af0d6 | 3166 | bool |
65f8144a | 3167 | gfc_check_new_line (gfc_expr *a) |
bec93d79 | 3168 | { |
524af0d6 JB |
3169 | if (!type_check (a, 0, BT_CHARACTER)) |
3170 | return false; | |
bec93d79 | 3171 | |
524af0d6 | 3172 | return true; |
bec93d79 | 3173 | } |
6de9cd9a | 3174 | |
65f8144a | 3175 | |
524af0d6 | 3176 | bool |
0cd0559e TB |
3177 | gfc_check_norm2 (gfc_expr *array, gfc_expr *dim) |
3178 | { | |
524af0d6 JB |
3179 | if (!type_check (array, 0, BT_REAL)) |
3180 | return false; | |
0cd0559e | 3181 | |
524af0d6 JB |
3182 | if (!array_check (array, 0)) |
3183 | return false; | |
0cd0559e | 3184 | |
524af0d6 JB |
3185 | if (!dim_rank_check (dim, array, false)) |
3186 | return false; | |
0cd0559e | 3187 | |
524af0d6 | 3188 | return true; |
0cd0559e TB |
3189 | } |
3190 | ||
524af0d6 | 3191 | bool |
65f8144a | 3192 | gfc_check_null (gfc_expr *mold) |
6de9cd9a DN |
3193 | { |
3194 | symbol_attribute attr; | |
3195 | ||
3196 | if (mold == NULL) | |
524af0d6 | 3197 | return true; |
6de9cd9a | 3198 | |
524af0d6 JB |
3199 | if (!variable_check (mold, 0, true)) |
3200 | return false; | |
6de9cd9a DN |
3201 | |
3202 | attr = gfc_variable_attr (mold, NULL); | |
3203 | ||
ea8ad3e5 | 3204 | if (!attr.pointer && !attr.proc_pointer && !attr.allocatable) |
6de9cd9a | 3205 | { |
ea8ad3e5 TB |
3206 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER, " |
3207 | "ALLOCATABLE or procedure pointer", | |
c4aa95f8 | 3208 | gfc_current_intrinsic_arg[0]->name, |
5aacb11e | 3209 | gfc_current_intrinsic, &mold->where); |
524af0d6 | 3210 | return false; |
5aacb11e TB |
3211 | } |
3212 | ||
ea8ad3e5 | 3213 | if (attr.allocatable |
524af0d6 JB |
3214 | && !gfc_notify_std (GFC_STD_F2003, "NULL intrinsic with " |
3215 | "allocatable MOLD at %L", &mold->where)) | |
3216 | return false; | |
ea8ad3e5 | 3217 | |
5aacb11e TB |
3218 | /* F2008, C1242. */ |
3219 | if (gfc_is_coindexed (mold)) | |
3220 | { | |
3221 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be " | |
0c133211 | 3222 | "coindexed", gfc_current_intrinsic_arg[0]->name, |
4c93c95a | 3223 | gfc_current_intrinsic, &mold->where); |
524af0d6 | 3224 | return false; |
6de9cd9a DN |
3225 | } |
3226 | ||
524af0d6 | 3227 | return true; |
6de9cd9a DN |
3228 | } |
3229 | ||
3230 | ||
524af0d6 | 3231 | bool |
65f8144a | 3232 | gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector) |
6de9cd9a | 3233 | { |
524af0d6 JB |
3234 | if (!array_check (array, 0)) |
3235 | return false; | |
6de9cd9a | 3236 | |
524af0d6 JB |
3237 | if (!type_check (mask, 1, BT_LOGICAL)) |
3238 | return false; | |
6de9cd9a | 3239 | |
524af0d6 JB |
3240 | if (!gfc_check_conformance (array, mask, |
3241 | "arguments '%s' and '%s' for intrinsic '%s'", | |
3242 | gfc_current_intrinsic_arg[0]->name, | |
3243 | gfc_current_intrinsic_arg[1]->name, | |
3244 | gfc_current_intrinsic)) | |
3245 | return false; | |
6de9cd9a DN |
3246 | |
3247 | if (vector != NULL) | |
3248 | { | |
7ba8c18c DF |
3249 | mpz_t array_size, vector_size; |
3250 | bool have_array_size, have_vector_size; | |
3251 | ||
524af0d6 JB |
3252 | if (!same_type_check (array, 0, vector, 2)) |
3253 | return false; | |
6de9cd9a | 3254 | |
524af0d6 JB |
3255 | if (!rank_check (vector, 2, 1)) |
3256 | return false; | |
6de9cd9a | 3257 | |
7ba8c18c DF |
3258 | /* VECTOR requires at least as many elements as MASK |
3259 | has .TRUE. values. */ | |
524af0d6 JB |
3260 | have_array_size = gfc_array_size(array, &array_size); |
3261 | have_vector_size = gfc_array_size(vector, &vector_size); | |
7ba8c18c DF |
3262 | |
3263 | if (have_vector_size | |
3264 | && (mask->expr_type == EXPR_ARRAY | |
3265 | || (mask->expr_type == EXPR_CONSTANT | |
3266 | && have_array_size))) | |
3267 | { | |
3268 | int mask_true_values = 0; | |
3269 | ||
3270 | if (mask->expr_type == EXPR_ARRAY) | |
3271 | { | |
b7e75771 JD |
3272 | gfc_constructor *mask_ctor; |
3273 | mask_ctor = gfc_constructor_first (mask->value.constructor); | |
7ba8c18c DF |
3274 | while (mask_ctor) |
3275 | { | |
3276 | if (mask_ctor->expr->expr_type != EXPR_CONSTANT) | |
3277 | { | |
3278 | mask_true_values = 0; | |
3279 | break; | |
3280 | } | |
3281 | ||
3282 | if (mask_ctor->expr->value.logical) | |
3283 | mask_true_values++; | |
3284 | ||
b7e75771 | 3285 | mask_ctor = gfc_constructor_next (mask_ctor); |
7ba8c18c DF |
3286 | } |
3287 | } | |
3288 | else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical) | |
3289 | mask_true_values = mpz_get_si (array_size); | |
3290 | ||
3291 | if (mpz_get_si (vector_size) < mask_true_values) | |
3292 | { | |
3293 | gfc_error ("'%s' argument of '%s' intrinsic at %L must " | |
3294 | "provide at least as many elements as there " | |
3295 | "are .TRUE. values in '%s' (%ld/%d)", | |
c4aa95f8 JW |
3296 | gfc_current_intrinsic_arg[2]->name, |
3297 | gfc_current_intrinsic, &vector->where, | |
3298 | gfc_current_intrinsic_arg[1]->name, | |
7ba8c18c | 3299 | mpz_get_si (vector_size), mask_true_values); |
524af0d6 | 3300 | return false; |
7ba8c18c DF |
3301 | } |
3302 | } | |
3303 | ||
3304 | if (have_array_size) | |
3305 | mpz_clear (array_size); | |
3306 | if (have_vector_size) | |
3307 | mpz_clear (vector_size); | |
6de9cd9a DN |
3308 | } |
3309 | ||
524af0d6 | 3310 | return true; |
6de9cd9a DN |
3311 | } |
3312 | ||
3313 | ||
524af0d6 | 3314 | bool |
0cd0559e TB |
3315 | gfc_check_parity (gfc_expr *mask, gfc_expr *dim) |
3316 | { | |
524af0d6 JB |
3317 | if (!type_check (mask, 0, BT_LOGICAL)) |
3318 | return false; | |
0cd0559e | 3319 | |
524af0d6 JB |
3320 | if (!array_check (mask, 0)) |
3321 | return false; | |
0cd0559e | 3322 | |
524af0d6 JB |
3323 | if (!dim_rank_check (dim, mask, false)) |
3324 | return false; | |
0cd0559e | 3325 | |
524af0d6 | 3326 | return true; |
0cd0559e TB |
3327 | } |
3328 | ||
3329 | ||
524af0d6 | 3330 | bool |
65f8144a | 3331 | gfc_check_precision (gfc_expr *x) |
6de9cd9a | 3332 | { |
524af0d6 JB |
3333 | if (!real_or_complex_check (x, 0)) |
3334 | return false; | |
6de9cd9a | 3335 | |
524af0d6 | 3336 | return true; |
6de9cd9a DN |
3337 | } |
3338 | ||
3339 | ||
524af0d6 | 3340 | bool |
65f8144a | 3341 | gfc_check_present (gfc_expr *a) |
6de9cd9a DN |
3342 | { |
3343 | gfc_symbol *sym; | |
3344 | ||
524af0d6 JB |
3345 | if (!variable_check (a, 0, true)) |
3346 | return false; | |
6de9cd9a DN |
3347 | |
3348 | sym = a->symtree->n.sym; | |
3349 | if (!sym->attr.dummy) | |
3350 | { | |
4c93c95a | 3351 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a " |
c4aa95f8 | 3352 | "dummy variable", gfc_current_intrinsic_arg[0]->name, |
4c93c95a | 3353 | gfc_current_intrinsic, &a->where); |
524af0d6 | 3354 | return false; |
6de9cd9a DN |
3355 | } |
3356 | ||
3357 | if (!sym->attr.optional) | |
3358 | { | |
4c93c95a | 3359 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be of " |
c4aa95f8 JW |
3360 | "an OPTIONAL dummy variable", |
3361 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, | |
3362 | &a->where); | |
524af0d6 | 3363 | return false; |
6de9cd9a DN |
3364 | } |
3365 | ||
65f8144a SK |
3366 | /* 13.14.82 PRESENT(A) |
3367 | ...... | |
3368 | Argument. A shall be the name of an optional dummy argument that is | |
3369 | accessible in the subprogram in which the PRESENT function reference | |
3370 | appears... */ | |
72af9f0b PT |
3371 | |
3372 | if (a->ref != NULL | |
65f8144a | 3373 | && !(a->ref->next == NULL && a->ref->type == REF_ARRAY |
0c53708e TB |
3374 | && (a->ref->u.ar.type == AR_FULL |
3375 | || (a->ref->u.ar.type == AR_ELEMENT | |
3376 | && a->ref->u.ar.as->rank == 0)))) | |
72af9f0b | 3377 | { |
65f8144a | 3378 | gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a " |
c4aa95f8 | 3379 | "subobject of '%s'", gfc_current_intrinsic_arg[0]->name, |
72af9f0b | 3380 | gfc_current_intrinsic, &a->where, sym->name); |
524af0d6 | 3381 | return false; |
72af9f0b PT |
3382 | } |
3383 | ||
524af0d6 | 3384 | return true; |
6de9cd9a DN |
3385 | } |
3386 | ||
3387 | ||
524af0d6 | 3388 | bool |
65f8144a | 3389 | gfc_check_radix (gfc_expr *x) |
6de9cd9a | 3390 | { |
524af0d6 JB |
3391 | if (!int_or_real_check (x, 0)) |
3392 | return false; | |
6de9cd9a | 3393 | |
524af0d6 | 3394 | return true; |
6de9cd9a DN |
3395 | } |
3396 | ||
3397 | ||
524af0d6 | 3398 | bool |
65f8144a | 3399 | gfc_check_range (gfc_expr *x) |
6de9cd9a | 3400 | { |
524af0d6 JB |
3401 | if (!numeric_check (x, 0)) |
3402 | return false; | |
6de9cd9a | 3403 | |
524af0d6 | 3404 | return true; |
6de9cd9a DN |
3405 | } |
3406 | ||
3407 | ||
524af0d6 | 3408 | bool |
2514987f TB |
3409 | gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED) |
3410 | { | |
3411 | /* Any data object is allowed; a "data object" is a "constant (4.1.3), | |
3412 | variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */ | |
3413 | ||
3414 | bool is_variable = true; | |
3415 | ||
1cc0e193 | 3416 | /* Functions returning pointers are regarded as variable, cf. F2008, R602. */ |
8b704316 | 3417 | if (a->expr_type == EXPR_FUNCTION) |
2514987f TB |
3418 | is_variable = a->value.function.esym |
3419 | ? a->value.function.esym->result->attr.pointer | |
3420 | : a->symtree->n.sym->result->attr.pointer; | |
3421 | ||
3422 | if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL | |
3423 | || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC | |
3424 | || !is_variable) | |
3425 | { | |
3426 | gfc_error ("The argument of the RANK intrinsic at %L must be a data " | |
3427 | "object", &a->where); | |
524af0d6 | 3428 | return false; |
2514987f TB |
3429 | } |
3430 | ||
524af0d6 | 3431 | return true; |
2514987f TB |
3432 | } |
3433 | ||
3434 | ||
6de9cd9a | 3435 | /* real, float, sngl. */ |
524af0d6 | 3436 | bool |
65f8144a | 3437 | gfc_check_real (gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 3438 | { |
524af0d6 JB |
3439 | if (!numeric_check (a, 0)) |
3440 | return false; | |
6de9cd9a | 3441 | |
524af0d6 JB |
3442 | if (!kind_check (kind, 1, BT_REAL)) |
3443 | return false; | |
6de9cd9a | 3444 | |
524af0d6 | 3445 | return true; |
6de9cd9a DN |
3446 | } |
3447 | ||
3448 | ||
524af0d6 | 3449 | bool |
65f8144a | 3450 | gfc_check_rename (gfc_expr *path1, gfc_expr *path2) |
f77b6ca3 | 3451 | { |
524af0d6 JB |
3452 | if (!type_check (path1, 0, BT_CHARACTER)) |
3453 | return false; | |
3454 | if (!kind_value_check (path1, 0, gfc_default_character_kind)) | |
3455 | return false; | |
f77b6ca3 | 3456 | |
524af0d6 JB |
3457 | if (!type_check (path2, 1, BT_CHARACTER)) |
3458 | return false; | |
3459 | if (!kind_value_check (path2, 1, gfc_default_character_kind)) | |
3460 | return false; | |
f77b6ca3 | 3461 | |
524af0d6 | 3462 | return true; |
f77b6ca3 FXC |
3463 | } |
3464 | ||
3465 | ||
524af0d6 | 3466 | bool |
65f8144a | 3467 | gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status) |
f77b6ca3 | 3468 | { |
524af0d6 JB |
3469 | if (!type_check (path1, 0, BT_CHARACTER)) |
3470 | return false; | |
3471 | if (!kind_value_check (path1, 0, gfc_default_character_kind)) | |
3472 | return false; | |
f77b6ca3 | 3473 | |
524af0d6 JB |
3474 | if (!type_check (path2, 1, BT_CHARACTER)) |
3475 | return false; | |
3476 | if (!kind_value_check (path2, 1, gfc_default_character_kind)) | |
3477 | return false; | |
f77b6ca3 FXC |
3478 | |
3479 | if (status == NULL) | |
524af0d6 | 3480 | return true; |
f77b6ca3 | 3481 | |
524af0d6 JB |
3482 | if (!type_check (status, 2, BT_INTEGER)) |
3483 | return false; | |
f77b6ca3 | 3484 | |
524af0d6 JB |
3485 | if (!scalar_check (status, 2)) |
3486 | return false; | |
f77b6ca3 | 3487 | |
524af0d6 | 3488 | return true; |
f77b6ca3 FXC |
3489 | } |
3490 | ||
3491 | ||
524af0d6 | 3492 | bool |
65f8144a | 3493 | gfc_check_repeat (gfc_expr *x, gfc_expr *y) |
6de9cd9a | 3494 | { |
524af0d6 JB |
3495 | if (!type_check (x, 0, BT_CHARACTER)) |
3496 | return false; | |
6de9cd9a | 3497 | |
524af0d6 JB |
3498 | if (!scalar_check (x, 0)) |
3499 | return false; | |
6de9cd9a | 3500 | |
524af0d6 JB |
3501 | if (!type_check (y, 0, BT_INTEGER)) |
3502 | return false; | |
6de9cd9a | 3503 | |
524af0d6 JB |
3504 | if (!scalar_check (y, 1)) |
3505 | return false; | |
6de9cd9a | 3506 | |
524af0d6 | 3507 | return true; |
6de9cd9a DN |
3508 | } |
3509 | ||
3510 | ||
524af0d6 | 3511 | bool |
65f8144a SK |
3512 | gfc_check_reshape (gfc_expr *source, gfc_expr *shape, |
3513 | gfc_expr *pad, gfc_expr *order) | |
6de9cd9a DN |
3514 | { |
3515 | mpz_t size; | |
d8d8121a | 3516 | mpz_t nelems; |
535ff342 | 3517 | int shape_size; |
6de9cd9a | 3518 | |
524af0d6 JB |
3519 | if (!array_check (source, 0)) |
3520 | return false; | |
6de9cd9a | 3521 | |
524af0d6 JB |
3522 | if (!rank_check (shape, 1, 1)) |
3523 | return false; | |
6de9cd9a | 3524 | |
524af0d6 JB |
3525 | if (!type_check (shape, 1, BT_INTEGER)) |
3526 | return false; | |
6de9cd9a | 3527 | |
524af0d6 | 3528 | if (!gfc_array_size (shape, &size)) |
6de9cd9a DN |
3529 | { |
3530 | gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an " | |
3531 | "array of constant size", &shape->where); | |
524af0d6 | 3532 | return false; |
6de9cd9a DN |
3533 | } |
3534 | ||
535ff342 | 3535 | shape_size = mpz_get_ui (size); |
6de9cd9a DN |
3536 | mpz_clear (size); |
3537 | ||
535ff342 DF |
3538 | if (shape_size <= 0) |
3539 | { | |
3540 | gfc_error ("'%s' argument of '%s' intrinsic at %L is empty", | |
c4aa95f8 | 3541 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, |
535ff342 | 3542 | &shape->where); |
524af0d6 | 3543 | return false; |
535ff342 DF |
3544 | } |
3545 | else if (shape_size > GFC_MAX_DIMENSIONS) | |
6de9cd9a | 3546 | { |
31043f6c FXC |
3547 | gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more " |
3548 | "than %d elements", &shape->where, GFC_MAX_DIMENSIONS); | |
524af0d6 | 3549 | return false; |
6de9cd9a | 3550 | } |
df1c8791 | 3551 | else if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape)) |
535ff342 DF |
3552 | { |
3553 | gfc_expr *e; | |
3554 | int i, extent; | |
3555 | for (i = 0; i < shape_size; ++i) | |
3556 | { | |
b7e75771 | 3557 | e = gfc_constructor_lookup_expr (shape->value.constructor, i); |
535ff342 | 3558 | if (e->expr_type != EXPR_CONSTANT) |
b7e75771 | 3559 | continue; |
535ff342 DF |
3560 | |
3561 | gfc_extract_int (e, &extent); | |
3562 | if (extent < 0) | |
3563 | { | |
3564 | gfc_error ("'%s' argument of '%s' intrinsic at %L has " | |
c4aa95f8 JW |
3565 | "negative element (%d)", |
3566 | gfc_current_intrinsic_arg[1]->name, | |
535ff342 | 3567 | gfc_current_intrinsic, &e->where, extent); |
524af0d6 | 3568 | return false; |
535ff342 | 3569 | } |
535ff342 DF |
3570 | } |
3571 | } | |
6de9cd9a DN |
3572 | |
3573 | if (pad != NULL) | |
3574 | { | |
524af0d6 JB |
3575 | if (!same_type_check (source, 0, pad, 2)) |
3576 | return false; | |
535ff342 | 3577 | |
524af0d6 JB |
3578 | if (!array_check (pad, 2)) |
3579 | return false; | |
6de9cd9a DN |
3580 | } |
3581 | ||
535ff342 DF |
3582 | if (order != NULL) |
3583 | { | |
524af0d6 JB |
3584 | if (!array_check (order, 3)) |
3585 | return false; | |
535ff342 | 3586 | |
524af0d6 JB |
3587 | if (!type_check (order, 3, BT_INTEGER)) |
3588 | return false; | |
535ff342 DF |
3589 | |
3590 | if (order->expr_type == EXPR_ARRAY) | |
3591 | { | |
3592 | int i, order_size, dim, perm[GFC_MAX_DIMENSIONS]; | |
3593 | gfc_expr *e; | |
3594 | ||
3595 | for (i = 0; i < GFC_MAX_DIMENSIONS; ++i) | |
3596 | perm[i] = 0; | |
3597 | ||
3598 | gfc_array_size (order, &size); | |
3599 | order_size = mpz_get_ui (size); | |
3600 | mpz_clear (size); | |
3601 | ||
3602 | if (order_size != shape_size) | |
3603 | { | |
3604 | gfc_error ("'%s' argument of '%s' intrinsic at %L " | |
8b704316 | 3605 | "has wrong number of elements (%d/%d)", |
c4aa95f8 | 3606 | gfc_current_intrinsic_arg[3]->name, |
535ff342 DF |
3607 | gfc_current_intrinsic, &order->where, |
3608 | order_size, shape_size); | |
524af0d6 | 3609 | return false; |
535ff342 DF |
3610 | } |
3611 | ||
3612 | for (i = 1; i <= order_size; ++i) | |
3613 | { | |
b7e75771 | 3614 | e = gfc_constructor_lookup_expr (order->value.constructor, i-1); |
535ff342 | 3615 | if (e->expr_type != EXPR_CONSTANT) |
b7e75771 | 3616 | continue; |
535ff342 DF |
3617 | |
3618 | gfc_extract_int (e, &dim); | |
3619 | ||
3620 | if (dim < 1 || dim > order_size) | |
3621 | { | |
3622 | gfc_error ("'%s' argument of '%s' intrinsic at %L " | |
8b704316 | 3623 | "has out-of-range dimension (%d)", |
c4aa95f8 | 3624 | gfc_current_intrinsic_arg[3]->name, |
535ff342 | 3625 | gfc_current_intrinsic, &e->where, dim); |
524af0d6 | 3626 | return false; |
535ff342 DF |
3627 | } |
3628 | ||
3629 | if (perm[dim-1] != 0) | |
3630 | { | |
3631 | gfc_error ("'%s' argument of '%s' intrinsic at %L has " | |
3632 | "invalid permutation of dimensions (dimension " | |
c4aa95f8 JW |
3633 | "'%d' duplicated)", |
3634 | gfc_current_intrinsic_arg[3]->name, | |
535ff342 | 3635 | gfc_current_intrinsic, &e->where, dim); |
524af0d6 | 3636 | return false; |
535ff342 DF |
3637 | } |
3638 | ||
3639 | perm[dim-1] = 1; | |
535ff342 DF |
3640 | } |
3641 | } | |
3642 | } | |
6de9cd9a | 3643 | |
65f8144a SK |
3644 | if (pad == NULL && shape->expr_type == EXPR_ARRAY |
3645 | && gfc_is_constant_expr (shape) | |
3646 | && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as | |
3647 | && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE)) | |
d8d8121a PT |
3648 | { |
3649 | /* Check the match in size between source and destination. */ | |
524af0d6 | 3650 | if (gfc_array_size (source, &nelems)) |
d8d8121a PT |
3651 | { |
3652 | gfc_constructor *c; | |
3653 | bool test; | |
3654 | ||
8b704316 | 3655 | |
d8d8121a | 3656 | mpz_init_set_ui (size, 1); |
b7e75771 JD |
3657 | for (c = gfc_constructor_first (shape->value.constructor); |
3658 | c; c = gfc_constructor_next (c)) | |
d8d8121a PT |
3659 | mpz_mul (size, size, c->expr->value.integer); |
3660 | ||
3661 | test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0; | |
3662 | mpz_clear (nelems); | |
3663 | mpz_clear (size); | |
3664 | ||
3665 | if (test) | |
3666 | { | |
65f8144a SK |
3667 | gfc_error ("Without padding, there are not enough elements " |
3668 | "in the intrinsic RESHAPE source at %L to match " | |
3669 | "the shape", &source->where); | |
524af0d6 | 3670 | return false; |
d8d8121a PT |
3671 | } |
3672 | } | |
3673 | } | |
3674 | ||
524af0d6 | 3675 | return true; |
6de9cd9a DN |
3676 | } |
3677 | ||
3678 | ||
524af0d6 | 3679 | bool |
cf2b3c22 TB |
3680 | gfc_check_same_type_as (gfc_expr *a, gfc_expr *b) |
3681 | { | |
cf2b3c22 TB |
3682 | if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS) |
3683 | { | |
8b704316 PT |
3684 | gfc_error ("'%s' argument of '%s' intrinsic at %L " |
3685 | "cannot be of type %s", | |
3686 | gfc_current_intrinsic_arg[0]->name, | |
3687 | gfc_current_intrinsic, | |
3688 | &a->where, gfc_typename (&a->ts)); | |
524af0d6 | 3689 | return false; |
cf2b3c22 TB |
3690 | } |
3691 | ||
8b704316 | 3692 | if (!(gfc_type_is_extensible (a->ts.u.derived) || UNLIMITED_POLY (a))) |
cf2b3c22 TB |
3693 | { |
3694 | gfc_error ("'%s' argument of '%s' intrinsic at %L " | |
c4aa95f8 JW |
3695 | "must be of an extensible type", |
3696 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, | |
3697 | &a->where); | |
524af0d6 | 3698 | return false; |
cf2b3c22 TB |
3699 | } |
3700 | ||
3701 | if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS) | |
3702 | { | |
8b704316 PT |
3703 | gfc_error ("'%s' argument of '%s' intrinsic at %L " |
3704 | "cannot be of type %s", | |
3705 | gfc_current_intrinsic_arg[0]->name, | |
3706 | gfc_current_intrinsic, | |
3707 | &b->where, gfc_typename (&b->ts)); | |
524af0d6 | 3708 | return false; |
cf2b3c22 TB |
3709 | } |
3710 | ||
8b704316 | 3711 | if (!(gfc_type_is_extensible (b->ts.u.derived) || UNLIMITED_POLY (b))) |
cf2b3c22 TB |
3712 | { |
3713 | gfc_error ("'%s' argument of '%s' intrinsic at %L " | |
c4aa95f8 JW |
3714 | "must be of an extensible type", |
3715 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
3716 | &b->where); | |
524af0d6 | 3717 | return false; |
cf2b3c22 TB |
3718 | } |
3719 | ||
524af0d6 | 3720 | return true; |
cf2b3c22 TB |
3721 | } |
3722 | ||
3723 | ||
524af0d6 | 3724 | bool |
65f8144a | 3725 | gfc_check_scale (gfc_expr *x, gfc_expr *i) |
6de9cd9a | 3726 | { |
524af0d6 JB |
3727 | if (!type_check (x, 0, BT_REAL)) |
3728 | return false; | |
6de9cd9a | 3729 | |
524af0d6 JB |
3730 | if (!type_check (i, 1, BT_INTEGER)) |
3731 | return false; | |
6de9cd9a | 3732 | |
524af0d6 | 3733 | return true; |
6de9cd9a DN |
3734 | } |
3735 | ||
3736 | ||
524af0d6 | 3737 | bool |
5cda5098 | 3738 | gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind) |
6de9cd9a | 3739 | { |
524af0d6 JB |
3740 | if (!type_check (x, 0, BT_CHARACTER)) |
3741 | return false; | |
6de9cd9a | 3742 | |
524af0d6 JB |
3743 | if (!type_check (y, 1, BT_CHARACTER)) |
3744 | return false; | |
6de9cd9a | 3745 | |
524af0d6 JB |
3746 | if (z != NULL && !type_check (z, 2, BT_LOGICAL)) |
3747 | return false; | |
6de9cd9a | 3748 | |
524af0d6 JB |
3749 | if (!kind_check (kind, 3, BT_INTEGER)) |
3750 | return false; | |
3751 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
3752 | "with KIND argument at %L", | |
3753 | gfc_current_intrinsic, &kind->where)) | |
3754 | return false; | |
5cda5098 | 3755 | |
524af0d6 JB |
3756 | if (!same_type_check (x, 0, y, 1)) |
3757 | return false; | |
6de9cd9a | 3758 | |
524af0d6 | 3759 | return true; |
6de9cd9a DN |
3760 | } |
3761 | ||
3762 | ||
524af0d6 | 3763 | bool |
65f8144a | 3764 | gfc_check_secnds (gfc_expr *r) |
53096259 | 3765 | { |
524af0d6 JB |
3766 | if (!type_check (r, 0, BT_REAL)) |
3767 | return false; | |
53096259 | 3768 | |
524af0d6 JB |
3769 | if (!kind_value_check (r, 0, 4)) |
3770 | return false; | |
53096259 | 3771 | |
524af0d6 JB |
3772 | if (!scalar_check (r, 0)) |
3773 | return false; | |
53096259 | 3774 | |
524af0d6 | 3775 | return true; |
53096259 PT |
3776 | } |
3777 | ||
3778 | ||
524af0d6 | 3779 | bool |
a39fafac FXC |
3780 | gfc_check_selected_char_kind (gfc_expr *name) |
3781 | { | |
524af0d6 JB |
3782 | if (!type_check (name, 0, BT_CHARACTER)) |
3783 | return false; | |
a39fafac | 3784 | |
524af0d6 JB |
3785 | if (!kind_value_check (name, 0, gfc_default_character_kind)) |
3786 | return false; | |
a39fafac | 3787 | |
524af0d6 JB |
3788 | if (!scalar_check (name, 0)) |
3789 | return false; | |
a39fafac | 3790 | |
524af0d6 | 3791 | return true; |
a39fafac FXC |
3792 | } |
3793 | ||
3794 | ||
524af0d6 | 3795 | bool |
65f8144a | 3796 | gfc_check_selected_int_kind (gfc_expr *r) |
145cf79b | 3797 | { |
524af0d6 JB |
3798 | if (!type_check (r, 0, BT_INTEGER)) |
3799 | return false; | |
145cf79b | 3800 | |
524af0d6 JB |
3801 | if (!scalar_check (r, 0)) |
3802 | return false; | |
145cf79b | 3803 | |
524af0d6 | 3804 | return true; |
145cf79b SK |
3805 | } |
3806 | ||
3807 | ||
524af0d6 | 3808 | bool |
01349049 | 3809 | gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix) |
6de9cd9a | 3810 | { |
01349049 | 3811 | if (p == NULL && r == NULL |
524af0d6 JB |
3812 | && !gfc_notify_std (GFC_STD_F2008, "SELECTED_REAL_KIND with" |
3813 | " neither 'P' nor 'R' argument at %L", | |
3814 | gfc_current_intrinsic_where)) | |
3815 | return false; | |
6de9cd9a | 3816 | |
70987f62 DF |
3817 | if (p) |
3818 | { | |
524af0d6 JB |
3819 | if (!type_check (p, 0, BT_INTEGER)) |
3820 | return false; | |
6de9cd9a | 3821 | |
524af0d6 JB |
3822 | if (!scalar_check (p, 0)) |
3823 | return false; | |
70987f62 DF |
3824 | } |
3825 | ||
3826 | if (r) | |
3827 | { | |
524af0d6 JB |
3828 | if (!type_check (r, 1, BT_INTEGER)) |
3829 | return false; | |
70987f62 | 3830 | |
524af0d6 JB |
3831 | if (!scalar_check (r, 1)) |
3832 | return false; | |
70987f62 | 3833 | } |
6de9cd9a | 3834 | |
01349049 TB |
3835 | if (radix) |
3836 | { | |
524af0d6 JB |
3837 | if (!type_check (radix, 1, BT_INTEGER)) |
3838 | return false; | |
01349049 | 3839 | |
524af0d6 JB |
3840 | if (!scalar_check (radix, 1)) |
3841 | return false; | |
01349049 | 3842 | |
524af0d6 JB |
3843 | if (!gfc_notify_std (GFC_STD_F2008, "'%s' intrinsic with " |
3844 | "RADIX argument at %L", gfc_current_intrinsic, | |
3845 | &radix->where)) | |
3846 | return false; | |
01349049 TB |
3847 | } |
3848 | ||
524af0d6 | 3849 | return true; |
6de9cd9a DN |
3850 | } |
3851 | ||
3852 | ||
524af0d6 | 3853 | bool |
65f8144a | 3854 | gfc_check_set_exponent (gfc_expr *x, gfc_expr *i) |
6de9cd9a | 3855 | { |
524af0d6 JB |
3856 | if (!type_check (x, 0, BT_REAL)) |
3857 | return false; | |
6de9cd9a | 3858 | |
524af0d6 JB |
3859 | if (!type_check (i, 1, BT_INTEGER)) |
3860 | return false; | |
6de9cd9a | 3861 | |
524af0d6 | 3862 | return true; |
6de9cd9a DN |
3863 | } |
3864 | ||
3865 | ||
524af0d6 | 3866 | bool |
7320cf09 | 3867 | gfc_check_shape (gfc_expr *source, gfc_expr *kind) |
6de9cd9a DN |
3868 | { |
3869 | gfc_array_ref *ar; | |
3870 | ||
3871 | if (source->rank == 0 || source->expr_type != EXPR_VARIABLE) | |
524af0d6 | 3872 | return true; |
6de9cd9a DN |
3873 | |
3874 | ar = gfc_find_array_ref (source); | |
3875 | ||
86288ff0 | 3876 | if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL) |
6de9cd9a DN |
3877 | { |
3878 | gfc_error ("'source' argument of 'shape' intrinsic at %L must not be " | |
3879 | "an assumed size array", &source->where); | |
524af0d6 | 3880 | return false; |
6de9cd9a DN |
3881 | } |
3882 | ||
524af0d6 JB |
3883 | if (!kind_check (kind, 1, BT_INTEGER)) |
3884 | return false; | |
3885 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
3886 | "with KIND argument at %L", | |
3887 | gfc_current_intrinsic, &kind->where)) | |
3888 | return false; | |
7320cf09 | 3889 | |
524af0d6 | 3890 | return true; |
6de9cd9a DN |
3891 | } |
3892 | ||
3893 | ||
524af0d6 | 3894 | bool |
88a95a11 FXC |
3895 | gfc_check_shift (gfc_expr *i, gfc_expr *shift) |
3896 | { | |
524af0d6 JB |
3897 | if (!type_check (i, 0, BT_INTEGER)) |
3898 | return false; | |
88a95a11 | 3899 | |
524af0d6 JB |
3900 | if (!type_check (shift, 0, BT_INTEGER)) |
3901 | return false; | |
88a95a11 | 3902 | |
524af0d6 JB |
3903 | if (!nonnegative_check ("SHIFT", shift)) |
3904 | return false; | |
88a95a11 | 3905 | |
524af0d6 JB |
3906 | if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true)) |
3907 | return false; | |
88a95a11 | 3908 | |
524af0d6 | 3909 | return true; |
88a95a11 FXC |
3910 | } |
3911 | ||
3912 | ||
524af0d6 | 3913 | bool |
65f8144a | 3914 | gfc_check_sign (gfc_expr *a, gfc_expr *b) |
6de9cd9a | 3915 | { |
524af0d6 JB |
3916 | if (!int_or_real_check (a, 0)) |
3917 | return false; | |
6de9cd9a | 3918 | |
524af0d6 JB |
3919 | if (!same_type_check (a, 0, b, 1)) |
3920 | return false; | |
27dfc9c4 | 3921 | |
524af0d6 | 3922 | return true; |
27dfc9c4 TS |
3923 | } |
3924 | ||
3925 | ||
524af0d6 | 3926 | bool |
5cda5098 | 3927 | gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
27dfc9c4 | 3928 | { |
524af0d6 JB |
3929 | if (!array_check (array, 0)) |
3930 | return false; | |
6de9cd9a | 3931 | |
524af0d6 JB |
3932 | if (!dim_check (dim, 1, true)) |
3933 | return false; | |
6de9cd9a | 3934 | |
524af0d6 JB |
3935 | if (!dim_rank_check (dim, array, 0)) |
3936 | return false; | |
6de9cd9a | 3937 | |
524af0d6 JB |
3938 | if (!kind_check (kind, 2, BT_INTEGER)) |
3939 | return false; | |
3940 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
3941 | "with KIND argument at %L", | |
3942 | gfc_current_intrinsic, &kind->where)) | |
3943 | return false; | |
5cda5098 FXC |
3944 | |
3945 | ||
524af0d6 | 3946 | return true; |
6de9cd9a DN |
3947 | } |
3948 | ||
3949 | ||
524af0d6 | 3950 | bool |
2c23ebfe | 3951 | gfc_check_sizeof (gfc_expr *arg) |
fd2157ce | 3952 | { |
2c23ebfe JW |
3953 | if (arg->ts.type == BT_PROCEDURE) |
3954 | { | |
1a8c1e35 | 3955 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be a procedure", |
2c23ebfe JW |
3956 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, |
3957 | &arg->where); | |
524af0d6 | 3958 | return false; |
2c23ebfe | 3959 | } |
1a8c1e35 | 3960 | |
69c3654c TB |
3961 | /* TYPE(*) is acceptable if and only if it uses an array descriptor. */ |
3962 | if (arg->ts.type == BT_ASSUMED | |
3963 | && (arg->symtree->n.sym->as == NULL | |
3964 | || (arg->symtree->n.sym->as->type != AS_ASSUMED_SHAPE | |
3965 | && arg->symtree->n.sym->as->type != AS_DEFERRED | |
3966 | && arg->symtree->n.sym->as->type != AS_ASSUMED_RANK))) | |
1a8c1e35 TB |
3967 | { |
3968 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be TYPE(*)", | |
3969 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, | |
3970 | &arg->where); | |
524af0d6 | 3971 | return false; |
1a8c1e35 TB |
3972 | } |
3973 | ||
3974 | if (arg->rank && arg->expr_type == EXPR_VARIABLE | |
3975 | && arg->symtree->n.sym->as != NULL | |
3976 | && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref | |
3977 | && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL) | |
3978 | { | |
3979 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be an " | |
3980 | "assumed-size array", gfc_current_intrinsic_arg[0]->name, | |
3981 | gfc_current_intrinsic, &arg->where); | |
524af0d6 | 3982 | return false; |
1a8c1e35 TB |
3983 | } |
3984 | ||
524af0d6 | 3985 | return true; |
fd2157ce TS |
3986 | } |
3987 | ||
3988 | ||
cadddfdd TB |
3989 | /* Check whether an expression is interoperable. When returning false, |
3990 | msg is set to a string telling why the expression is not interoperable, | |
3991 | otherwise, it is set to NULL. The msg string can be used in diagnostics. | |
6082753e TB |
3992 | If c_loc is true, character with len > 1 are allowed (cf. Fortran |
3993 | 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape | |
5e7ea214 | 3994 | arrays are permitted. And if c_f_ptr is true, deferred-shape arrays |
1cc0e193 | 3995 | are permitted. */ |
cadddfdd TB |
3996 | |
3997 | static bool | |
5e7ea214 | 3998 | is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr) |
cadddfdd TB |
3999 | { |
4000 | *msg = NULL; | |
4001 | ||
4002 | if (expr->ts.type == BT_CLASS) | |
4003 | { | |
4004 | *msg = "Expression is polymorphic"; | |
4005 | return false; | |
4006 | } | |
4007 | ||
4008 | if (expr->ts.type == BT_DERIVED && !expr->ts.u.derived->attr.is_bind_c | |
4009 | && !expr->ts.u.derived->ts.is_iso_c) | |
4010 | { | |
4011 | *msg = "Expression is a noninteroperable derived type"; | |
4012 | return false; | |
4013 | } | |
4014 | ||
4015 | if (expr->ts.type == BT_PROCEDURE) | |
4016 | { | |
4017 | *msg = "Procedure unexpected as argument"; | |
4018 | return false; | |
4019 | } | |
4020 | ||
4021 | if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_LOGICAL) | |
4022 | { | |
4023 | int i; | |
4024 | for (i = 0; gfc_logical_kinds[i].kind; i++) | |
4025 | if (gfc_logical_kinds[i].kind == expr->ts.kind) | |
4026 | return true; | |
4027 | *msg = "Extension to use a non-C_Bool-kind LOGICAL"; | |
4028 | return false; | |
4029 | } | |
4030 | ||
4031 | if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_CHARACTER | |
4032 | && expr->ts.kind != 1) | |
4033 | { | |
4034 | *msg = "Extension to use a non-C_CHAR-kind CHARACTER"; | |
4035 | return false; | |
4036 | } | |
4037 | ||
4038 | if (expr->ts.type == BT_CHARACTER) { | |
4039 | if (expr->ts.deferred) | |
4040 | { | |
4041 | /* TS 29113 allows deferred-length strings as dummy arguments, | |
1cc0e193 | 4042 | but it is not an interoperable type. */ |
cadddfdd TB |
4043 | *msg = "Expression shall not be a deferred-length string"; |
4044 | return false; | |
4045 | } | |
4046 | ||
4047 | if (expr->ts.u.cl && expr->ts.u.cl->length | |
524af0d6 | 4048 | && !gfc_simplify_expr (expr, 0)) |
cadddfdd TB |
4049 | gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed"); |
4050 | ||
6082753e | 4051 | if (!c_loc && expr->ts.u.cl |
cadddfdd TB |
4052 | && (!expr->ts.u.cl->length |
4053 | || expr->ts.u.cl->length->expr_type != EXPR_CONSTANT | |
4054 | || mpz_cmp_si (expr->ts.u.cl->length->value.integer, 1) != 0)) | |
4055 | { | |
4056 | *msg = "Type shall have a character length of 1"; | |
4057 | return false; | |
4058 | } | |
4059 | } | |
4060 | ||
4061 | /* Note: The following checks are about interoperatable variables, Fortran | |
4062 | 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more | |
4063 | is allowed, e.g. assumed-shape arrays with TS 29113. */ | |
4064 | ||
4065 | if (gfc_is_coarray (expr)) | |
4066 | { | |
4067 | *msg = "Coarrays are not interoperable"; | |
4068 | return false; | |
4069 | } | |
4070 | ||
6082753e | 4071 | if (!c_loc && expr->rank > 0 && expr->expr_type != EXPR_ARRAY) |
cadddfdd TB |
4072 | { |
4073 | gfc_array_ref *ar = gfc_find_array_ref (expr); | |
4074 | if (ar->type != AR_FULL) | |
4075 | { | |
4076 | *msg = "Only whole-arrays are interoperable"; | |
4077 | return false; | |
4078 | } | |
5e7ea214 TB |
4079 | if (!c_f_ptr && ar->as->type != AS_EXPLICIT |
4080 | && ar->as->type != AS_ASSUMED_SIZE) | |
cadddfdd TB |
4081 | { |
4082 | *msg = "Only explicit-size and assumed-size arrays are interoperable"; | |
4083 | return false; | |
4084 | } | |
4085 | } | |
4086 | ||
4087 | return true; | |
4088 | } | |
4089 | ||
4090 | ||
524af0d6 | 4091 | bool |
048510c8 JW |
4092 | gfc_check_c_sizeof (gfc_expr *arg) |
4093 | { | |
cadddfdd TB |
4094 | const char *msg; |
4095 | ||
5e7ea214 | 4096 | if (!is_c_interoperable (arg, &msg, false, false)) |
048510c8 | 4097 | { |
40ebf57b | 4098 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be an " |
cadddfdd | 4099 | "interoperable data entity: %s", |
c4aa95f8 | 4100 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, |
cadddfdd | 4101 | &arg->where, msg); |
524af0d6 | 4102 | return false; |
cadddfdd TB |
4103 | } |
4104 | ||
1a8c1e35 TB |
4105 | if (arg->ts.type == BT_ASSUMED) |
4106 | { | |
4107 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be " | |
4108 | "TYPE(*)", | |
4109 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, | |
4110 | &arg->where); | |
524af0d6 | 4111 | return false; |
1a8c1e35 TB |
4112 | } |
4113 | ||
cadddfdd TB |
4114 | if (arg->rank && arg->expr_type == EXPR_VARIABLE |
4115 | && arg->symtree->n.sym->as != NULL | |
4116 | && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref | |
4117 | && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL) | |
4118 | { | |
4119 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be an " | |
4120 | "assumed-size array", gfc_current_intrinsic_arg[0]->name, | |
4121 | gfc_current_intrinsic, &arg->where); | |
524af0d6 | 4122 | return false; |
cadddfdd TB |
4123 | } |
4124 | ||
524af0d6 | 4125 | return true; |
cadddfdd TB |
4126 | } |
4127 | ||
4128 | ||
524af0d6 | 4129 | bool |
cadddfdd TB |
4130 | gfc_check_c_associated (gfc_expr *c_ptr_1, gfc_expr *c_ptr_2) |
4131 | { | |
4132 | if (c_ptr_1->ts.type != BT_DERIVED | |
4133 | || c_ptr_1->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING | |
4134 | || (c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR | |
4135 | && c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR)) | |
4136 | { | |
4137 | gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the " | |
4138 | "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1->where); | |
524af0d6 | 4139 | return false; |
cadddfdd TB |
4140 | } |
4141 | ||
524af0d6 JB |
4142 | if (!scalar_check (c_ptr_1, 0)) |
4143 | return false; | |
cadddfdd TB |
4144 | |
4145 | if (c_ptr_2 | |
4146 | && (c_ptr_2->ts.type != BT_DERIVED | |
4147 | || c_ptr_2->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING | |
4148 | || (c_ptr_1->ts.u.derived->intmod_sym_id | |
4149 | != c_ptr_2->ts.u.derived->intmod_sym_id))) | |
4150 | { | |
4151 | gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the " | |
4152 | "same type as C_PTR_1: %s instead of %s", &c_ptr_1->where, | |
4153 | gfc_typename (&c_ptr_1->ts), | |
4154 | gfc_typename (&c_ptr_2->ts)); | |
524af0d6 | 4155 | return false; |
cadddfdd TB |
4156 | } |
4157 | ||
524af0d6 JB |
4158 | if (c_ptr_2 && !scalar_check (c_ptr_2, 1)) |
4159 | return false; | |
cadddfdd | 4160 | |
524af0d6 | 4161 | return true; |
cadddfdd TB |
4162 | } |
4163 | ||
4164 | ||
524af0d6 | 4165 | bool |
cadddfdd TB |
4166 | gfc_check_c_f_pointer (gfc_expr *cptr, gfc_expr *fptr, gfc_expr *shape) |
4167 | { | |
4168 | symbol_attribute attr; | |
4169 | const char *msg; | |
4170 | ||
4171 | if (cptr->ts.type != BT_DERIVED | |
4172 | || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING | |
4173 | || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR) | |
4174 | { | |
4175 | gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the " | |
4176 | "type TYPE(C_PTR)", &cptr->where); | |
524af0d6 | 4177 | return false; |
cadddfdd TB |
4178 | } |
4179 | ||
524af0d6 JB |
4180 | if (!scalar_check (cptr, 0)) |
4181 | return false; | |
cadddfdd TB |
4182 | |
4183 | attr = gfc_expr_attr (fptr); | |
4184 | ||
4185 | if (!attr.pointer) | |
4186 | { | |
4187 | gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer", | |
4188 | &fptr->where); | |
524af0d6 | 4189 | return false; |
cadddfdd TB |
4190 | } |
4191 | ||
4192 | if (fptr->ts.type == BT_CLASS) | |
4193 | { | |
4194 | gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic", | |
4195 | &fptr->where); | |
524af0d6 | 4196 | return false; |
cadddfdd TB |
4197 | } |
4198 | ||
4199 | if (gfc_is_coindexed (fptr)) | |
4200 | { | |
4201 | gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be " | |
4202 | "coindexed", &fptr->where); | |
524af0d6 | 4203 | return false; |
cadddfdd TB |
4204 | } |
4205 | ||
4206 | if (fptr->rank == 0 && shape) | |
4207 | { | |
4208 | gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar " | |
4209 | "FPTR", &fptr->where); | |
524af0d6 | 4210 | return false; |
cadddfdd TB |
4211 | } |
4212 | else if (fptr->rank && !shape) | |
4213 | { | |
4214 | gfc_error ("Expected SHAPE argument to C_F_POINTER with array " | |
4215 | "FPTR at %L", &fptr->where); | |
524af0d6 | 4216 | return false; |
cadddfdd TB |
4217 | } |
4218 | ||
524af0d6 JB |
4219 | if (shape && !rank_check (shape, 2, 1)) |
4220 | return false; | |
cadddfdd | 4221 | |
524af0d6 JB |
4222 | if (shape && !type_check (shape, 2, BT_INTEGER)) |
4223 | return false; | |
cadddfdd TB |
4224 | |
4225 | if (shape) | |
4226 | { | |
4227 | mpz_t size; | |
f1ed9e15 | 4228 | if (gfc_array_size (shape, &size)) |
cadddfdd | 4229 | { |
f1ed9e15 JW |
4230 | if (mpz_cmp_ui (size, fptr->rank) != 0) |
4231 | { | |
4232 | mpz_clear (size); | |
4233 | gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same " | |
4234 | "size as the RANK of FPTR", &shape->where); | |
4235 | return false; | |
4236 | } | |
cadddfdd | 4237 | mpz_clear (size); |
cadddfdd | 4238 | } |
cadddfdd TB |
4239 | } |
4240 | ||
4241 | if (fptr->ts.type == BT_CLASS) | |
4242 | { | |
4243 | gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr->where); | |
524af0d6 | 4244 | return false; |
cadddfdd TB |
4245 | } |
4246 | ||
5e7ea214 | 4247 | if (!is_c_interoperable (fptr, &msg, false, true)) |
cadddfdd TB |
4248 | return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable array FPTR " |
4249 | "at %L to C_F_POINTER: %s", &fptr->where, msg); | |
4250 | ||
524af0d6 | 4251 | return true; |
cadddfdd TB |
4252 | } |
4253 | ||
4254 | ||
524af0d6 | 4255 | bool |
cadddfdd TB |
4256 | gfc_check_c_f_procpointer (gfc_expr *cptr, gfc_expr *fptr) |
4257 | { | |
4258 | symbol_attribute attr; | |
4259 | ||
4260 | if (cptr->ts.type != BT_DERIVED | |
4261 | || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING | |
4262 | || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR) | |
4263 | { | |
4264 | gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the " | |
4265 | "type TYPE(C_FUNPTR)", &cptr->where); | |
524af0d6 | 4266 | return false; |
cadddfdd TB |
4267 | } |
4268 | ||
524af0d6 JB |
4269 | if (!scalar_check (cptr, 0)) |
4270 | return false; | |
cadddfdd TB |
4271 | |
4272 | attr = gfc_expr_attr (fptr); | |
4273 | ||
4274 | if (!attr.proc_pointer) | |
4275 | { | |
4276 | gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure " | |
4277 | "pointer", &fptr->where); | |
524af0d6 | 4278 | return false; |
cadddfdd TB |
4279 | } |
4280 | ||
4281 | if (gfc_is_coindexed (fptr)) | |
4282 | { | |
4283 | gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be " | |
4284 | "coindexed", &fptr->where); | |
524af0d6 | 4285 | return false; |
cadddfdd TB |
4286 | } |
4287 | ||
4288 | if (!attr.is_bind_c) | |
4289 | return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure " | |
4290 | "pointer at %L to C_F_PROCPOINTER", &fptr->where); | |
4291 | ||
524af0d6 | 4292 | return true; |
cadddfdd TB |
4293 | } |
4294 | ||
4295 | ||
524af0d6 | 4296 | bool |
cadddfdd TB |
4297 | gfc_check_c_funloc (gfc_expr *x) |
4298 | { | |
4299 | symbol_attribute attr; | |
4300 | ||
4301 | if (gfc_is_coindexed (x)) | |
4302 | { | |
4303 | gfc_error ("Argument X at %L to C_FUNLOC shall not be " | |
4304 | "coindexed", &x->where); | |
524af0d6 | 4305 | return false; |
048510c8 | 4306 | } |
cadddfdd TB |
4307 | |
4308 | attr = gfc_expr_attr (x); | |
4309 | ||
4310 | if (attr.function && !attr.proc_pointer && x->expr_type == EXPR_VARIABLE | |
4311 | && x->symtree->n.sym == x->symtree->n.sym->result) | |
4312 | { | |
4313 | gfc_namespace *ns = gfc_current_ns; | |
4314 | ||
4315 | for (ns = gfc_current_ns; ns; ns = ns->parent) | |
4316 | if (x->symtree->n.sym == ns->proc_name) | |
4317 | { | |
4318 | gfc_error ("Function result '%s' at %L is invalid as X argument " | |
4319 | "to C_FUNLOC", x->symtree->n.sym->name, &x->where); | |
524af0d6 | 4320 | return false; |
cadddfdd TB |
4321 | } |
4322 | } | |
4323 | ||
4324 | if (attr.flavor != FL_PROCEDURE) | |
4325 | { | |
4326 | gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure " | |
4327 | "or a procedure pointer", &x->where); | |
524af0d6 | 4328 | return false; |
cadddfdd TB |
4329 | } |
4330 | ||
4331 | if (!attr.is_bind_c) | |
4332 | return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure " | |
4333 | "at %L to C_FUNLOC", &x->where); | |
524af0d6 | 4334 | return true; |
cadddfdd TB |
4335 | } |
4336 | ||
4337 | ||
524af0d6 | 4338 | bool |
cadddfdd TB |
4339 | gfc_check_c_loc (gfc_expr *x) |
4340 | { | |
4341 | symbol_attribute attr; | |
4342 | const char *msg; | |
4343 | ||
4344 | if (gfc_is_coindexed (x)) | |
4345 | { | |
4346 | gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x->where); | |
524af0d6 | 4347 | return false; |
cadddfdd TB |
4348 | } |
4349 | ||
4350 | if (x->ts.type == BT_CLASS) | |
4351 | { | |
4352 | gfc_error ("X argument at %L to C_LOC shall not be polymorphic", | |
4353 | &x->where); | |
524af0d6 | 4354 | return false; |
cadddfdd TB |
4355 | } |
4356 | ||
4357 | attr = gfc_expr_attr (x); | |
4358 | ||
4359 | if (!attr.pointer | |
4360 | && (x->expr_type != EXPR_VARIABLE || !attr.target | |
4361 | || attr.flavor == FL_PARAMETER)) | |
4362 | { | |
4363 | gfc_error ("Argument X at %L to C_LOC shall have either " | |
4364 | "the POINTER or the TARGET attribute", &x->where); | |
524af0d6 | 4365 | return false; |
cadddfdd TB |
4366 | } |
4367 | ||
4368 | if (x->ts.type == BT_CHARACTER | |
4369 | && gfc_var_strlen (x) == 0) | |
4370 | { | |
4371 | gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized " | |
4372 | "string", &x->where); | |
524af0d6 | 4373 | return false; |
cadddfdd TB |
4374 | } |
4375 | ||
5e7ea214 | 4376 | if (!is_c_interoperable (x, &msg, true, false)) |
cadddfdd TB |
4377 | { |
4378 | if (x->ts.type == BT_CLASS) | |
4379 | { | |
4380 | gfc_error ("Argument at %L to C_LOC shall not be polymorphic", | |
4381 | &x->where); | |
524af0d6 | 4382 | return false; |
cadddfdd TB |
4383 | } |
4384 | ||
4385 | if (x->rank | |
524af0d6 JB |
4386 | && !gfc_notify_std (GFC_STD_F2008_TS, |
4387 | "Noninteroperable array at %L as" | |
4388 | " argument to C_LOC: %s", &x->where, msg)) | |
4389 | return false; | |
cadddfdd | 4390 | } |
6082753e TB |
4391 | else if (x->rank > 0 && gfc_notification_std (GFC_STD_F2008)) |
4392 | { | |
4393 | gfc_array_ref *ar = gfc_find_array_ref (x); | |
4394 | ||
4395 | if (ar->as->type != AS_EXPLICIT && ar->as->type != AS_ASSUMED_SIZE | |
4396 | && !attr.allocatable | |
524af0d6 JB |
4397 | && !gfc_notify_std (GFC_STD_F2008, |
4398 | "Array of interoperable type at %L " | |
4399 | "to C_LOC which is nonallocatable and neither " | |
4400 | "assumed size nor explicit size", &x->where)) | |
4401 | return false; | |
6082753e | 4402 | else if (ar->type != AR_FULL |
524af0d6 JB |
4403 | && !gfc_notify_std (GFC_STD_F2008, "Array section at %L " |
4404 | "to C_LOC", &x->where)) | |
4405 | return false; | |
6082753e | 4406 | } |
cadddfdd | 4407 | |
524af0d6 | 4408 | return true; |
048510c8 JW |
4409 | } |
4410 | ||
4411 | ||
524af0d6 | 4412 | bool |
65f8144a | 4413 | gfc_check_sleep_sub (gfc_expr *seconds) |
f77b6ca3 | 4414 | { |
524af0d6 JB |
4415 | if (!type_check (seconds, 0, BT_INTEGER)) |
4416 | return false; | |
f77b6ca3 | 4417 | |
524af0d6 JB |
4418 | if (!scalar_check (seconds, 0)) |
4419 | return false; | |
f77b6ca3 | 4420 | |
524af0d6 | 4421 | return true; |
f77b6ca3 FXC |
4422 | } |
4423 | ||
524af0d6 | 4424 | bool |
c9018c71 DF |
4425 | gfc_check_sngl (gfc_expr *a) |
4426 | { | |
524af0d6 JB |
4427 | if (!type_check (a, 0, BT_REAL)) |
4428 | return false; | |
c9018c71 DF |
4429 | |
4430 | if ((a->ts.kind != gfc_default_double_kind) | |
524af0d6 JB |
4431 | && !gfc_notify_std (GFC_STD_GNU, "non double precision " |
4432 | "REAL argument to %s intrinsic at %L", | |
4433 | gfc_current_intrinsic, &a->where)) | |
4434 | return false; | |
c9018c71 | 4435 | |
524af0d6 | 4436 | return true; |
c9018c71 | 4437 | } |
f77b6ca3 | 4438 | |
524af0d6 | 4439 | bool |
65f8144a | 4440 | gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies) |
6de9cd9a | 4441 | { |
6de9cd9a DN |
4442 | if (source->rank >= GFC_MAX_DIMENSIONS) |
4443 | { | |
4c93c95a | 4444 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be less " |
c4aa95f8 | 4445 | "than rank %d", gfc_current_intrinsic_arg[0]->name, |
4c93c95a | 4446 | gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS); |
31043f6c | 4447 | |
524af0d6 | 4448 | return false; |
6de9cd9a DN |
4449 | } |
4450 | ||
7ab88654 | 4451 | if (dim == NULL) |
524af0d6 | 4452 | return false; |
7ab88654 | 4453 | |
524af0d6 JB |
4454 | if (!dim_check (dim, 1, false)) |
4455 | return false; | |
6de9cd9a | 4456 | |
c430a6f9 | 4457 | /* dim_rank_check() does not apply here. */ |
8b704316 | 4458 | if (dim |
c430a6f9 DF |
4459 | && dim->expr_type == EXPR_CONSTANT |
4460 | && (mpz_cmp_ui (dim->value.integer, 1) < 0 | |
4461 | || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0)) | |
4462 | { | |
4463 | gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid " | |
c4aa95f8 | 4464 | "dimension index", gfc_current_intrinsic_arg[1]->name, |
c430a6f9 | 4465 | gfc_current_intrinsic, &dim->where); |
524af0d6 | 4466 | return false; |
c430a6f9 DF |
4467 | } |
4468 | ||
524af0d6 JB |
4469 | if (!type_check (ncopies, 2, BT_INTEGER)) |
4470 | return false; | |
df65f093 | 4471 | |
524af0d6 JB |
4472 | if (!scalar_check (ncopies, 2)) |
4473 | return false; | |
6de9cd9a | 4474 | |
524af0d6 | 4475 | return true; |
6de9cd9a DN |
4476 | } |
4477 | ||
4478 | ||
5d723e54 FXC |
4479 | /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and |
4480 | functions). */ | |
65f8144a | 4481 | |
524af0d6 | 4482 | bool |
65f8144a | 4483 | gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status) |
5d723e54 | 4484 | { |
524af0d6 JB |
4485 | if (!type_check (unit, 0, BT_INTEGER)) |
4486 | return false; | |
5d723e54 | 4487 | |
524af0d6 JB |
4488 | if (!scalar_check (unit, 0)) |
4489 | return false; | |
5d723e54 | 4490 | |
524af0d6 JB |
4491 | if (!type_check (c, 1, BT_CHARACTER)) |
4492 | return false; | |
4493 | if (!kind_value_check (c, 1, gfc_default_character_kind)) | |
4494 | return false; | |
5d723e54 FXC |
4495 | |
4496 | if (status == NULL) | |
524af0d6 | 4497 | return true; |
5d723e54 | 4498 | |
524af0d6 JB |
4499 | if (!type_check (status, 2, BT_INTEGER) |
4500 | || !kind_value_check (status, 2, gfc_default_integer_kind) | |
4501 | || !scalar_check (status, 2)) | |
4502 | return false; | |
5d723e54 | 4503 | |
524af0d6 | 4504 | return true; |
5d723e54 FXC |
4505 | } |
4506 | ||
4507 | ||
524af0d6 | 4508 | bool |
65f8144a | 4509 | gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c) |
5d723e54 FXC |
4510 | { |
4511 | return gfc_check_fgetputc_sub (unit, c, NULL); | |
4512 | } | |
4513 | ||
4514 | ||
524af0d6 | 4515 | bool |
65f8144a | 4516 | gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status) |
5d723e54 | 4517 | { |
524af0d6 JB |
4518 | if (!type_check (c, 0, BT_CHARACTER)) |
4519 | return false; | |
4520 | if (!kind_value_check (c, 0, gfc_default_character_kind)) | |
4521 | return false; | |
5d723e54 FXC |
4522 | |
4523 | if (status == NULL) | |
524af0d6 | 4524 | return true; |
5d723e54 | 4525 | |
524af0d6 JB |
4526 | if (!type_check (status, 1, BT_INTEGER) |
4527 | || !kind_value_check (status, 1, gfc_default_integer_kind) | |
4528 | || !scalar_check (status, 1)) | |
4529 | return false; | |
5d723e54 | 4530 | |
524af0d6 | 4531 | return true; |
5d723e54 FXC |
4532 | } |
4533 | ||
4534 | ||
524af0d6 | 4535 | bool |
65f8144a | 4536 | gfc_check_fgetput (gfc_expr *c) |
5d723e54 FXC |
4537 | { |
4538 | return gfc_check_fgetput_sub (c, NULL); | |
4539 | } | |
4540 | ||
4541 | ||
524af0d6 | 4542 | bool |
dcdc26df DF |
4543 | gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status) |
4544 | { | |
524af0d6 JB |
4545 | if (!type_check (unit, 0, BT_INTEGER)) |
4546 | return false; | |
dcdc26df | 4547 | |
524af0d6 JB |
4548 | if (!scalar_check (unit, 0)) |
4549 | return false; | |
dcdc26df | 4550 | |
524af0d6 JB |
4551 | if (!type_check (offset, 1, BT_INTEGER)) |
4552 | return false; | |
dcdc26df | 4553 | |
524af0d6 JB |
4554 | if (!scalar_check (offset, 1)) |
4555 | return false; | |
dcdc26df | 4556 | |
524af0d6 JB |
4557 | if (!type_check (whence, 2, BT_INTEGER)) |
4558 | return false; | |
dcdc26df | 4559 | |
524af0d6 JB |
4560 | if (!scalar_check (whence, 2)) |
4561 | return false; | |
dcdc26df DF |
4562 | |
4563 | if (status == NULL) | |
524af0d6 | 4564 | return true; |
dcdc26df | 4565 | |
524af0d6 JB |
4566 | if (!type_check (status, 3, BT_INTEGER)) |
4567 | return false; | |
dcdc26df | 4568 | |
524af0d6 JB |
4569 | if (!kind_value_check (status, 3, 4)) |
4570 | return false; | |
dcdc26df | 4571 | |
524af0d6 JB |
4572 | if (!scalar_check (status, 3)) |
4573 | return false; | |
dcdc26df | 4574 | |
524af0d6 | 4575 | return true; |
dcdc26df DF |
4576 | } |
4577 | ||
4578 | ||
4579 | ||
524af0d6 | 4580 | bool |
65f8144a | 4581 | gfc_check_fstat (gfc_expr *unit, gfc_expr *array) |
df65f093 | 4582 | { |
524af0d6 JB |
4583 | if (!type_check (unit, 0, BT_INTEGER)) |
4584 | return false; | |
df65f093 | 4585 | |
524af0d6 JB |
4586 | if (!scalar_check (unit, 0)) |
4587 | return false; | |
df65f093 | 4588 | |
524af0d6 JB |
4589 | if (!type_check (array, 1, BT_INTEGER) |
4590 | || !kind_value_check (unit, 0, gfc_default_integer_kind)) | |
4591 | return false; | |
df65f093 | 4592 | |
524af0d6 JB |
4593 | if (!array_check (array, 1)) |
4594 | return false; | |
df65f093 | 4595 | |
524af0d6 | 4596 | return true; |
df65f093 SK |
4597 | } |
4598 | ||
4599 | ||
524af0d6 | 4600 | bool |
65f8144a | 4601 | gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status) |
df65f093 | 4602 | { |
524af0d6 JB |
4603 | if (!type_check (unit, 0, BT_INTEGER)) |
4604 | return false; | |
df65f093 | 4605 | |
524af0d6 JB |
4606 | if (!scalar_check (unit, 0)) |
4607 | return false; | |
df65f093 | 4608 | |
524af0d6 JB |
4609 | if (!type_check (array, 1, BT_INTEGER) |
4610 | || !kind_value_check (array, 1, gfc_default_integer_kind)) | |
4611 | return false; | |
df65f093 | 4612 | |
524af0d6 JB |
4613 | if (!array_check (array, 1)) |
4614 | return false; | |
df65f093 SK |
4615 | |
4616 | if (status == NULL) | |
524af0d6 | 4617 | return true; |
df65f093 | 4618 | |
524af0d6 JB |
4619 | if (!type_check (status, 2, BT_INTEGER) |
4620 | || !kind_value_check (status, 2, gfc_default_integer_kind)) | |
4621 | return false; | |
df65f093 | 4622 | |
524af0d6 JB |
4623 | if (!scalar_check (status, 2)) |
4624 | return false; | |
df65f093 | 4625 | |
524af0d6 | 4626 | return true; |
df65f093 SK |
4627 | } |
4628 | ||
4629 | ||
524af0d6 | 4630 | bool |
65f8144a | 4631 | gfc_check_ftell (gfc_expr *unit) |
5d723e54 | 4632 | { |
524af0d6 JB |
4633 | if (!type_check (unit, 0, BT_INTEGER)) |
4634 | return false; | |
5d723e54 | 4635 | |
524af0d6 JB |
4636 | if (!scalar_check (unit, 0)) |
4637 | return false; | |
5d723e54 | 4638 | |
524af0d6 | 4639 | return true; |
5d723e54 FXC |
4640 | } |
4641 | ||
4642 | ||
524af0d6 | 4643 | bool |
65f8144a | 4644 | gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset) |
5d723e54 | 4645 | { |
524af0d6 JB |
4646 | if (!type_check (unit, 0, BT_INTEGER)) |
4647 | return false; | |
5d723e54 | 4648 | |
524af0d6 JB |
4649 | if (!scalar_check (unit, 0)) |
4650 | return false; | |
5d723e54 | 4651 | |
524af0d6 JB |
4652 | if (!type_check (offset, 1, BT_INTEGER)) |
4653 | return false; | |
5d723e54 | 4654 | |
524af0d6 JB |
4655 | if (!scalar_check (offset, 1)) |
4656 | return false; | |
5d723e54 | 4657 | |
524af0d6 | 4658 | return true; |
5d723e54 FXC |
4659 | } |
4660 | ||
4661 | ||
524af0d6 | 4662 | bool |
65f8144a | 4663 | gfc_check_stat (gfc_expr *name, gfc_expr *array) |
df65f093 | 4664 | { |
524af0d6 JB |
4665 | if (!type_check (name, 0, BT_CHARACTER)) |
4666 | return false; | |
4667 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
4668 | return false; | |
df65f093 | 4669 | |
524af0d6 JB |
4670 | if (!type_check (array, 1, BT_INTEGER) |
4671 | || !kind_value_check (array, 1, gfc_default_integer_kind)) | |
4672 | return false; | |
df65f093 | 4673 | |
524af0d6 JB |
4674 | if (!array_check (array, 1)) |
4675 | return false; | |
df65f093 | 4676 | |
524af0d6 | 4677 | return true; |
df65f093 SK |
4678 | } |
4679 | ||
4680 | ||
524af0d6 | 4681 | bool |
65f8144a | 4682 | gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status) |
df65f093 | 4683 | { |
524af0d6 JB |
4684 | if (!type_check (name, 0, BT_CHARACTER)) |
4685 | return false; | |
4686 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
4687 | return false; | |
df65f093 | 4688 | |
524af0d6 JB |
4689 | if (!type_check (array, 1, BT_INTEGER) |
4690 | || !kind_value_check (array, 1, gfc_default_integer_kind)) | |
4691 | return false; | |
df65f093 | 4692 | |
524af0d6 JB |
4693 | if (!array_check (array, 1)) |
4694 | return false; | |
df65f093 SK |
4695 | |
4696 | if (status == NULL) | |
524af0d6 | 4697 | return true; |
df65f093 | 4698 | |
524af0d6 JB |
4699 | if (!type_check (status, 2, BT_INTEGER) |
4700 | || !kind_value_check (array, 1, gfc_default_integer_kind)) | |
4701 | return false; | |
df65f093 | 4702 | |
524af0d6 JB |
4703 | if (!scalar_check (status, 2)) |
4704 | return false; | |
df65f093 | 4705 | |
524af0d6 | 4706 | return true; |
df65f093 SK |
4707 | } |
4708 | ||
4709 | ||
524af0d6 | 4710 | bool |
64f002ed TB |
4711 | gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub) |
4712 | { | |
e84b920c TB |
4713 | mpz_t nelems; |
4714 | ||
64f002ed TB |
4715 | if (gfc_option.coarray == GFC_FCOARRAY_NONE) |
4716 | { | |
4717 | gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable"); | |
524af0d6 | 4718 | return false; |
64f002ed TB |
4719 | } |
4720 | ||
524af0d6 JB |
4721 | if (!coarray_check (coarray, 0)) |
4722 | return false; | |
64f002ed TB |
4723 | |
4724 | if (sub->rank != 1) | |
4725 | { | |
4726 | gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L", | |
c4aa95f8 | 4727 | gfc_current_intrinsic_arg[1]->name, &sub->where); |
524af0d6 | 4728 | return false; |
64f002ed TB |
4729 | } |
4730 | ||
524af0d6 | 4731 | if (gfc_array_size (sub, &nelems)) |
e84b920c TB |
4732 | { |
4733 | int corank = gfc_get_corank (coarray); | |
4734 | ||
4735 | if (mpz_cmp_ui (nelems, corank) != 0) | |
4736 | { | |
4737 | gfc_error ("The number of array elements of the SUB argument to " | |
4738 | "IMAGE_INDEX at %L shall be %d (corank) not %d", | |
4739 | &sub->where, corank, (int) mpz_get_si (nelems)); | |
4740 | mpz_clear (nelems); | |
524af0d6 | 4741 | return false; |
e84b920c TB |
4742 | } |
4743 | mpz_clear (nelems); | |
4744 | } | |
4745 | ||
524af0d6 | 4746 | return true; |
64f002ed TB |
4747 | } |
4748 | ||
4749 | ||
524af0d6 | 4750 | bool |
05fc16dd | 4751 | gfc_check_num_images (gfc_expr *distance, gfc_expr *failed) |
64f002ed TB |
4752 | { |
4753 | if (gfc_option.coarray == GFC_FCOARRAY_NONE) | |
4754 | { | |
4755 | gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable"); | |
524af0d6 | 4756 | return false; |
64f002ed TB |
4757 | } |
4758 | ||
05fc16dd | 4759 | if (distance) |
64f002ed | 4760 | { |
05fc16dd TB |
4761 | if (!type_check (distance, 0, BT_INTEGER)) |
4762 | return false; | |
4763 | ||
4764 | if (!nonnegative_check ("DISTANCE", distance)) | |
4765 | return false; | |
4766 | ||
4767 | if (!scalar_check (distance, 0)) | |
4768 | return false; | |
4769 | ||
4770 | if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to " | |
4771 | "NUM_IMAGES at %L", &distance->where)) | |
4772 | return false; | |
4773 | } | |
4774 | ||
4775 | if (failed) | |
4776 | { | |
4777 | if (!type_check (failed, 1, BT_LOGICAL)) | |
4778 | return false; | |
4779 | ||
4780 | if (!scalar_check (failed, 1)) | |
4781 | return false; | |
4782 | ||
4783 | if (!gfc_notify_std (GFC_STD_F2008_TS, "FAILED= argument to " | |
4784 | "NUM_IMAGES at %L", &distance->where)) | |
4785 | return false; | |
4786 | } | |
4787 | ||
4788 | return true; | |
4789 | } | |
4790 | ||
4791 | ||
4792 | bool | |
4793 | gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim, gfc_expr *distance) | |
4794 | { | |
4795 | if (gfc_option.coarray == GFC_FCOARRAY_NONE) | |
4796 | { | |
4797 | gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable"); | |
524af0d6 | 4798 | return false; |
64f002ed TB |
4799 | } |
4800 | ||
05fc16dd | 4801 | if (coarray == NULL && dim == NULL && distance == NULL) |
524af0d6 | 4802 | return true; |
64f002ed | 4803 | |
05fc16dd TB |
4804 | if (dim != NULL && coarray == NULL) |
4805 | { | |
4806 | gfc_error ("DIM argument without COARRAY argument not allowed for " | |
4807 | "THIS_IMAGE intrinsic at %L", &dim->where); | |
4808 | return false; | |
4809 | } | |
4810 | ||
4811 | if (distance && (coarray || dim)) | |
4812 | { | |
4813 | gfc_error ("The DISTANCE argument may not be specified together with the " | |
4814 | "COARRAY or DIM argument in intrinsic at %L", | |
4815 | &distance->where); | |
4816 | return false; | |
4817 | } | |
4818 | ||
4819 | /* Assume that we have "this_image (distance)". */ | |
4820 | if (coarray && !gfc_is_coarray (coarray) && coarray->ts.type == BT_INTEGER) | |
4821 | { | |
4822 | if (dim) | |
4823 | { | |
4824 | gfc_error ("Unexpected DIM argument with noncoarray argument at %L", | |
4825 | &coarray->where); | |
4826 | return false; | |
4827 | } | |
4828 | distance = coarray; | |
4829 | } | |
4830 | ||
4831 | if (distance) | |
4832 | { | |
4833 | if (!type_check (distance, 2, BT_INTEGER)) | |
4834 | return false; | |
4835 | ||
4836 | if (!nonnegative_check ("DISTANCE", distance)) | |
4837 | return false; | |
4838 | ||
4839 | if (!scalar_check (distance, 2)) | |
4840 | return false; | |
4841 | ||
4842 | if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to " | |
4843 | "THIS_IMAGE at %L", &distance->where)) | |
4844 | return false; | |
4845 | ||
4846 | return true; | |
4847 | } | |
4848 | ||
524af0d6 JB |
4849 | if (!coarray_check (coarray, 0)) |
4850 | return false; | |
64f002ed TB |
4851 | |
4852 | if (dim != NULL) | |
4853 | { | |
524af0d6 JB |
4854 | if (!dim_check (dim, 1, false)) |
4855 | return false; | |
64f002ed | 4856 | |
524af0d6 JB |
4857 | if (!dim_corank_check (dim, coarray)) |
4858 | return false; | |
64f002ed TB |
4859 | } |
4860 | ||
524af0d6 | 4861 | return true; |
64f002ed TB |
4862 | } |
4863 | ||
86dbed7d | 4864 | /* Calculate the sizes for transfer, used by gfc_check_transfer and also |
524af0d6 | 4865 | by gfc_simplify_transfer. Return false if we cannot do so. */ |
64f002ed | 4866 | |
524af0d6 | 4867 | bool |
86dbed7d TK |
4868 | gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size, |
4869 | size_t *source_size, size_t *result_size, | |
4870 | size_t *result_length_p) | |
86dbed7d TK |
4871 | { |
4872 | size_t result_elt_size; | |
86dbed7d TK |
4873 | |
4874 | if (source->expr_type == EXPR_FUNCTION) | |
524af0d6 | 4875 | return false; |
86dbed7d | 4876 | |
9a575e05 | 4877 | if (size && size->expr_type != EXPR_CONSTANT) |
524af0d6 | 4878 | return false; |
9a575e05 TB |
4879 | |
4880 | /* Calculate the size of the source. */ | |
86dbed7d | 4881 | *source_size = gfc_target_expr_size (source); |
9a575e05 | 4882 | if (*source_size == 0) |
524af0d6 | 4883 | return false; |
86dbed7d | 4884 | |
86dbed7d | 4885 | /* Determine the size of the element. */ |
e361d18d | 4886 | result_elt_size = gfc_element_size (mold); |
86dbed7d | 4887 | if (result_elt_size == 0) |
524af0d6 | 4888 | return false; |
86dbed7d TK |
4889 | |
4890 | if (mold->expr_type == EXPR_ARRAY || mold->rank || size) | |
4891 | { | |
4892 | int result_length; | |
4893 | ||
4894 | if (size) | |
4895 | result_length = (size_t)mpz_get_ui (size->value.integer); | |
4896 | else | |
4897 | { | |
4898 | result_length = *source_size / result_elt_size; | |
4899 | if (result_length * result_elt_size < *source_size) | |
4900 | result_length += 1; | |
4901 | } | |
4902 | ||
4903 | *result_size = result_length * result_elt_size; | |
4904 | if (result_length_p) | |
4905 | *result_length_p = result_length; | |
4906 | } | |
4907 | else | |
4908 | *result_size = result_elt_size; | |
4909 | ||
524af0d6 | 4910 | return true; |
86dbed7d TK |
4911 | } |
4912 | ||
4913 | ||
524af0d6 | 4914 | bool |
86dbed7d | 4915 | gfc_check_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size) |
6de9cd9a | 4916 | { |
86dbed7d TK |
4917 | size_t source_size; |
4918 | size_t result_size; | |
4919 | ||
3b45d6c4 BM |
4920 | if (mold->ts.type == BT_HOLLERITH) |
4921 | { | |
4922 | gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s", | |
4923 | &mold->where, gfc_basic_typename (BT_HOLLERITH)); | |
524af0d6 | 4924 | return false; |
3b45d6c4 BM |
4925 | } |
4926 | ||
6de9cd9a DN |
4927 | if (size != NULL) |
4928 | { | |
524af0d6 JB |
4929 | if (!type_check (size, 2, BT_INTEGER)) |
4930 | return false; | |
6de9cd9a | 4931 | |
524af0d6 JB |
4932 | if (!scalar_check (size, 2)) |
4933 | return false; | |
6de9cd9a | 4934 | |
524af0d6 JB |
4935 | if (!nonoptional_check (size, 2)) |
4936 | return false; | |
6de9cd9a DN |
4937 | } |
4938 | ||
86dbed7d | 4939 | if (!gfc_option.warn_surprising) |
524af0d6 | 4940 | return true; |
86dbed7d TK |
4941 | |
4942 | /* If we can't calculate the sizes, we cannot check any more. | |
524af0d6 | 4943 | Return true for that case. */ |
86dbed7d | 4944 | |
524af0d6 JB |
4945 | if (!gfc_calculate_transfer_sizes (source, mold, size, &source_size, |
4946 | &result_size, NULL)) | |
4947 | return true; | |
86dbed7d TK |
4948 | |
4949 | if (source_size < result_size) | |
4950 | gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: " | |
4951 | "source size %ld < result size %ld", &source->where, | |
4952 | (long) source_size, (long) result_size); | |
4953 | ||
524af0d6 | 4954 | return true; |
6de9cd9a DN |
4955 | } |
4956 | ||
4957 | ||
524af0d6 | 4958 | bool |
65f8144a | 4959 | gfc_check_transpose (gfc_expr *matrix) |
6de9cd9a | 4960 | { |
524af0d6 JB |
4961 | if (!rank_check (matrix, 0, 2)) |
4962 | return false; | |
6de9cd9a | 4963 | |
524af0d6 | 4964 | return true; |
6de9cd9a DN |
4965 | } |
4966 | ||
4967 | ||
524af0d6 | 4968 | bool |
5cda5098 | 4969 | gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
6de9cd9a | 4970 | { |
524af0d6 JB |
4971 | if (!array_check (array, 0)) |
4972 | return false; | |
6de9cd9a | 4973 | |
524af0d6 JB |
4974 | if (!dim_check (dim, 1, false)) |
4975 | return false; | |
6de9cd9a | 4976 | |
524af0d6 JB |
4977 | if (!dim_rank_check (dim, array, 0)) |
4978 | return false; | |
27dfc9c4 | 4979 | |
524af0d6 JB |
4980 | if (!kind_check (kind, 2, BT_INTEGER)) |
4981 | return false; | |
4982 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
4983 | "with KIND argument at %L", | |
4984 | gfc_current_intrinsic, &kind->where)) | |
4985 | return false; | |
64f002ed | 4986 | |
524af0d6 | 4987 | return true; |
64f002ed TB |
4988 | } |
4989 | ||
4990 | ||
524af0d6 | 4991 | bool |
64f002ed TB |
4992 | gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind) |
4993 | { | |
4994 | if (gfc_option.coarray == GFC_FCOARRAY_NONE) | |
4995 | { | |
4996 | gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable"); | |
524af0d6 | 4997 | return false; |
64f002ed TB |
4998 | } |
4999 | ||
524af0d6 JB |
5000 | if (!coarray_check (coarray, 0)) |
5001 | return false; | |
64f002ed TB |
5002 | |
5003 | if (dim != NULL) | |
5004 | { | |
524af0d6 JB |
5005 | if (!dim_check (dim, 1, false)) |
5006 | return false; | |
64f002ed | 5007 | |
524af0d6 JB |
5008 | if (!dim_corank_check (dim, coarray)) |
5009 | return false; | |
64f002ed TB |
5010 | } |
5011 | ||
524af0d6 JB |
5012 | if (!kind_check (kind, 2, BT_INTEGER)) |
5013 | return false; | |
5cda5098 | 5014 | |
524af0d6 | 5015 | return true; |
6de9cd9a DN |
5016 | } |
5017 | ||
5018 | ||
524af0d6 | 5019 | bool |
65f8144a | 5020 | gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field) |
6de9cd9a | 5021 | { |
c430a6f9 DF |
5022 | mpz_t vector_size; |
5023 | ||
524af0d6 JB |
5024 | if (!rank_check (vector, 0, 1)) |
5025 | return false; | |
6de9cd9a | 5026 | |
524af0d6 JB |
5027 | if (!array_check (mask, 1)) |
5028 | return false; | |
6de9cd9a | 5029 | |
524af0d6 JB |
5030 | if (!type_check (mask, 1, BT_LOGICAL)) |
5031 | return false; | |
6de9cd9a | 5032 | |
524af0d6 JB |
5033 | if (!same_type_check (vector, 0, field, 2)) |
5034 | return false; | |
6de9cd9a | 5035 | |
c430a6f9 | 5036 | if (mask->expr_type == EXPR_ARRAY |
524af0d6 | 5037 | && gfc_array_size (vector, &vector_size)) |
c430a6f9 DF |
5038 | { |
5039 | int mask_true_count = 0; | |
b7e75771 JD |
5040 | gfc_constructor *mask_ctor; |
5041 | mask_ctor = gfc_constructor_first (mask->value.constructor); | |
c430a6f9 DF |
5042 | while (mask_ctor) |
5043 | { | |
5044 | if (mask_ctor->expr->expr_type != EXPR_CONSTANT) | |
5045 | { | |
5046 | mask_true_count = 0; | |
5047 | break; | |
5048 | } | |
5049 | ||
5050 | if (mask_ctor->expr->value.logical) | |
5051 | mask_true_count++; | |
5052 | ||
b7e75771 | 5053 | mask_ctor = gfc_constructor_next (mask_ctor); |
c430a6f9 DF |
5054 | } |
5055 | ||
5056 | if (mpz_get_si (vector_size) < mask_true_count) | |
5057 | { | |
5058 | gfc_error ("'%s' argument of '%s' intrinsic at %L must " | |
5059 | "provide at least as many elements as there " | |
5060 | "are .TRUE. values in '%s' (%ld/%d)", | |
c4aa95f8 JW |
5061 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, |
5062 | &vector->where, gfc_current_intrinsic_arg[1]->name, | |
c430a6f9 | 5063 | mpz_get_si (vector_size), mask_true_count); |
524af0d6 | 5064 | return false; |
c430a6f9 DF |
5065 | } |
5066 | ||
5067 | mpz_clear (vector_size); | |
5068 | } | |
5069 | ||
d1a296c1 TB |
5070 | if (mask->rank != field->rank && field->rank != 0) |
5071 | { | |
c430a6f9 | 5072 | gfc_error ("'%s' argument of '%s' intrinsic at %L must have " |
8b704316 | 5073 | "the same rank as '%s' or be a scalar", |
c4aa95f8 JW |
5074 | gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic, |
5075 | &field->where, gfc_current_intrinsic_arg[1]->name); | |
524af0d6 | 5076 | return false; |
d1a296c1 TB |
5077 | } |
5078 | ||
5079 | if (mask->rank == field->rank) | |
5080 | { | |
5081 | int i; | |
5082 | for (i = 0; i < field->rank; i++) | |
5083 | if (! identical_dimen_shape (mask, i, field, i)) | |
5084 | { | |
c430a6f9 | 5085 | gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L " |
8b704316 | 5086 | "must have identical shape.", |
c4aa95f8 JW |
5087 | gfc_current_intrinsic_arg[2]->name, |
5088 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
c430a6f9 | 5089 | &field->where); |
d1a296c1 TB |
5090 | } |
5091 | } | |
5092 | ||
524af0d6 | 5093 | return true; |
6de9cd9a DN |
5094 | } |
5095 | ||
5096 | ||
524af0d6 | 5097 | bool |
5cda5098 | 5098 | gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind) |
6de9cd9a | 5099 | { |
524af0d6 JB |
5100 | if (!type_check (x, 0, BT_CHARACTER)) |
5101 | return false; | |
6de9cd9a | 5102 | |
524af0d6 JB |
5103 | if (!same_type_check (x, 0, y, 1)) |
5104 | return false; | |
6de9cd9a | 5105 | |
524af0d6 JB |
5106 | if (z != NULL && !type_check (z, 2, BT_LOGICAL)) |
5107 | return false; | |
6de9cd9a | 5108 | |
524af0d6 JB |
5109 | if (!kind_check (kind, 3, BT_INTEGER)) |
5110 | return false; | |
5111 | if (kind && !gfc_notify_std (GFC_STD_F2003, "'%s' intrinsic " | |
5112 | "with KIND argument at %L", | |
5113 | gfc_current_intrinsic, &kind->where)) | |
5114 | return false; | |
5cda5098 | 5115 | |
524af0d6 | 5116 | return true; |
6de9cd9a DN |
5117 | } |
5118 | ||
5119 | ||
524af0d6 | 5120 | bool |
65f8144a | 5121 | gfc_check_trim (gfc_expr *x) |
6de9cd9a | 5122 | { |
524af0d6 JB |
5123 | if (!type_check (x, 0, BT_CHARACTER)) |
5124 | return false; | |
6de9cd9a | 5125 | |
524af0d6 JB |
5126 | if (!scalar_check (x, 0)) |
5127 | return false; | |
6de9cd9a | 5128 | |
524af0d6 | 5129 | return true; |
6de9cd9a DN |
5130 | } |
5131 | ||
5132 | ||
524af0d6 | 5133 | bool |
65f8144a | 5134 | gfc_check_ttynam (gfc_expr *unit) |
25fc05eb | 5135 | { |
524af0d6 JB |
5136 | if (!scalar_check (unit, 0)) |
5137 | return false; | |
25fc05eb | 5138 | |
524af0d6 JB |
5139 | if (!type_check (unit, 0, BT_INTEGER)) |
5140 | return false; | |
25fc05eb | 5141 | |
524af0d6 | 5142 | return true; |
25fc05eb FXC |
5143 | } |
5144 | ||
5145 | ||
6de9cd9a DN |
5146 | /* Common check function for the half a dozen intrinsics that have a |
5147 | single real argument. */ | |
5148 | ||
524af0d6 | 5149 | bool |
65f8144a | 5150 | gfc_check_x (gfc_expr *x) |
6de9cd9a | 5151 | { |
524af0d6 JB |
5152 | if (!type_check (x, 0, BT_REAL)) |
5153 | return false; | |
6de9cd9a | 5154 | |
524af0d6 | 5155 | return true; |
6de9cd9a DN |
5156 | } |
5157 | ||
5158 | ||
5159 | /************* Check functions for intrinsic subroutines *************/ | |
5160 | ||
524af0d6 | 5161 | bool |
65f8144a | 5162 | gfc_check_cpu_time (gfc_expr *time) |
6de9cd9a | 5163 | { |
524af0d6 JB |
5164 | if (!scalar_check (time, 0)) |
5165 | return false; | |
6de9cd9a | 5166 | |
524af0d6 JB |
5167 | if (!type_check (time, 0, BT_REAL)) |
5168 | return false; | |
6de9cd9a | 5169 | |
524af0d6 JB |
5170 | if (!variable_check (time, 0, false)) |
5171 | return false; | |
6de9cd9a | 5172 | |
524af0d6 | 5173 | return true; |
6de9cd9a DN |
5174 | } |
5175 | ||
5176 | ||
524af0d6 | 5177 | bool |
65f8144a SK |
5178 | gfc_check_date_and_time (gfc_expr *date, gfc_expr *time, |
5179 | gfc_expr *zone, gfc_expr *values) | |
6de9cd9a | 5180 | { |
6de9cd9a DN |
5181 | if (date != NULL) |
5182 | { | |
524af0d6 JB |
5183 | if (!type_check (date, 0, BT_CHARACTER)) |
5184 | return false; | |
5185 | if (!kind_value_check (date, 0, gfc_default_character_kind)) | |
5186 | return false; | |
5187 | if (!scalar_check (date, 0)) | |
5188 | return false; | |
5189 | if (!variable_check (date, 0, false)) | |
5190 | return false; | |
6de9cd9a DN |
5191 | } |
5192 | ||
5193 | if (time != NULL) | |
5194 | { | |
524af0d6 JB |
5195 | if (!type_check (time, 1, BT_CHARACTER)) |
5196 | return false; | |
5197 | if (!kind_value_check (time, 1, gfc_default_character_kind)) | |
5198 | return false; | |
5199 | if (!scalar_check (time, 1)) | |
5200 | return false; | |
5201 | if (!variable_check (time, 1, false)) | |
5202 | return false; | |
6de9cd9a DN |
5203 | } |
5204 | ||
5205 | if (zone != NULL) | |
5206 | { | |
524af0d6 JB |
5207 | if (!type_check (zone, 2, BT_CHARACTER)) |
5208 | return false; | |
5209 | if (!kind_value_check (zone, 2, gfc_default_character_kind)) | |
5210 | return false; | |
5211 | if (!scalar_check (zone, 2)) | |
5212 | return false; | |
5213 | if (!variable_check (zone, 2, false)) | |
5214 | return false; | |
6de9cd9a DN |
5215 | } |
5216 | ||
5217 | if (values != NULL) | |
5218 | { | |
524af0d6 JB |
5219 | if (!type_check (values, 3, BT_INTEGER)) |
5220 | return false; | |
5221 | if (!array_check (values, 3)) | |
5222 | return false; | |
5223 | if (!rank_check (values, 3, 1)) | |
5224 | return false; | |
5225 | if (!variable_check (values, 3, false)) | |
5226 | return false; | |
6de9cd9a DN |
5227 | } |
5228 | ||
524af0d6 | 5229 | return true; |
6de9cd9a DN |
5230 | } |
5231 | ||
5232 | ||
524af0d6 | 5233 | bool |
65f8144a SK |
5234 | gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len, |
5235 | gfc_expr *to, gfc_expr *topos) | |
6de9cd9a | 5236 | { |
524af0d6 JB |
5237 | if (!type_check (from, 0, BT_INTEGER)) |
5238 | return false; | |
6de9cd9a | 5239 | |
524af0d6 JB |
5240 | if (!type_check (frompos, 1, BT_INTEGER)) |
5241 | return false; | |
6de9cd9a | 5242 | |
524af0d6 JB |
5243 | if (!type_check (len, 2, BT_INTEGER)) |
5244 | return false; | |
6de9cd9a | 5245 | |
524af0d6 JB |
5246 | if (!same_type_check (from, 0, to, 3)) |
5247 | return false; | |
6de9cd9a | 5248 | |
524af0d6 JB |
5249 | if (!variable_check (to, 3, false)) |
5250 | return false; | |
6de9cd9a | 5251 | |
524af0d6 JB |
5252 | if (!type_check (topos, 4, BT_INTEGER)) |
5253 | return false; | |
6de9cd9a | 5254 | |
524af0d6 JB |
5255 | if (!nonnegative_check ("frompos", frompos)) |
5256 | return false; | |
289e52fd | 5257 | |
524af0d6 JB |
5258 | if (!nonnegative_check ("topos", topos)) |
5259 | return false; | |
289e52fd | 5260 | |
524af0d6 JB |
5261 | if (!nonnegative_check ("len", len)) |
5262 | return false; | |
289e52fd | 5263 | |
524af0d6 JB |
5264 | if (!less_than_bitsize2 ("from", from, "frompos", frompos, "len", len)) |
5265 | return false; | |
289e52fd | 5266 | |
524af0d6 JB |
5267 | if (!less_than_bitsize2 ("to", to, "topos", topos, "len", len)) |
5268 | return false; | |
289e52fd | 5269 | |
524af0d6 | 5270 | return true; |
6de9cd9a DN |
5271 | } |
5272 | ||
5273 | ||
524af0d6 | 5274 | bool |
65f8144a | 5275 | gfc_check_random_number (gfc_expr *harvest) |
6de9cd9a | 5276 | { |
524af0d6 JB |
5277 | if (!type_check (harvest, 0, BT_REAL)) |
5278 | return false; | |
6de9cd9a | 5279 | |
524af0d6 JB |
5280 | if (!variable_check (harvest, 0, false)) |
5281 | return false; | |
6de9cd9a | 5282 | |
524af0d6 | 5283 | return true; |
6de9cd9a DN |
5284 | } |
5285 | ||
5286 | ||
524af0d6 | 5287 | bool |
65f8144a | 5288 | gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get) |
6de9cd9a | 5289 | { |
1b867ae7 | 5290 | unsigned int nargs = 0, kiss_size; |
34b4bc5c | 5291 | locus *where = NULL; |
b55c4f04 | 5292 | mpz_t put_size, get_size; |
1b867ae7 | 5293 | bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */ |
34b4bc5c | 5294 | |
1b867ae7 DW |
5295 | have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1; |
5296 | ||
b55c4f04 DF |
5297 | /* Keep the number of bytes in sync with kiss_size in |
5298 | libgfortran/intrinsics/random.c. */ | |
5299 | kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind; | |
5300 | ||
6de9cd9a DN |
5301 | if (size != NULL) |
5302 | { | |
34b4bc5c FXC |
5303 | if (size->expr_type != EXPR_VARIABLE |
5304 | || !size->symtree->n.sym->attr.optional) | |
5305 | nargs++; | |
5306 | ||
524af0d6 JB |
5307 | if (!scalar_check (size, 0)) |
5308 | return false; | |
6de9cd9a | 5309 | |
524af0d6 JB |
5310 | if (!type_check (size, 0, BT_INTEGER)) |
5311 | return false; | |
6de9cd9a | 5312 | |
524af0d6 JB |
5313 | if (!variable_check (size, 0, false)) |
5314 | return false; | |
6de9cd9a | 5315 | |
524af0d6 JB |
5316 | if (!kind_value_check (size, 0, gfc_default_integer_kind)) |
5317 | return false; | |
6de9cd9a DN |
5318 | } |
5319 | ||
5320 | if (put != NULL) | |
5321 | { | |
34b4bc5c FXC |
5322 | if (put->expr_type != EXPR_VARIABLE |
5323 | || !put->symtree->n.sym->attr.optional) | |
5324 | { | |
5325 | nargs++; | |
5326 | where = &put->where; | |
5327 | } | |
95d3f567 | 5328 | |
524af0d6 JB |
5329 | if (!array_check (put, 1)) |
5330 | return false; | |
95d3f567 | 5331 | |
524af0d6 JB |
5332 | if (!rank_check (put, 1, 1)) |
5333 | return false; | |
6de9cd9a | 5334 | |
524af0d6 JB |
5335 | if (!type_check (put, 1, BT_INTEGER)) |
5336 | return false; | |
6de9cd9a | 5337 | |
524af0d6 JB |
5338 | if (!kind_value_check (put, 1, gfc_default_integer_kind)) |
5339 | return false; | |
1b867ae7 | 5340 | |
524af0d6 | 5341 | if (gfc_array_size (put, &put_size) |
1b867ae7 | 5342 | && mpz_get_ui (put_size) < kiss_size) |
b55c4f04 DF |
5343 | gfc_error ("Size of '%s' argument of '%s' intrinsic at %L " |
5344 | "too small (%i/%i)", | |
c4aa95f8 JW |
5345 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, |
5346 | where, (int) mpz_get_ui (put_size), kiss_size); | |
6de9cd9a DN |
5347 | } |
5348 | ||
5349 | if (get != NULL) | |
5350 | { | |
34b4bc5c FXC |
5351 | if (get->expr_type != EXPR_VARIABLE |
5352 | || !get->symtree->n.sym->attr.optional) | |
5353 | { | |
5354 | nargs++; | |
5355 | where = &get->where; | |
5356 | } | |
95d3f567 | 5357 | |
524af0d6 JB |
5358 | if (!array_check (get, 2)) |
5359 | return false; | |
95d3f567 | 5360 | |
524af0d6 JB |
5361 | if (!rank_check (get, 2, 1)) |
5362 | return false; | |
6de9cd9a | 5363 | |
524af0d6 JB |
5364 | if (!type_check (get, 2, BT_INTEGER)) |
5365 | return false; | |
6de9cd9a | 5366 | |
524af0d6 JB |
5367 | if (!variable_check (get, 2, false)) |
5368 | return false; | |
6de9cd9a | 5369 | |
524af0d6 JB |
5370 | if (!kind_value_check (get, 2, gfc_default_integer_kind)) |
5371 | return false; | |
b55c4f04 | 5372 | |
524af0d6 | 5373 | if (gfc_array_size (get, &get_size) |
b55c4f04 DF |
5374 | && mpz_get_ui (get_size) < kiss_size) |
5375 | gfc_error ("Size of '%s' argument of '%s' intrinsic at %L " | |
5376 | "too small (%i/%i)", | |
c4aa95f8 JW |
5377 | gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic, |
5378 | where, (int) mpz_get_ui (get_size), kiss_size); | |
6de9cd9a DN |
5379 | } |
5380 | ||
34b4bc5c FXC |
5381 | /* RANDOM_SEED may not have more than one non-optional argument. */ |
5382 | if (nargs > 1) | |
5383 | gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where); | |
5384 | ||
524af0d6 | 5385 | return true; |
6de9cd9a | 5386 | } |
21fdfcc1 | 5387 | |
65f8144a | 5388 | |
524af0d6 | 5389 | bool |
65f8144a | 5390 | gfc_check_second_sub (gfc_expr *time) |
2bd74949 | 5391 | { |
524af0d6 JB |
5392 | if (!scalar_check (time, 0)) |
5393 | return false; | |
2bd74949 | 5394 | |
524af0d6 JB |
5395 | if (!type_check (time, 0, BT_REAL)) |
5396 | return false; | |
2bd74949 | 5397 | |
524af0d6 JB |
5398 | if (!kind_value_check (time, 0, 4)) |
5399 | return false; | |
2bd74949 | 5400 | |
524af0d6 | 5401 | return true; |
2bd74949 SK |
5402 | } |
5403 | ||
5404 | ||
a416c4c7 FXC |
5405 | /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer |
5406 | variables in Fortran 95. In Fortran 2003 and later, they can be of any | |
5407 | kind, and COUNT_RATE can be of type real. Note, count, count_rate, and | |
5408 | count_max are all optional arguments */ | |
21fdfcc1 | 5409 | |
524af0d6 | 5410 | bool |
65f8144a SK |
5411 | gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate, |
5412 | gfc_expr *count_max) | |
21fdfcc1 | 5413 | { |
21fdfcc1 SK |
5414 | if (count != NULL) |
5415 | { | |
524af0d6 JB |
5416 | if (!scalar_check (count, 0)) |
5417 | return false; | |
21fdfcc1 | 5418 | |
524af0d6 JB |
5419 | if (!type_check (count, 0, BT_INTEGER)) |
5420 | return false; | |
21fdfcc1 | 5421 | |
a416c4c7 FXC |
5422 | if (count->ts.kind != gfc_default_integer_kind |
5423 | && !gfc_notify_std (GFC_STD_F2003, "COUNT argument to " | |
5424 | "SYSTEM_CLOCK at %L has non-default kind", | |
5425 | &count->where)) | |
5426 | return false; | |
5427 | ||
524af0d6 JB |
5428 | if (!variable_check (count, 0, false)) |
5429 | return false; | |
21fdfcc1 SK |
5430 | } |
5431 | ||
5432 | if (count_rate != NULL) | |
5433 | { | |
524af0d6 JB |
5434 | if (!scalar_check (count_rate, 1)) |
5435 | return false; | |
21fdfcc1 | 5436 | |
524af0d6 JB |
5437 | if (!variable_check (count_rate, 1, false)) |
5438 | return false; | |
21fdfcc1 | 5439 | |
a416c4c7 FXC |
5440 | if (count_rate->ts.type == BT_REAL) |
5441 | { | |
5442 | if (!gfc_notify_std (GFC_STD_F2003, "Real COUNT_RATE argument to " | |
5443 | "SYSTEM_CLOCK at %L", &count_rate->where)) | |
5444 | return false; | |
5445 | } | |
5446 | else | |
5447 | { | |
5448 | if (!type_check (count_rate, 1, BT_INTEGER)) | |
5449 | return false; | |
5450 | ||
5451 | if (count_rate->ts.kind != gfc_default_integer_kind | |
5452 | && !gfc_notify_std (GFC_STD_F2003, "COUNT_RATE argument to " | |
5453 | "SYSTEM_CLOCK at %L has non-default kind", | |
5454 | &count_rate->where)) | |
5455 | return false; | |
5456 | } | |
21fdfcc1 SK |
5457 | |
5458 | } | |
5459 | ||
5460 | if (count_max != NULL) | |
5461 | { | |
524af0d6 JB |
5462 | if (!scalar_check (count_max, 2)) |
5463 | return false; | |
21fdfcc1 | 5464 | |
524af0d6 JB |
5465 | if (!type_check (count_max, 2, BT_INTEGER)) |
5466 | return false; | |
21fdfcc1 | 5467 | |
a416c4c7 FXC |
5468 | if (count_max->ts.kind != gfc_default_integer_kind |
5469 | && !gfc_notify_std (GFC_STD_F2003, "COUNT_MAX argument to " | |
5470 | "SYSTEM_CLOCK at %L has non-default kind", | |
5471 | &count_max->where)) | |
524af0d6 | 5472 | return false; |
21fdfcc1 | 5473 | |
a416c4c7 | 5474 | if (!variable_check (count_max, 2, false)) |
524af0d6 | 5475 | return false; |
27dfc9c4 | 5476 | } |
21fdfcc1 | 5477 | |
524af0d6 | 5478 | return true; |
21fdfcc1 | 5479 | } |
2bd74949 | 5480 | |
65f8144a | 5481 | |
524af0d6 | 5482 | bool |
65f8144a | 5483 | gfc_check_irand (gfc_expr *x) |
2bd74949 | 5484 | { |
7a003d8e | 5485 | if (x == NULL) |
524af0d6 | 5486 | return true; |
7a003d8e | 5487 | |
524af0d6 JB |
5488 | if (!scalar_check (x, 0)) |
5489 | return false; | |
2bd74949 | 5490 | |
524af0d6 JB |
5491 | if (!type_check (x, 0, BT_INTEGER)) |
5492 | return false; | |
2bd74949 | 5493 | |
524af0d6 JB |
5494 | if (!kind_value_check (x, 0, 4)) |
5495 | return false; | |
2bd74949 | 5496 | |
524af0d6 | 5497 | return true; |
2bd74949 SK |
5498 | } |
5499 | ||
185d7d97 | 5500 | |
524af0d6 | 5501 | bool |
65f8144a | 5502 | gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status) |
185d7d97 | 5503 | { |
524af0d6 JB |
5504 | if (!scalar_check (seconds, 0)) |
5505 | return false; | |
5506 | if (!type_check (seconds, 0, BT_INTEGER)) | |
5507 | return false; | |
185d7d97 | 5508 | |
524af0d6 JB |
5509 | if (!int_or_proc_check (handler, 1)) |
5510 | return false; | |
5511 | if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1)) | |
5512 | return false; | |
185d7d97 FXC |
5513 | |
5514 | if (status == NULL) | |
524af0d6 | 5515 | return true; |
185d7d97 | 5516 | |
524af0d6 JB |
5517 | if (!scalar_check (status, 2)) |
5518 | return false; | |
5519 | if (!type_check (status, 2, BT_INTEGER)) | |
5520 | return false; | |
5521 | if (!kind_value_check (status, 2, gfc_default_integer_kind)) | |
5522 | return false; | |
32af3784 | 5523 | |
524af0d6 | 5524 | return true; |
185d7d97 FXC |
5525 | } |
5526 | ||
5527 | ||
524af0d6 | 5528 | bool |
65f8144a | 5529 | gfc_check_rand (gfc_expr *x) |
2bd74949 | 5530 | { |
7a003d8e | 5531 | if (x == NULL) |
524af0d6 | 5532 | return true; |
7a003d8e | 5533 | |
524af0d6 JB |
5534 | if (!scalar_check (x, 0)) |
5535 | return false; | |
2bd74949 | 5536 | |
524af0d6 JB |
5537 | if (!type_check (x, 0, BT_INTEGER)) |
5538 | return false; | |
2bd74949 | 5539 | |
524af0d6 JB |
5540 | if (!kind_value_check (x, 0, 4)) |
5541 | return false; | |
2bd74949 | 5542 | |
524af0d6 | 5543 | return true; |
2bd74949 SK |
5544 | } |
5545 | ||
65f8144a | 5546 | |
524af0d6 | 5547 | bool |
65f8144a | 5548 | gfc_check_srand (gfc_expr *x) |
2bd74949 | 5549 | { |
524af0d6 JB |
5550 | if (!scalar_check (x, 0)) |
5551 | return false; | |
2bd74949 | 5552 | |
524af0d6 JB |
5553 | if (!type_check (x, 0, BT_INTEGER)) |
5554 | return false; | |
2bd74949 | 5555 | |
524af0d6 JB |
5556 | if (!kind_value_check (x, 0, 4)) |
5557 | return false; | |
2bd74949 | 5558 | |
524af0d6 | 5559 | return true; |
2bd74949 SK |
5560 | } |
5561 | ||
65f8144a | 5562 | |
524af0d6 | 5563 | bool |
65f8144a | 5564 | gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result) |
35059811 | 5565 | { |
524af0d6 JB |
5566 | if (!scalar_check (time, 0)) |
5567 | return false; | |
5568 | if (!type_check (time, 0, BT_INTEGER)) | |
5569 | return false; | |
35059811 | 5570 | |
524af0d6 JB |
5571 | if (!type_check (result, 1, BT_CHARACTER)) |
5572 | return false; | |
5573 | if (!kind_value_check (result, 1, gfc_default_character_kind)) | |
5574 | return false; | |
35059811 | 5575 | |
524af0d6 | 5576 | return true; |
35059811 FXC |
5577 | } |
5578 | ||
65f8144a | 5579 | |
524af0d6 | 5580 | bool |
a1ba31ce | 5581 | gfc_check_dtime_etime (gfc_expr *x) |
2bd74949 | 5582 | { |
524af0d6 JB |
5583 | if (!array_check (x, 0)) |
5584 | return false; | |
2bd74949 | 5585 | |
524af0d6 JB |
5586 | if (!rank_check (x, 0, 1)) |
5587 | return false; | |
2bd74949 | 5588 | |
524af0d6 JB |
5589 | if (!variable_check (x, 0, false)) |
5590 | return false; | |
2bd74949 | 5591 | |
524af0d6 JB |
5592 | if (!type_check (x, 0, BT_REAL)) |
5593 | return false; | |
2bd74949 | 5594 | |
524af0d6 JB |
5595 | if (!kind_value_check (x, 0, 4)) |
5596 | return false; | |
2bd74949 | 5597 | |
524af0d6 | 5598 | return true; |
2bd74949 SK |
5599 | } |
5600 | ||
65f8144a | 5601 | |
524af0d6 | 5602 | bool |
a1ba31ce | 5603 | gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time) |
2bd74949 | 5604 | { |
524af0d6 JB |
5605 | if (!array_check (values, 0)) |
5606 | return false; | |
2bd74949 | 5607 | |
524af0d6 JB |
5608 | if (!rank_check (values, 0, 1)) |
5609 | return false; | |
2bd74949 | 5610 | |
524af0d6 JB |
5611 | if (!variable_check (values, 0, false)) |
5612 | return false; | |
2bd74949 | 5613 | |
524af0d6 JB |
5614 | if (!type_check (values, 0, BT_REAL)) |
5615 | return false; | |
2bd74949 | 5616 | |
524af0d6 JB |
5617 | if (!kind_value_check (values, 0, 4)) |
5618 | return false; | |
2bd74949 | 5619 | |
524af0d6 JB |
5620 | if (!scalar_check (time, 1)) |
5621 | return false; | |
2bd74949 | 5622 | |
524af0d6 JB |
5623 | if (!type_check (time, 1, BT_REAL)) |
5624 | return false; | |
2bd74949 | 5625 | |
524af0d6 JB |
5626 | if (!kind_value_check (time, 1, 4)) |
5627 | return false; | |
2bd74949 | 5628 | |
524af0d6 | 5629 | return true; |
2bd74949 | 5630 | } |
a8c60d7f SK |
5631 | |
5632 | ||
524af0d6 | 5633 | bool |
65f8144a | 5634 | gfc_check_fdate_sub (gfc_expr *date) |
35059811 | 5635 | { |
524af0d6 JB |
5636 | if (!type_check (date, 0, BT_CHARACTER)) |
5637 | return false; | |
5638 | if (!kind_value_check (date, 0, gfc_default_character_kind)) | |
5639 | return false; | |
35059811 | 5640 | |
524af0d6 | 5641 | return true; |
35059811 FXC |
5642 | } |
5643 | ||
5644 | ||
524af0d6 | 5645 | bool |
65f8144a | 5646 | gfc_check_gerror (gfc_expr *msg) |
f77b6ca3 | 5647 | { |
524af0d6 JB |
5648 | if (!type_check (msg, 0, BT_CHARACTER)) |
5649 | return false; | |
5650 | if (!kind_value_check (msg, 0, gfc_default_character_kind)) | |
5651 | return false; | |
f77b6ca3 | 5652 | |
524af0d6 | 5653 | return true; |
f77b6ca3 FXC |
5654 | } |
5655 | ||
5656 | ||
524af0d6 | 5657 | bool |
65f8144a | 5658 | gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status) |
a8c60d7f | 5659 | { |
524af0d6 JB |
5660 | if (!type_check (cwd, 0, BT_CHARACTER)) |
5661 | return false; | |
5662 | if (!kind_value_check (cwd, 0, gfc_default_character_kind)) | |
5663 | return false; | |
a8c60d7f | 5664 | |
d8fe26b2 | 5665 | if (status == NULL) |
524af0d6 | 5666 | return true; |
d8fe26b2 | 5667 | |
524af0d6 JB |
5668 | if (!scalar_check (status, 1)) |
5669 | return false; | |
d8fe26b2 | 5670 | |
524af0d6 JB |
5671 | if (!type_check (status, 1, BT_INTEGER)) |
5672 | return false; | |
d8fe26b2 | 5673 | |
524af0d6 | 5674 | return true; |
d8fe26b2 SK |
5675 | } |
5676 | ||
5677 | ||
524af0d6 | 5678 | bool |
ed8315d5 FXC |
5679 | gfc_check_getarg (gfc_expr *pos, gfc_expr *value) |
5680 | { | |
524af0d6 JB |
5681 | if (!type_check (pos, 0, BT_INTEGER)) |
5682 | return false; | |
ed8315d5 FXC |
5683 | |
5684 | if (pos->ts.kind > gfc_default_integer_kind) | |
5685 | { | |
5686 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind " | |
5687 | "not wider than the default kind (%d)", | |
c4aa95f8 | 5688 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, |
ed8315d5 | 5689 | &pos->where, gfc_default_integer_kind); |
524af0d6 | 5690 | return false; |
ed8315d5 FXC |
5691 | } |
5692 | ||
524af0d6 JB |
5693 | if (!type_check (value, 1, BT_CHARACTER)) |
5694 | return false; | |
5695 | if (!kind_value_check (value, 1, gfc_default_character_kind)) | |
5696 | return false; | |
ed8315d5 | 5697 | |
524af0d6 | 5698 | return true; |
ed8315d5 FXC |
5699 | } |
5700 | ||
5701 | ||
524af0d6 | 5702 | bool |
65f8144a | 5703 | gfc_check_getlog (gfc_expr *msg) |
f77b6ca3 | 5704 | { |
524af0d6 JB |
5705 | if (!type_check (msg, 0, BT_CHARACTER)) |
5706 | return false; | |
5707 | if (!kind_value_check (msg, 0, gfc_default_character_kind)) | |
5708 | return false; | |
f77b6ca3 | 5709 | |
524af0d6 | 5710 | return true; |
f77b6ca3 FXC |
5711 | } |
5712 | ||
5713 | ||
524af0d6 | 5714 | bool |
65f8144a | 5715 | gfc_check_exit (gfc_expr *status) |
d8fe26b2 | 5716 | { |
d8fe26b2 | 5717 | if (status == NULL) |
524af0d6 | 5718 | return true; |
d8fe26b2 | 5719 | |
524af0d6 JB |
5720 | if (!type_check (status, 0, BT_INTEGER)) |
5721 | return false; | |
d8fe26b2 | 5722 | |
524af0d6 JB |
5723 | if (!scalar_check (status, 0)) |
5724 | return false; | |
d8fe26b2 | 5725 | |
524af0d6 | 5726 | return true; |
d8fe26b2 SK |
5727 | } |
5728 | ||
5729 | ||
524af0d6 | 5730 | bool |
65f8144a | 5731 | gfc_check_flush (gfc_expr *unit) |
df65f093 | 5732 | { |
df65f093 | 5733 | if (unit == NULL) |
524af0d6 | 5734 | return true; |
df65f093 | 5735 | |
524af0d6 JB |
5736 | if (!type_check (unit, 0, BT_INTEGER)) |
5737 | return false; | |
df65f093 | 5738 | |
524af0d6 JB |
5739 | if (!scalar_check (unit, 0)) |
5740 | return false; | |
df65f093 | 5741 | |
524af0d6 | 5742 | return true; |
df65f093 SK |
5743 | } |
5744 | ||
5745 | ||
524af0d6 | 5746 | bool |
65f8144a | 5747 | gfc_check_free (gfc_expr *i) |
0d519038 | 5748 | { |
524af0d6 JB |
5749 | if (!type_check (i, 0, BT_INTEGER)) |
5750 | return false; | |
0d519038 | 5751 | |
524af0d6 JB |
5752 | if (!scalar_check (i, 0)) |
5753 | return false; | |
0d519038 | 5754 | |
524af0d6 | 5755 | return true; |
0d519038 FXC |
5756 | } |
5757 | ||
5758 | ||
524af0d6 | 5759 | bool |
65f8144a | 5760 | gfc_check_hostnm (gfc_expr *name) |
f77b6ca3 | 5761 | { |
524af0d6 JB |
5762 | if (!type_check (name, 0, BT_CHARACTER)) |
5763 | return false; | |
5764 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
5765 | return false; | |
f77b6ca3 | 5766 | |
524af0d6 | 5767 | return true; |
f77b6ca3 FXC |
5768 | } |
5769 | ||
5770 | ||
524af0d6 | 5771 | bool |
65f8144a | 5772 | gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status) |
f77b6ca3 | 5773 | { |
524af0d6 JB |
5774 | if (!type_check (name, 0, BT_CHARACTER)) |
5775 | return false; | |
5776 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
5777 | return false; | |
f77b6ca3 FXC |
5778 | |
5779 | if (status == NULL) | |
524af0d6 | 5780 | return true; |
f77b6ca3 | 5781 | |
524af0d6 JB |
5782 | if (!scalar_check (status, 1)) |
5783 | return false; | |
f77b6ca3 | 5784 | |
524af0d6 JB |
5785 | if (!type_check (status, 1, BT_INTEGER)) |
5786 | return false; | |
f77b6ca3 | 5787 | |
524af0d6 | 5788 | return true; |
f77b6ca3 FXC |
5789 | } |
5790 | ||
5791 | ||
524af0d6 | 5792 | bool |
65f8144a | 5793 | gfc_check_itime_idate (gfc_expr *values) |
12197210 | 5794 | { |
524af0d6 JB |
5795 | if (!array_check (values, 0)) |
5796 | return false; | |
12197210 | 5797 | |
524af0d6 JB |
5798 | if (!rank_check (values, 0, 1)) |
5799 | return false; | |
12197210 | 5800 | |
524af0d6 JB |
5801 | if (!variable_check (values, 0, false)) |
5802 | return false; | |
12197210 | 5803 | |
524af0d6 JB |
5804 | if (!type_check (values, 0, BT_INTEGER)) |
5805 | return false; | |
12197210 | 5806 | |
524af0d6 JB |
5807 | if (!kind_value_check (values, 0, gfc_default_integer_kind)) |
5808 | return false; | |
12197210 | 5809 | |
524af0d6 | 5810 | return true; |
12197210 FXC |
5811 | } |
5812 | ||
5813 | ||
524af0d6 | 5814 | bool |
65f8144a | 5815 | gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values) |
a119fc1c | 5816 | { |
524af0d6 JB |
5817 | if (!type_check (time, 0, BT_INTEGER)) |
5818 | return false; | |
a119fc1c | 5819 | |
524af0d6 JB |
5820 | if (!kind_value_check (time, 0, gfc_default_integer_kind)) |
5821 | return false; | |
a119fc1c | 5822 | |
524af0d6 JB |
5823 | if (!scalar_check (time, 0)) |
5824 | return false; | |
a119fc1c | 5825 | |
524af0d6 JB |
5826 | if (!array_check (values, 1)) |
5827 | return false; | |
a119fc1c | 5828 | |
524af0d6 JB |
5829 | if (!rank_check (values, 1, 1)) |
5830 | return false; | |
a119fc1c | 5831 | |
524af0d6 JB |
5832 | if (!variable_check (values, 1, false)) |
5833 | return false; | |
a119fc1c | 5834 | |
524af0d6 JB |
5835 | if (!type_check (values, 1, BT_INTEGER)) |
5836 | return false; | |
a119fc1c | 5837 | |
524af0d6 JB |
5838 | if (!kind_value_check (values, 1, gfc_default_integer_kind)) |
5839 | return false; | |
a119fc1c | 5840 | |
524af0d6 | 5841 | return true; |
a119fc1c FXC |
5842 | } |
5843 | ||
5844 | ||
524af0d6 | 5845 | bool |
65f8144a | 5846 | gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name) |
ae8b8789 | 5847 | { |
524af0d6 JB |
5848 | if (!scalar_check (unit, 0)) |
5849 | return false; | |
ae8b8789 | 5850 | |
524af0d6 JB |
5851 | if (!type_check (unit, 0, BT_INTEGER)) |
5852 | return false; | |
ae8b8789 | 5853 | |
524af0d6 JB |
5854 | if (!type_check (name, 1, BT_CHARACTER)) |
5855 | return false; | |
5856 | if (!kind_value_check (name, 1, gfc_default_character_kind)) | |
5857 | return false; | |
ae8b8789 | 5858 | |
524af0d6 | 5859 | return true; |
ae8b8789 FXC |
5860 | } |
5861 | ||
5862 | ||
524af0d6 | 5863 | bool |
65f8144a | 5864 | gfc_check_isatty (gfc_expr *unit) |
ae8b8789 FXC |
5865 | { |
5866 | if (unit == NULL) | |
524af0d6 | 5867 | return false; |
ae8b8789 | 5868 | |
524af0d6 JB |
5869 | if (!type_check (unit, 0, BT_INTEGER)) |
5870 | return false; | |
ae8b8789 | 5871 | |
524af0d6 JB |
5872 | if (!scalar_check (unit, 0)) |
5873 | return false; | |
ae8b8789 | 5874 | |
524af0d6 | 5875 | return true; |
ae8b8789 FXC |
5876 | } |
5877 | ||
5878 | ||
524af0d6 | 5879 | bool |
3d97b1af FXC |
5880 | gfc_check_isnan (gfc_expr *x) |
5881 | { | |
524af0d6 JB |
5882 | if (!type_check (x, 0, BT_REAL)) |
5883 | return false; | |
3d97b1af | 5884 | |
524af0d6 | 5885 | return true; |
3d97b1af FXC |
5886 | } |
5887 | ||
5888 | ||
524af0d6 | 5889 | bool |
65f8144a | 5890 | gfc_check_perror (gfc_expr *string) |
f77b6ca3 | 5891 | { |
524af0d6 JB |
5892 | if (!type_check (string, 0, BT_CHARACTER)) |
5893 | return false; | |
5894 | if (!kind_value_check (string, 0, gfc_default_character_kind)) | |
5895 | return false; | |
f77b6ca3 | 5896 | |
524af0d6 | 5897 | return true; |
f77b6ca3 FXC |
5898 | } |
5899 | ||
5900 | ||
524af0d6 | 5901 | bool |
65f8144a | 5902 | gfc_check_umask (gfc_expr *mask) |
d8fe26b2 | 5903 | { |
524af0d6 JB |
5904 | if (!type_check (mask, 0, BT_INTEGER)) |
5905 | return false; | |
d8fe26b2 | 5906 | |
524af0d6 JB |
5907 | if (!scalar_check (mask, 0)) |
5908 | return false; | |
d8fe26b2 | 5909 | |
524af0d6 | 5910 | return true; |
d8fe26b2 SK |
5911 | } |
5912 | ||
5913 | ||
524af0d6 | 5914 | bool |
65f8144a | 5915 | gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old) |
d8fe26b2 | 5916 | { |
524af0d6 JB |
5917 | if (!type_check (mask, 0, BT_INTEGER)) |
5918 | return false; | |
d8fe26b2 | 5919 | |
524af0d6 JB |
5920 | if (!scalar_check (mask, 0)) |
5921 | return false; | |
d8fe26b2 SK |
5922 | |
5923 | if (old == NULL) | |
524af0d6 | 5924 | return true; |
d8fe26b2 | 5925 | |
524af0d6 JB |
5926 | if (!scalar_check (old, 1)) |
5927 | return false; | |
d8fe26b2 | 5928 | |
524af0d6 JB |
5929 | if (!type_check (old, 1, BT_INTEGER)) |
5930 | return false; | |
d8fe26b2 | 5931 | |
524af0d6 | 5932 | return true; |
d8fe26b2 SK |
5933 | } |
5934 | ||
5935 | ||
524af0d6 | 5936 | bool |
65f8144a | 5937 | gfc_check_unlink (gfc_expr *name) |
d8fe26b2 | 5938 | { |
524af0d6 JB |
5939 | if (!type_check (name, 0, BT_CHARACTER)) |
5940 | return false; | |
5941 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
5942 | return false; | |
d8fe26b2 | 5943 | |
524af0d6 | 5944 | return true; |
d8fe26b2 SK |
5945 | } |
5946 | ||
5947 | ||
524af0d6 | 5948 | bool |
65f8144a | 5949 | gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status) |
d8fe26b2 | 5950 | { |
524af0d6 JB |
5951 | if (!type_check (name, 0, BT_CHARACTER)) |
5952 | return false; | |
5953 | if (!kind_value_check (name, 0, gfc_default_character_kind)) | |
5954 | return false; | |
d8fe26b2 SK |
5955 | |
5956 | if (status == NULL) | |
524af0d6 | 5957 | return true; |
d8fe26b2 | 5958 | |
524af0d6 JB |
5959 | if (!scalar_check (status, 1)) |
5960 | return false; | |
a8c60d7f | 5961 | |
524af0d6 JB |
5962 | if (!type_check (status, 1, BT_INTEGER)) |
5963 | return false; | |
a8c60d7f | 5964 | |
524af0d6 | 5965 | return true; |
a8c60d7f | 5966 | } |
5b1374e9 TS |
5967 | |
5968 | ||
524af0d6 | 5969 | bool |
65f8144a | 5970 | gfc_check_signal (gfc_expr *number, gfc_expr *handler) |
185d7d97 | 5971 | { |
524af0d6 JB |
5972 | if (!scalar_check (number, 0)) |
5973 | return false; | |
5974 | if (!type_check (number, 0, BT_INTEGER)) | |
5975 | return false; | |
185d7d97 | 5976 | |
524af0d6 JB |
5977 | if (!int_or_proc_check (handler, 1)) |
5978 | return false; | |
5979 | if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1)) | |
5980 | return false; | |
185d7d97 | 5981 | |
524af0d6 | 5982 | return true; |
185d7d97 FXC |
5983 | } |
5984 | ||
5985 | ||
524af0d6 | 5986 | bool |
65f8144a | 5987 | gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status) |
185d7d97 | 5988 | { |
524af0d6 JB |
5989 | if (!scalar_check (number, 0)) |
5990 | return false; | |
5991 | if (!type_check (number, 0, BT_INTEGER)) | |
5992 | return false; | |
185d7d97 | 5993 | |
524af0d6 JB |
5994 | if (!int_or_proc_check (handler, 1)) |
5995 | return false; | |
5996 | if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1)) | |
5997 | return false; | |
185d7d97 FXC |
5998 | |
5999 | if (status == NULL) | |
524af0d6 | 6000 | return true; |
185d7d97 | 6001 | |
524af0d6 JB |
6002 | if (!type_check (status, 2, BT_INTEGER)) |
6003 | return false; | |
6004 | if (!scalar_check (status, 2)) | |
6005 | return false; | |
185d7d97 | 6006 | |
524af0d6 | 6007 | return true; |
185d7d97 FXC |
6008 | } |
6009 | ||
6010 | ||
524af0d6 | 6011 | bool |
65f8144a | 6012 | gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status) |
5b1374e9 | 6013 | { |
524af0d6 JB |
6014 | if (!type_check (cmd, 0, BT_CHARACTER)) |
6015 | return false; | |
6016 | if (!kind_value_check (cmd, 0, gfc_default_character_kind)) | |
6017 | return false; | |
5b1374e9 | 6018 | |
524af0d6 JB |
6019 | if (!scalar_check (status, 1)) |
6020 | return false; | |
5b1374e9 | 6021 | |
524af0d6 JB |
6022 | if (!type_check (status, 1, BT_INTEGER)) |
6023 | return false; | |
5b1374e9 | 6024 | |
524af0d6 JB |
6025 | if (!kind_value_check (status, 1, gfc_default_integer_kind)) |
6026 | return false; | |
5b1374e9 | 6027 | |
524af0d6 | 6028 | return true; |
5b1374e9 | 6029 | } |
5d723e54 FXC |
6030 | |
6031 | ||
6032 | /* This is used for the GNU intrinsics AND, OR and XOR. */ | |
524af0d6 | 6033 | bool |
65f8144a | 6034 | gfc_check_and (gfc_expr *i, gfc_expr *j) |
5d723e54 FXC |
6035 | { |
6036 | if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL) | |
6037 | { | |
65f8144a | 6038 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER " |
c4aa95f8 | 6039 | "or LOGICAL", gfc_current_intrinsic_arg[0]->name, |
65f8144a | 6040 | gfc_current_intrinsic, &i->where); |
524af0d6 | 6041 | return false; |
5d723e54 FXC |
6042 | } |
6043 | ||
6044 | if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL) | |
6045 | { | |
65f8144a | 6046 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER " |
c4aa95f8 | 6047 | "or LOGICAL", gfc_current_intrinsic_arg[1]->name, |
65f8144a | 6048 | gfc_current_intrinsic, &j->where); |
524af0d6 | 6049 | return false; |
5d723e54 FXC |
6050 | } |
6051 | ||
6052 | if (i->ts.type != j->ts.type) | |
6053 | { | |
6054 | gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must " | |
c4aa95f8 JW |
6055 | "have the same type", gfc_current_intrinsic_arg[0]->name, |
6056 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, | |
5d723e54 | 6057 | &j->where); |
524af0d6 | 6058 | return false; |
5d723e54 FXC |
6059 | } |
6060 | ||
524af0d6 JB |
6061 | if (!scalar_check (i, 0)) |
6062 | return false; | |
5d723e54 | 6063 | |
524af0d6 JB |
6064 | if (!scalar_check (j, 1)) |
6065 | return false; | |
5d723e54 | 6066 | |
524af0d6 | 6067 | return true; |
5d723e54 | 6068 | } |
048510c8 JW |
6069 | |
6070 | ||
524af0d6 | 6071 | bool |
1a8c1e35 | 6072 | gfc_check_storage_size (gfc_expr *a, gfc_expr *kind) |
048510c8 | 6073 | { |
1a8c1e35 TB |
6074 | if (a->ts.type == BT_ASSUMED) |
6075 | { | |
6076 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be TYPE(*)", | |
6077 | gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic, | |
6078 | &a->where); | |
524af0d6 | 6079 | return false; |
1a8c1e35 TB |
6080 | } |
6081 | ||
6082 | if (a->ts.type == BT_PROCEDURE) | |
6083 | { | |
6084 | gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be a " | |
6085 | "procedure", gfc_current_intrinsic_arg[0]->name, | |
6086 | gfc_current_intrinsic, &a->where); | |
524af0d6 | 6087 | return false; |
1a8c1e35 TB |
6088 | } |
6089 | ||
048510c8 | 6090 | if (kind == NULL) |
524af0d6 | 6091 | return true; |
048510c8 | 6092 | |
524af0d6 JB |
6093 | if (!type_check (kind, 1, BT_INTEGER)) |
6094 | return false; | |
048510c8 | 6095 | |
524af0d6 JB |
6096 | if (!scalar_check (kind, 1)) |
6097 | return false; | |
048510c8 JW |
6098 | |
6099 | if (kind->expr_type != EXPR_CONSTANT) | |
6100 | { | |
6101 | gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant", | |
c4aa95f8 | 6102 | gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic, |
048510c8 | 6103 | &kind->where); |
524af0d6 | 6104 | return false; |
048510c8 JW |
6105 | } |
6106 | ||
524af0d6 | 6107 | return true; |
048510c8 | 6108 | } |