Branch data Line data Source code
1 : : /* Matching subroutines in all sizes, shapes and colors.
2 : : Copyright (C) 2000-2025 Free Software Foundation, Inc.
3 : : Contributed by Andy Vaught
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
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.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "options.h"
25 : : #include "gfortran.h"
26 : : #include "match.h"
27 : : #include "parse.h"
28 : :
29 : : int gfc_matching_ptr_assignment = 0;
30 : : int gfc_matching_procptr_assignment = 0;
31 : : bool gfc_matching_prefix = false;
32 : :
33 : : /* Stack of SELECT TYPE statements. */
34 : : gfc_select_type_stack *select_type_stack = NULL;
35 : :
36 : : /* List of type parameter expressions. */
37 : : gfc_actual_arglist *type_param_spec_list;
38 : :
39 : : /* For debugging and diagnostic purposes. Return the textual representation
40 : : of the intrinsic operator OP. */
41 : : const char *
42 : 8485631 : gfc_op2string (gfc_intrinsic_op op)
43 : : {
44 : 8485631 : switch (op)
45 : : {
46 : : case INTRINSIC_UPLUS:
47 : : case INTRINSIC_PLUS:
48 : : return "+";
49 : :
50 : 652578 : case INTRINSIC_UMINUS:
51 : 652578 : case INTRINSIC_MINUS:
52 : 652578 : return "-";
53 : :
54 : 326170 : case INTRINSIC_POWER:
55 : 326170 : return "**";
56 : 326169 : case INTRINSIC_CONCAT:
57 : 326169 : return "//";
58 : 326632 : case INTRINSIC_TIMES:
59 : 326632 : return "*";
60 : 326170 : case INTRINSIC_DIVIDE:
61 : 326170 : return "/";
62 : :
63 : 326297 : case INTRINSIC_AND:
64 : 326297 : return ".and.";
65 : 326987 : case INTRINSIC_OR:
66 : 326987 : return ".or.";
67 : 326287 : case INTRINSIC_EQV:
68 : 326287 : return ".eqv.";
69 : 326284 : case INTRINSIC_NEQV:
70 : 326284 : return ".neqv.";
71 : :
72 : 326190 : case INTRINSIC_EQ_OS:
73 : 326190 : return ".eq.";
74 : 326178 : case INTRINSIC_EQ:
75 : 326178 : return "==";
76 : 326190 : case INTRINSIC_NE_OS:
77 : 326190 : return ".ne.";
78 : 326178 : case INTRINSIC_NE:
79 : 326178 : return "/=";
80 : 326181 : case INTRINSIC_GE_OS:
81 : 326181 : return ".ge.";
82 : 326175 : case INTRINSIC_GE:
83 : 326175 : return ">=";
84 : 326182 : case INTRINSIC_LE_OS:
85 : 326182 : return ".le.";
86 : 326175 : case INTRINSIC_LE:
87 : 326175 : return "<=";
88 : 326227 : case INTRINSIC_LT_OS:
89 : 326227 : return ".lt.";
90 : 326199 : case INTRINSIC_LT:
91 : 326199 : return "<";
92 : 326190 : case INTRINSIC_GT_OS:
93 : 326190 : return ".gt.";
94 : 326175 : case INTRINSIC_GT:
95 : 326175 : return ">";
96 : 326168 : case INTRINSIC_NOT:
97 : 326168 : return ".not.";
98 : :
99 : 775 : case INTRINSIC_ASSIGN:
100 : 775 : return "=";
101 : :
102 : 326168 : case INTRINSIC_PARENTHESES:
103 : 326168 : return "parens";
104 : :
105 : 1 : case INTRINSIC_NONE:
106 : 1 : return "none";
107 : :
108 : : /* DTIO */
109 : 0 : case INTRINSIC_FORMATTED:
110 : 0 : return "formatted";
111 : 0 : case INTRINSIC_UNFORMATTED:
112 : 0 : return "unformatted";
113 : :
114 : 0 : default:
115 : 0 : break;
116 : : }
117 : :
118 : 0 : gfc_internal_error ("gfc_op2string(): Bad code");
119 : : /* Not reached. */
120 : : }
121 : :
122 : :
123 : : /******************** Generic matching subroutines ************************/
124 : :
125 : : /* Matches a member separator. With standard FORTRAN this is '%', but with
126 : : DEC structures we must carefully match dot ('.').
127 : : Because operators are spelled ".op.", a dotted string such as "x.y.z..."
128 : : can be either a component reference chain or a combination of binary
129 : : operations.
130 : : There is no real way to win because the string may be grammatically
131 : : ambiguous. The following rules help avoid ambiguities - they match
132 : : some behavior of other (older) compilers. If the rules here are changed
133 : : the test cases should be updated. If the user has problems with these rules
134 : : they probably deserve the consequences. Consider "x.y.z":
135 : : (1) If any user defined operator ".y." exists, this is always y(x,z)
136 : : (even if ".y." is the wrong type and/or x has a member y).
137 : : (2) Otherwise if x has a member y, and y is itself a derived type,
138 : : this is (x->y)->z, even if an intrinsic operator exists which
139 : : can handle (x,z).
140 : : (3) If x has no member y or (x->y) is not a derived type but ".y."
141 : : is an intrinsic operator (such as ".eq."), this is y(x,z).
142 : : (4) Lastly if there is no operator ".y." and x has no member "y", it is an
143 : : error.
144 : : It is worth noting that the logic here does not support mixed use of member
145 : : accessors within a single string. That is, even if x has component y and y
146 : : has component z, the following are all syntax errors:
147 : : "x%y.z" "x.y%z" "(x.y).z" "(x%y)%z"
148 : : */
149 : :
150 : : match
151 : 7837044 : gfc_match_member_sep(gfc_symbol *sym)
152 : : {
153 : 7837044 : char name[GFC_MAX_SYMBOL_LEN + 1];
154 : 7837044 : locus dot_loc, start_loc;
155 : 7837044 : gfc_intrinsic_op iop;
156 : 7837044 : match m;
157 : 7837044 : gfc_symbol *tsym;
158 : 7837044 : gfc_component *c = NULL;
159 : :
160 : : /* What a relief: '%' is an unambiguous member separator. */
161 : 7837044 : if (gfc_match_char ('%') == MATCH_YES)
162 : : return MATCH_YES;
163 : :
164 : : /* Beware ye who enter here. */
165 : 7671542 : if (!flag_dec_structure || !sym)
166 : : return MATCH_NO;
167 : :
168 : 66707 : tsym = NULL;
169 : :
170 : : /* We may be given either a derived type variable or the derived type
171 : : declaration itself (which actually contains the components);
172 : : we need the latter to search for components. */
173 : 66707 : if (gfc_fl_struct (sym->attr.flavor))
174 : : tsym = sym;
175 : 66307 : else if (gfc_bt_struct (sym->ts.type))
176 : 2726 : tsym = sym->ts.u.derived;
177 : :
178 : 66707 : iop = INTRINSIC_NONE;
179 : 66707 : name[0] = '\0';
180 : 66707 : m = MATCH_NO;
181 : :
182 : : /* If we have to reject come back here later. */
183 : 66707 : start_loc = gfc_current_locus;
184 : :
185 : : /* Look for a component access next. */
186 : 66707 : if (gfc_match_char ('.') != MATCH_YES)
187 : : return MATCH_NO;
188 : :
189 : : /* If we accept, come back here. */
190 : 7865 : dot_loc = gfc_current_locus;
191 : :
192 : : /* Try to match a symbol name following the dot. */
193 : 7865 : if (gfc_match_name (name) != MATCH_YES)
194 : : {
195 : 1 : gfc_error ("Expected structure component or operator name "
196 : : "after %<.%> at %C");
197 : 1 : goto error;
198 : : }
199 : :
200 : : /* If no dot follows we have "x.y" which should be a component access. */
201 : 7864 : if (gfc_match_char ('.') != MATCH_YES)
202 : 1658 : goto yes;
203 : :
204 : : /* Now we have a string "x.y.z" which could be a nested member access
205 : : (x->y)->z or a binary operation y on x and z. */
206 : :
207 : : /* First use any user-defined operators ".y." */
208 : 6206 : if (gfc_find_uop (name, sym->ns) != NULL)
209 : 6 : goto no;
210 : :
211 : : /* Match accesses to existing derived-type components for
212 : : derived-type vars: "x.y.z" = (x->y)->z */
213 : 6200 : c = gfc_find_component(tsym, name, false, true, NULL);
214 : 6200 : if (c && (gfc_bt_struct (c->ts.type) || c->ts.type == BT_CLASS))
215 : 314 : goto yes;
216 : :
217 : : /* If y is not a component or has no members, try intrinsic operators. */
218 : 5886 : gfc_current_locus = start_loc;
219 : 5886 : if (gfc_match_intrinsic_op (&iop) != MATCH_YES)
220 : : {
221 : : /* If ".y." is not an intrinsic operator but y was a valid non-
222 : : structure component, match and leave the trailing dot to be
223 : : dealt with later. */
224 : 877 : if (c)
225 : 877 : goto yes;
226 : :
227 : 0 : gfc_error ("%qs is neither a defined operator nor a "
228 : : "structure component in dotted string at %C", name);
229 : 0 : goto error;
230 : : }
231 : :
232 : : /* .y. is an intrinsic operator, overriding any possible member access. */
233 : 5009 : goto no;
234 : :
235 : : /* Return keeping the current locus consistent with the match result. */
236 : : error:
237 : : m = MATCH_ERROR;
238 : 5016 : no:
239 : 5016 : gfc_current_locus = start_loc;
240 : 5016 : return m;
241 : 2849 : yes:
242 : 2849 : gfc_current_locus = dot_loc;
243 : 2849 : return MATCH_YES;
244 : : }
245 : :
246 : :
247 : : /* This function scans the current statement counting the opened and closed
248 : : parenthesis to make sure they are balanced. */
249 : :
250 : : match
251 : 361895 : gfc_match_parens (void)
252 : : {
253 : 361895 : locus old_loc, where;
254 : 361895 : int count;
255 : 361895 : gfc_instring instring;
256 : 361895 : gfc_char_t c, quote;
257 : :
258 : 361895 : old_loc = gfc_current_locus;
259 : 361895 : count = 0;
260 : 361895 : instring = NONSTRING;
261 : 361895 : quote = ' ';
262 : :
263 : 13999778 : for (;;)
264 : : {
265 : 13999778 : if (count > 0)
266 : 7836309 : where = gfc_current_locus;
267 : 13999778 : c = gfc_next_char_literal (instring);
268 : 13999778 : if (c == '\n')
269 : : break;
270 : 13637883 : if (quote == ' ' && ((c == '\'') || (c == '"')))
271 : : {
272 : 56103 : quote = c;
273 : 56103 : instring = INSTRING_WARN;
274 : 56103 : continue;
275 : : }
276 : 13581780 : if (quote != ' ' && c == quote)
277 : : {
278 : 56103 : quote = ' ';
279 : 56103 : instring = NONSTRING;
280 : 56103 : continue;
281 : : }
282 : :
283 : 13525677 : if (c == '(' && quote == ' ')
284 : : {
285 : 652965 : count++;
286 : : }
287 : 13525677 : if (c == ')' && quote == ' ')
288 : : {
289 : 652959 : count--;
290 : 652959 : where = gfc_current_locus;
291 : : }
292 : : }
293 : :
294 : 361895 : gfc_current_locus = old_loc;
295 : :
296 : 361895 : if (count != 0)
297 : : {
298 : 10 : gfc_error ("Missing %qs in statement at or before %L",
299 : : count > 0? ")":"(", &where);
300 : 10 : return MATCH_ERROR;
301 : : }
302 : :
303 : : return MATCH_YES;
304 : : }
305 : :
306 : :
307 : : /* See if the next character is a special character that has
308 : : escaped by a \ via the -fbackslash option. */
309 : :
310 : : match
311 : 12228 : gfc_match_special_char (gfc_char_t *res)
312 : : {
313 : 12228 : int len, i;
314 : 12228 : gfc_char_t c, n;
315 : 12228 : match m;
316 : :
317 : 12228 : m = MATCH_YES;
318 : :
319 : 12228 : switch ((c = gfc_next_char_literal (INSTRING_WARN)))
320 : : {
321 : 0 : case 'a':
322 : 0 : *res = '\a';
323 : 0 : break;
324 : 372 : case 'b':
325 : 372 : *res = '\b';
326 : 372 : break;
327 : 96 : case 't':
328 : 96 : *res = '\t';
329 : 96 : break;
330 : 0 : case 'f':
331 : 0 : *res = '\f';
332 : 0 : break;
333 : 36 : case 'n':
334 : 36 : *res = '\n';
335 : 36 : break;
336 : 96 : case 'r':
337 : 96 : *res = '\r';
338 : 96 : break;
339 : 0 : case 'v':
340 : 0 : *res = '\v';
341 : 0 : break;
342 : 48 : case '\\':
343 : 48 : *res = '\\';
344 : 48 : break;
345 : 2644 : case '0':
346 : 2644 : *res = '\0';
347 : 2644 : break;
348 : :
349 : 8936 : case 'x':
350 : 8936 : case 'u':
351 : 8936 : case 'U':
352 : : /* Hexadecimal form of wide characters. */
353 : 8936 : len = (c == 'x' ? 2 : (c == 'u' ? 4 : 8));
354 : 8936 : n = 0;
355 : 34168 : for (i = 0; i < len; i++)
356 : : {
357 : 25232 : char buf[2] = { '\0', '\0' };
358 : :
359 : 25232 : c = gfc_next_char_literal (INSTRING_WARN);
360 : 25232 : if (!gfc_wide_fits_in_byte (c)
361 : 25232 : || !gfc_check_digit ((unsigned char) c, 16))
362 : 0 : return MATCH_NO;
363 : :
364 : 25232 : buf[0] = (unsigned char) c;
365 : 25232 : n = n << 4;
366 : 25232 : n += strtol (buf, NULL, 16);
367 : : }
368 : 8936 : *res = n;
369 : 8936 : break;
370 : :
371 : : default:
372 : : /* Unknown backslash codes are simply not expanded. */
373 : : m = MATCH_NO;
374 : : break;
375 : : }
376 : :
377 : : return m;
378 : : }
379 : :
380 : :
381 : : /* In free form, match at least one space. Always matches in fixed
382 : : form. */
383 : :
384 : : match
385 : 433219 : gfc_match_space (void)
386 : : {
387 : 433219 : locus old_loc;
388 : 433219 : char c;
389 : :
390 : 433219 : if (gfc_current_form == FORM_FIXED)
391 : : return MATCH_YES;
392 : :
393 : 413526 : old_loc = gfc_current_locus;
394 : :
395 : 413526 : c = gfc_next_ascii_char ();
396 : 413526 : if (!gfc_is_whitespace (c))
397 : : {
398 : 15898 : gfc_current_locus = old_loc;
399 : 15898 : return MATCH_NO;
400 : : }
401 : :
402 : 397628 : gfc_gobble_whitespace ();
403 : :
404 : 397628 : return MATCH_YES;
405 : : }
406 : :
407 : :
408 : : /* Match an end of statement. End of statement is optional
409 : : whitespace, followed by a ';' or '\n' or comment '!'. If a
410 : : semicolon is found, we continue to eat whitespace and semicolons. */
411 : :
412 : : match
413 : 3388932 : gfc_match_eos (void)
414 : : {
415 : 3388932 : locus old_loc;
416 : 3388932 : int flag;
417 : 3388932 : char c;
418 : :
419 : 3388932 : flag = 0;
420 : :
421 : 3453280 : for (;;)
422 : : {
423 : 3421106 : old_loc = gfc_current_locus;
424 : 3421106 : gfc_gobble_whitespace ();
425 : :
426 : 3421106 : c = gfc_next_ascii_char ();
427 : 3421106 : switch (c)
428 : : {
429 : 0 : case '!':
430 : 0 : do
431 : : {
432 : 0 : c = gfc_next_ascii_char ();
433 : : }
434 : 0 : while (c != '\n');
435 : :
436 : : /* Fall through. */
437 : :
438 : : case '\n':
439 : : return MATCH_YES;
440 : :
441 : 32174 : case ';':
442 : 32174 : flag = 1;
443 : 32174 : continue;
444 : : }
445 : :
446 : 2127406 : break;
447 : : }
448 : :
449 : 2127406 : gfc_current_locus = old_loc;
450 : 2127406 : return (flag) ? MATCH_YES : MATCH_NO;
451 : : }
452 : :
453 : :
454 : : /* Match a literal integer on the input, setting the value on
455 : : MATCH_YES. Literal ints occur in kind-parameters as well as
456 : : old-style character length specifications. If cnt is non-NULL it
457 : : will be set to the number of digits.
458 : : When gobble_ws is false, do not skip over leading blanks. */
459 : :
460 : : match
461 : 773735 : gfc_match_small_literal_int (int *value, int *cnt, bool gobble_ws)
462 : : {
463 : 773735 : locus old_loc;
464 : 773735 : char c;
465 : 773735 : int i, j;
466 : :
467 : 773735 : old_loc = gfc_current_locus;
468 : :
469 : 773735 : *value = -1;
470 : 773735 : if (gobble_ws)
471 : 304698 : gfc_gobble_whitespace ();
472 : 773735 : c = gfc_next_ascii_char ();
473 : 773735 : if (cnt)
474 : 300909 : *cnt = 0;
475 : :
476 : 773735 : if (!ISDIGIT (c))
477 : : {
478 : 384340 : gfc_current_locus = old_loc;
479 : 384340 : return MATCH_NO;
480 : : }
481 : :
482 : 389395 : i = c - '0';
483 : 389395 : j = 1;
484 : :
485 : 479493 : for (;;)
486 : : {
487 : 479493 : old_loc = gfc_current_locus;
488 : 479493 : c = gfc_next_ascii_char ();
489 : :
490 : 479493 : if (!ISDIGIT (c))
491 : : break;
492 : :
493 : 90098 : i = 10 * i + c - '0';
494 : 90098 : j++;
495 : :
496 : 90098 : if (i > 99999999)
497 : : {
498 : 0 : gfc_error ("Integer too large at %C");
499 : 0 : return MATCH_ERROR;
500 : : }
501 : : }
502 : :
503 : 389395 : gfc_current_locus = old_loc;
504 : :
505 : 389395 : *value = i;
506 : 389395 : if (cnt)
507 : 11018 : *cnt = j;
508 : : return MATCH_YES;
509 : : }
510 : :
511 : :
512 : : /* Match a small, constant integer expression, like in a kind
513 : : statement. On MATCH_YES, 'value' is set. */
514 : :
515 : : match
516 : 186513 : gfc_match_small_int (int *value)
517 : : {
518 : 186513 : gfc_expr *expr;
519 : 186513 : match m;
520 : 186513 : int i;
521 : :
522 : 186513 : m = gfc_match_expr (&expr);
523 : 186513 : if (m != MATCH_YES)
524 : : return m;
525 : :
526 : 186513 : if (gfc_extract_int (expr, &i, 1))
527 : 1228 : m = MATCH_ERROR;
528 : 186513 : gfc_free_expr (expr);
529 : :
530 : 186513 : *value = i;
531 : 186513 : return m;
532 : : }
533 : :
534 : :
535 : : /* Matches a statement label. Uses gfc_match_small_literal_int() to
536 : : do most of the work. */
537 : :
538 : : match
539 : 300905 : gfc_match_st_label (gfc_st_label **label)
540 : : {
541 : 300905 : locus old_loc;
542 : 300905 : match m;
543 : 300905 : int i, cnt;
544 : :
545 : 300905 : old_loc = gfc_current_locus;
546 : :
547 : 300905 : m = gfc_match_small_literal_int (&i, &cnt);
548 : 300905 : if (m != MATCH_YES)
549 : : return m;
550 : :
551 : 11016 : if (cnt > 5)
552 : : {
553 : 2 : gfc_error ("Too many digits in statement label at %C");
554 : 2 : goto cleanup;
555 : : }
556 : :
557 : 11014 : if (i == 0)
558 : : {
559 : 2 : gfc_error ("Statement label at %C is zero");
560 : 2 : goto cleanup;
561 : : }
562 : :
563 : 11012 : *label = gfc_get_st_label (i);
564 : 11012 : return MATCH_YES;
565 : :
566 : 4 : cleanup:
567 : :
568 : 4 : gfc_current_locus = old_loc;
569 : 4 : return MATCH_ERROR;
570 : : }
571 : :
572 : :
573 : : /* Match and validate a label associated with a named IF, DO or SELECT
574 : : statement. If the symbol does not have the label attribute, we add
575 : : it. We also make sure the symbol does not refer to another
576 : : (active) block. A matched label is pointed to by gfc_new_block. */
577 : :
578 : : static match
579 : 5038859 : gfc_match_label (void)
580 : : {
581 : 5038859 : char name[GFC_MAX_SYMBOL_LEN + 1];
582 : 5038859 : match m;
583 : :
584 : 5038859 : gfc_new_block = NULL;
585 : :
586 : 5038859 : m = gfc_match (" %n :", name);
587 : 5038859 : if (m != MATCH_YES)
588 : : return m;
589 : :
590 : 101877 : if (gfc_get_symbol (name, NULL, &gfc_new_block))
591 : : {
592 : 0 : gfc_error ("Label name %qs at %C is ambiguous", name);
593 : 0 : return MATCH_ERROR;
594 : : }
595 : :
596 : 101877 : if (gfc_new_block->attr.flavor == FL_LABEL)
597 : : {
598 : 70 : gfc_error ("Duplicate construct label %qs at %C", name);
599 : 70 : return MATCH_ERROR;
600 : : }
601 : :
602 : 101807 : if (!gfc_add_flavor (&gfc_new_block->attr, FL_LABEL,
603 : : gfc_new_block->name, NULL))
604 : : return MATCH_ERROR;
605 : :
606 : : return MATCH_YES;
607 : : }
608 : :
609 : :
610 : : /* See if the current input looks like a name of some sort. Modifies
611 : : the passed buffer which must be GFC_MAX_SYMBOL_LEN+1 bytes long.
612 : : Note that options.cc restricts max_identifier_length to not more
613 : : than GFC_MAX_SYMBOL_LEN.
614 : : When gobble_ws is false, do not skip over leading blanks. */
615 : :
616 : : match
617 : 26447815 : gfc_match_name (char *buffer, bool gobble_ws)
618 : : {
619 : 26447815 : locus old_loc;
620 : 26447815 : int i;
621 : 26447815 : char c;
622 : :
623 : 26447815 : old_loc = gfc_current_locus;
624 : 26447815 : if (gobble_ws)
625 : 26353882 : gfc_gobble_whitespace ();
626 : :
627 : 26447815 : c = gfc_next_ascii_char ();
628 : 26447815 : if (!(ISALPHA (c) || (c == '_' && flag_allow_leading_underscore)))
629 : : {
630 : : /* Special cases for unary minus and plus, which allows for a sensible
631 : : error message for code of the form 'c = exp(-a*b) )' where an
632 : : extra ')' appears at the end of statement. */
633 : 1558336 : if (!gfc_error_flag_test () && c != '(' && c != '-' && c != '+')
634 : 405055 : gfc_error ("Invalid character in name at %C");
635 : 1558336 : gfc_current_locus = old_loc;
636 : 1558336 : return MATCH_NO;
637 : : }
638 : :
639 : : i = 0;
640 : :
641 : 113058899 : do
642 : : {
643 : 113058899 : buffer[i++] = c;
644 : :
645 : 113058899 : if (i > gfc_option.max_identifier_length)
646 : : {
647 : 0 : gfc_error ("Name at %C is too long");
648 : 0 : return MATCH_ERROR;
649 : : }
650 : :
651 : 113058899 : old_loc = gfc_current_locus;
652 : 113058899 : c = gfc_next_ascii_char ();
653 : : }
654 : 113058899 : while (ISALNUM (c) || c == '_' || (flag_dollar_ok && c == '$'));
655 : :
656 : 24889479 : if (c == '$' && !flag_dollar_ok)
657 : : {
658 : 2 : gfc_fatal_error ("Invalid character %<$%> at %L. Use %<-fdollar-ok%> to "
659 : : "allow it as an extension", &old_loc);
660 : : return MATCH_ERROR;
661 : : }
662 : :
663 : 24889477 : buffer[i] = '\0';
664 : 24889477 : gfc_current_locus = old_loc;
665 : :
666 : 24889477 : return MATCH_YES;
667 : : }
668 : :
669 : :
670 : : /* Match a symbol on the input. Modifies the pointer to the symbol
671 : : pointer if successful. */
672 : :
673 : : match
674 : 4103976 : gfc_match_sym_tree (gfc_symtree **matched_symbol, int host_assoc)
675 : : {
676 : 4103976 : char buffer[GFC_MAX_SYMBOL_LEN + 1];
677 : 4103976 : match m;
678 : 4103976 : int ret;
679 : :
680 : 4103976 : locus loc = gfc_current_locus;
681 : 4103976 : m = gfc_match_name (buffer);
682 : 4103975 : if (m != MATCH_YES)
683 : : return m;
684 : 4103833 : loc = gfc_get_location_range (NULL, 0, &loc, 1, &gfc_current_locus);
685 : 4103833 : if (host_assoc)
686 : : {
687 : 2524118 : ret = gfc_get_ha_sym_tree (buffer, matched_symbol, &loc);
688 : 5048234 : return ret ? MATCH_ERROR : MATCH_YES;
689 : : }
690 : :
691 : 1579715 : ret = gfc_get_sym_tree (buffer, NULL, matched_symbol, false, &loc);
692 : 1579715 : if (ret)
693 : 30 : return MATCH_ERROR;
694 : :
695 : : return MATCH_YES;
696 : : }
697 : :
698 : :
699 : : match
700 : 1398030 : gfc_match_symbol (gfc_symbol **matched_symbol, int host_assoc)
701 : : {
702 : 1398030 : gfc_symtree *st;
703 : 1398030 : match m;
704 : :
705 : 1398030 : m = gfc_match_sym_tree (&st, host_assoc);
706 : :
707 : 1398030 : if (m == MATCH_YES)
708 : : {
709 : 1397880 : if (st)
710 : 1397880 : *matched_symbol = st->n.sym;
711 : : else
712 : 0 : *matched_symbol = NULL;
713 : : }
714 : : else
715 : 150 : *matched_symbol = NULL;
716 : 1398030 : return m;
717 : : }
718 : :
719 : :
720 : : /* Match an intrinsic operator. Returns an INTRINSIC enum. While matching,
721 : : we always find INTRINSIC_PLUS before INTRINSIC_UPLUS. We work around this
722 : : in matchexp.cc. */
723 : :
724 : : match
725 : 77650330 : gfc_match_intrinsic_op (gfc_intrinsic_op *result)
726 : : {
727 : 77650330 : locus orig_loc = gfc_current_locus;
728 : 77650330 : char ch;
729 : :
730 : 77650330 : gfc_gobble_whitespace ();
731 : 77650330 : ch = gfc_next_ascii_char ();
732 : 77650330 : switch (ch)
733 : : {
734 : 337793 : case '+':
735 : : /* Matched "+". */
736 : 337793 : *result = INTRINSIC_PLUS;
737 : 337793 : return MATCH_YES;
738 : :
739 : 515267 : case '-':
740 : : /* Matched "-". */
741 : 515267 : *result = INTRINSIC_MINUS;
742 : 515267 : return MATCH_YES;
743 : :
744 : 259120 : case '=':
745 : 259120 : if (gfc_next_ascii_char () == '=')
746 : : {
747 : : /* Matched "==". */
748 : 146931 : *result = INTRINSIC_EQ;
749 : 146931 : return MATCH_YES;
750 : : }
751 : : break;
752 : :
753 : 76645 : case '<':
754 : 76645 : if (gfc_peek_ascii_char () == '=')
755 : : {
756 : : /* Matched "<=". */
757 : 33399 : gfc_next_ascii_char ();
758 : 33399 : *result = INTRINSIC_LE;
759 : 33399 : return MATCH_YES;
760 : : }
761 : : /* Matched "<". */
762 : 43246 : *result = INTRINSIC_LT;
763 : 43246 : return MATCH_YES;
764 : :
765 : 268030 : case '>':
766 : 268030 : if (gfc_peek_ascii_char () == '=')
767 : : {
768 : : /* Matched ">=". */
769 : 12595 : gfc_next_ascii_char ();
770 : 12595 : *result = INTRINSIC_GE;
771 : 12595 : return MATCH_YES;
772 : : }
773 : : /* Matched ">". */
774 : 255435 : *result = INTRINSIC_GT;
775 : 255435 : return MATCH_YES;
776 : :
777 : 263978 : case '*':
778 : 263978 : if (gfc_peek_ascii_char () == '*')
779 : : {
780 : : /* Matched "**". */
781 : 67457 : gfc_next_ascii_char ();
782 : 67457 : *result = INTRINSIC_POWER;
783 : 67457 : return MATCH_YES;
784 : : }
785 : : /* Matched "*". */
786 : 196521 : *result = INTRINSIC_TIMES;
787 : 196521 : return MATCH_YES;
788 : :
789 : 5029493 : case '/':
790 : 5029493 : ch = gfc_peek_ascii_char ();
791 : 5029493 : if (ch == '=')
792 : : {
793 : : /* Matched "/=". */
794 : 4315202 : gfc_next_ascii_char ();
795 : 4315202 : *result = INTRINSIC_NE;
796 : 4315202 : return MATCH_YES;
797 : : }
798 : 714291 : else if (ch == '/')
799 : : {
800 : : /* Matched "//". */
801 : 30879 : gfc_next_ascii_char ();
802 : 30879 : *result = INTRINSIC_CONCAT;
803 : 30879 : return MATCH_YES;
804 : : }
805 : : /* Matched "/". */
806 : 683412 : *result = INTRINSIC_DIVIDE;
807 : 683412 : return MATCH_YES;
808 : :
809 : 3821255 : case '.':
810 : 3821255 : ch = gfc_next_ascii_char ();
811 : 3821255 : switch (ch)
812 : : {
813 : 127516 : case 'a':
814 : 127516 : if (gfc_next_ascii_char () == 'n'
815 : 126606 : && gfc_next_ascii_char () == 'd'
816 : 254122 : && gfc_next_ascii_char () == '.')
817 : : {
818 : : /* Matched ".and.". */
819 : 126606 : *result = INTRINSIC_AND;
820 : 126606 : return MATCH_YES;
821 : : }
822 : : break;
823 : :
824 : 99746 : case 'e':
825 : 99746 : if (gfc_next_ascii_char () == 'q')
826 : : {
827 : 99662 : ch = gfc_next_ascii_char ();
828 : 99662 : if (ch == '.')
829 : : {
830 : : /* Matched ".eq.". */
831 : 79783 : *result = INTRINSIC_EQ_OS;
832 : 79783 : return MATCH_YES;
833 : : }
834 : 19879 : else if (ch == 'v')
835 : : {
836 : 19877 : if (gfc_next_ascii_char () == '.')
837 : : {
838 : : /* Matched ".eqv.". */
839 : 19877 : *result = INTRINSIC_EQV;
840 : 19877 : return MATCH_YES;
841 : : }
842 : : }
843 : : }
844 : : break;
845 : :
846 : 77757 : case 'g':
847 : 77757 : ch = gfc_next_ascii_char ();
848 : 77757 : if (ch == 'e')
849 : : {
850 : 20232 : if (gfc_next_ascii_char () == '.')
851 : : {
852 : : /* Matched ".ge.". */
853 : 20154 : *result = INTRINSIC_GE_OS;
854 : 20154 : return MATCH_YES;
855 : : }
856 : : }
857 : 57525 : else if (ch == 't')
858 : : {
859 : 57525 : if (gfc_next_ascii_char () == '.')
860 : : {
861 : : /* Matched ".gt.". */
862 : 57525 : *result = INTRINSIC_GT_OS;
863 : 57525 : return MATCH_YES;
864 : : }
865 : : }
866 : : break;
867 : :
868 : 52518 : case 'l':
869 : 52518 : ch = gfc_next_ascii_char ();
870 : 52518 : if (ch == 'e')
871 : : {
872 : 18288 : if (gfc_next_ascii_char () == '.')
873 : : {
874 : : /* Matched ".le.". */
875 : 18288 : *result = INTRINSIC_LE_OS;
876 : 18288 : return MATCH_YES;
877 : : }
878 : : }
879 : 34230 : else if (ch == 't')
880 : : {
881 : 34044 : if (gfc_next_ascii_char () == '.')
882 : : {
883 : : /* Matched ".lt.". */
884 : 34044 : *result = INTRINSIC_LT_OS;
885 : 34044 : return MATCH_YES;
886 : : }
887 : : }
888 : : break;
889 : :
890 : 1700926 : case 'n':
891 : 1700926 : ch = gfc_next_ascii_char ();
892 : 1700926 : if (ch == 'e')
893 : : {
894 : 1624587 : ch = gfc_next_ascii_char ();
895 : 1624587 : if (ch == '.')
896 : : {
897 : : /* Matched ".ne.". */
898 : 1381034 : *result = INTRINSIC_NE_OS;
899 : 1381034 : return MATCH_YES;
900 : : }
901 : 243553 : else if (ch == 'q')
902 : : {
903 : 243553 : if (gfc_next_ascii_char () == 'v'
904 : 243553 : && gfc_next_ascii_char () == '.')
905 : : {
906 : : /* Matched ".neqv.". */
907 : 243553 : *result = INTRINSIC_NEQV;
908 : 243553 : return MATCH_YES;
909 : : }
910 : : }
911 : : }
912 : 76339 : else if (ch == 'o')
913 : : {
914 : 76336 : if (gfc_next_ascii_char () == 't'
915 : 76336 : && gfc_next_ascii_char () == '.')
916 : : {
917 : : /* Matched ".not.". */
918 : 76291 : *result = INTRINSIC_NOT;
919 : 76291 : return MATCH_YES;
920 : : }
921 : : }
922 : : break;
923 : :
924 : 1622257 : case 'o':
925 : 1622257 : if (gfc_next_ascii_char () == 'r'
926 : 1622257 : && gfc_next_ascii_char () == '.')
927 : : {
928 : : /* Matched ".or.". */
929 : 1622032 : *result = INTRINSIC_OR;
930 : 1622032 : return MATCH_YES;
931 : : }
932 : : break;
933 : :
934 : 449 : case 'x':
935 : 449 : if (gfc_next_ascii_char () == 'o'
936 : 327 : && gfc_next_ascii_char () == 'r'
937 : 776 : && gfc_next_ascii_char () == '.')
938 : : {
939 : 327 : if (!gfc_notify_std (GFC_STD_LEGACY, ".XOR. operator at %C"))
940 : : return MATCH_ERROR;
941 : : /* Matched ".xor." - equivalent to ".neqv.". */
942 : 320 : *result = INTRINSIC_NEQV;
943 : 320 : return MATCH_YES;
944 : : }
945 : : break;
946 : :
947 : : default:
948 : : break;
949 : : }
950 : : break;
951 : :
952 : : default:
953 : : break;
954 : : }
955 : :
956 : 67332679 : gfc_current_locus = orig_loc;
957 : 67332679 : return MATCH_NO;
958 : : }
959 : :
960 : :
961 : : /* Match a loop control phrase:
962 : :
963 : : <LVALUE> = <EXPR>, <EXPR> [, <EXPR> ]
964 : :
965 : : If the final integer expression is not present, a constant unity
966 : : expression is returned. We don't return MATCH_ERROR until after
967 : : the equals sign is seen. */
968 : :
969 : : match
970 : 41345 : gfc_match_iterator (gfc_iterator *iter, int init_flag)
971 : : {
972 : 41345 : char name[GFC_MAX_SYMBOL_LEN + 1];
973 : 41345 : gfc_expr *var, *e1, *e2, *e3;
974 : 41345 : locus start;
975 : 41345 : match m;
976 : :
977 : 41345 : e1 = e2 = e3 = NULL;
978 : :
979 : : /* Match the start of an iterator without affecting the symbol table. */
980 : :
981 : 41345 : start = gfc_current_locus;
982 : 41345 : m = gfc_match (" %n =", name);
983 : 41345 : gfc_current_locus = start;
984 : :
985 : 41345 : if (m != MATCH_YES)
986 : : return MATCH_NO;
987 : :
988 : 39705 : m = gfc_match_variable (&var, 0);
989 : 39705 : if (m != MATCH_YES)
990 : : return MATCH_NO;
991 : :
992 : 39705 : if (var->symtree->n.sym->attr.dimension)
993 : : {
994 : 4 : gfc_error ("Loop variable at %C cannot be an array");
995 : 4 : goto cleanup;
996 : : }
997 : :
998 : : /* F2008, C617 & C565. */
999 : 39701 : if (var->symtree->n.sym->attr.codimension)
1000 : : {
1001 : 1 : gfc_error ("Loop variable at %C cannot be a coarray");
1002 : 1 : goto cleanup;
1003 : : }
1004 : :
1005 : 39700 : if (var->ref != NULL)
1006 : : {
1007 : 0 : gfc_error ("Loop variable at %C cannot be a sub-component");
1008 : 0 : goto cleanup;
1009 : : }
1010 : :
1011 : 39700 : gfc_match_char ('=');
1012 : :
1013 : 39700 : var->symtree->n.sym->attr.implied_index = 1;
1014 : :
1015 : 39700 : m = init_flag ? gfc_match_init_expr (&e1) : gfc_match_expr (&e1);
1016 : 39700 : if (m == MATCH_NO)
1017 : 0 : goto syntax;
1018 : 39700 : if (m == MATCH_ERROR)
1019 : 0 : goto cleanup;
1020 : :
1021 : 39700 : if (gfc_match_char (',') != MATCH_YES)
1022 : 1 : goto syntax;
1023 : :
1024 : 39699 : m = init_flag ? gfc_match_init_expr (&e2) : gfc_match_expr (&e2);
1025 : 39699 : if (m == MATCH_NO)
1026 : 0 : goto syntax;
1027 : 39699 : if (m == MATCH_ERROR)
1028 : 0 : goto cleanup;
1029 : :
1030 : 39699 : if (gfc_match_char (',') != MATCH_YES)
1031 : : {
1032 : 36166 : e3 = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
1033 : 36166 : goto done;
1034 : : }
1035 : :
1036 : 3533 : m = init_flag ? gfc_match_init_expr (&e3) : gfc_match_expr (&e3);
1037 : 3533 : if (m == MATCH_ERROR)
1038 : 0 : goto cleanup;
1039 : 3533 : if (m == MATCH_NO)
1040 : : {
1041 : 0 : gfc_error ("Expected a step value in iterator at %C");
1042 : 0 : goto cleanup;
1043 : : }
1044 : :
1045 : 3533 : done:
1046 : 39699 : iter->var = var;
1047 : 39699 : iter->start = e1;
1048 : 39699 : iter->end = e2;
1049 : 39699 : iter->step = e3;
1050 : 39699 : return MATCH_YES;
1051 : :
1052 : 1 : syntax:
1053 : 1 : gfc_error ("Syntax error in iterator at %C");
1054 : :
1055 : 6 : cleanup:
1056 : 6 : gfc_free_expr (e1);
1057 : 6 : gfc_free_expr (e2);
1058 : 6 : gfc_free_expr (e3);
1059 : :
1060 : 6 : return MATCH_ERROR;
1061 : : }
1062 : :
1063 : :
1064 : : /* Tries to match the next non-whitespace character on the input.
1065 : : This subroutine does not return MATCH_ERROR.
1066 : : When gobble_ws is false, do not skip over leading blanks. */
1067 : :
1068 : : match
1069 : 39263438 : gfc_match_char (char c, bool gobble_ws)
1070 : : {
1071 : 39263438 : locus where;
1072 : :
1073 : 39263438 : where = gfc_current_locus;
1074 : 39263438 : if (gobble_ws)
1075 : 34927922 : gfc_gobble_whitespace ();
1076 : :
1077 : 39263438 : if (gfc_next_ascii_char () == c)
1078 : : return MATCH_YES;
1079 : :
1080 : 31956475 : gfc_current_locus = where;
1081 : 31956475 : return MATCH_NO;
1082 : : }
1083 : :
1084 : :
1085 : : /* General purpose matching subroutine. The target string is a
1086 : : scanf-like format string in which spaces correspond to arbitrary
1087 : : whitespace (including no whitespace), characters correspond to
1088 : : themselves. The %-codes are:
1089 : :
1090 : : %% Literal percent sign
1091 : : %e Expression, pointer to a pointer is set
1092 : : %s Symbol, pointer to the symbol is set (host_assoc = 0)
1093 : : %S Symbol, pointer to the symbol is set (host_assoc = 1)
1094 : : %n Name, character buffer is set to name
1095 : : %t Matches end of statement.
1096 : : %o Matches an intrinsic operator, returned as an INTRINSIC enum.
1097 : : %l Matches a statement label
1098 : : %v Matches a variable expression (an lvalue, except function references
1099 : : having a data pointer result)
1100 : : % Matches a required space (in free form) and optional spaces. */
1101 : :
1102 : : match
1103 : 86003884 : gfc_match (const char *target, ...)
1104 : : {
1105 : 86003884 : gfc_st_label **label;
1106 : 86003884 : int matches, *ip;
1107 : 86003884 : locus old_loc;
1108 : 86003884 : va_list argp;
1109 : 86003884 : char c, *np;
1110 : 86003884 : match m, n;
1111 : 86003884 : void **vp;
1112 : 86003884 : const char *p;
1113 : :
1114 : 86003884 : old_loc = gfc_current_locus;
1115 : 86003884 : va_start (argp, target);
1116 : 86003884 : m = MATCH_NO;
1117 : 86003884 : matches = 0;
1118 : 86003884 : p = target;
1119 : :
1120 : 368166283 : loop:
1121 : 368166283 : c = *p++;
1122 : 368166283 : switch (c)
1123 : : {
1124 : 107652111 : case ' ':
1125 : 107652111 : gfc_gobble_whitespace ();
1126 : 107652111 : goto loop;
1127 : : case '\0':
1128 : : m = MATCH_YES;
1129 : : break;
1130 : :
1131 : 21659800 : case '%':
1132 : 21659800 : c = *p++;
1133 : 21659800 : switch (c)
1134 : : {
1135 : 1914397 : case 'e':
1136 : 1914397 : vp = va_arg (argp, void **);
1137 : 1914397 : n = gfc_match_expr ((gfc_expr **) vp);
1138 : 1914397 : if (n != MATCH_YES)
1139 : : {
1140 : 606863 : m = n;
1141 : 606863 : goto not_yes;
1142 : : }
1143 : :
1144 : 1307534 : matches++;
1145 : 1307534 : goto loop;
1146 : :
1147 : 2621343 : case 'v':
1148 : 2621343 : vp = va_arg (argp, void **);
1149 : 2621343 : n = gfc_match_variable ((gfc_expr **) vp, 0);
1150 : 2621342 : if (n != MATCH_YES)
1151 : : {
1152 : 2411 : m = n;
1153 : 2411 : goto not_yes;
1154 : : }
1155 : :
1156 : 2618931 : matches++;
1157 : 2618931 : goto loop;
1158 : :
1159 : 28935 : case 's':
1160 : 28935 : case 'S':
1161 : 28935 : vp = va_arg (argp, void **);
1162 : 28935 : n = gfc_match_symbol ((gfc_symbol **) vp, c == 'S');
1163 : 28935 : if (n != MATCH_YES)
1164 : : {
1165 : 3 : m = n;
1166 : 3 : goto not_yes;
1167 : : }
1168 : :
1169 : 28932 : matches++;
1170 : 28932 : goto loop;
1171 : :
1172 : 12141738 : case 'n':
1173 : 12141738 : np = va_arg (argp, char *);
1174 : 12141738 : n = gfc_match_name (np);
1175 : 12141738 : if (n != MATCH_YES)
1176 : : {
1177 : 25551 : m = n;
1178 : 25551 : goto not_yes;
1179 : : }
1180 : :
1181 : 12116187 : matches++;
1182 : 12116187 : goto loop;
1183 : :
1184 : 221625 : case 'l':
1185 : 221625 : label = va_arg (argp, gfc_st_label **);
1186 : 221625 : n = gfc_match_st_label (label);
1187 : 221625 : if (n != MATCH_YES)
1188 : : {
1189 : 219353 : m = n;
1190 : 219353 : goto not_yes;
1191 : : }
1192 : :
1193 : 2272 : matches++;
1194 : 2272 : goto loop;
1195 : :
1196 : 1593 : case 'o':
1197 : 1593 : ip = va_arg (argp, int *);
1198 : 1593 : n = gfc_match_intrinsic_op ((gfc_intrinsic_op *) ip);
1199 : 1593 : if (n != MATCH_YES)
1200 : : {
1201 : 729 : m = n;
1202 : 729 : goto not_yes;
1203 : : }
1204 : :
1205 : 864 : matches++;
1206 : 864 : goto loop;
1207 : :
1208 : 363600 : case 't':
1209 : 363600 : if (gfc_match_eos () != MATCH_YES)
1210 : : {
1211 : 2320 : m = MATCH_NO;
1212 : 2320 : goto not_yes;
1213 : : }
1214 : 361280 : goto loop;
1215 : :
1216 : 330275 : case ' ':
1217 : 330275 : if (gfc_match_space () == MATCH_YES)
1218 : 326558 : goto loop;
1219 : 3717 : m = MATCH_NO;
1220 : 3717 : goto not_yes;
1221 : :
1222 : : case '%':
1223 : : break; /* Fall through to character matcher. */
1224 : :
1225 : 0 : default:
1226 : 0 : gfc_internal_error ("gfc_match(): Bad match code %c", c);
1227 : : }
1228 : : /* FALLTHRU */
1229 : :
1230 : 225585089 : default:
1231 : :
1232 : : /* gfc_next_ascii_char converts characters to lower-case, so we shouldn't
1233 : : expect an upper case character here! */
1234 : 225585089 : gcc_assert (TOLOWER (c) == c);
1235 : :
1236 : 225585089 : if (c == gfc_next_ascii_char ())
1237 : 157747730 : goto loop;
1238 : : break;
1239 : : }
1240 : :
1241 : 86003883 : not_yes:
1242 : 86003883 : va_end (argp);
1243 : :
1244 : 86003883 : if (m != MATCH_YES)
1245 : : {
1246 : : /* Clean up after a failed match. */
1247 : 68698306 : gfc_current_locus = old_loc;
1248 : 68698306 : va_start (argp, target);
1249 : :
1250 : 68698306 : p = target;
1251 : 76112913 : for (; matches > 0; matches--)
1252 : : {
1253 : 15103149 : while (*p++ != '%');
1254 : :
1255 : 7414607 : switch (*p++)
1256 : : {
1257 : 0 : case '%':
1258 : 0 : matches++;
1259 : 0 : break; /* Skip. */
1260 : :
1261 : : /* Matches that don't have to be undone */
1262 : 5095538 : case 'o':
1263 : 5095538 : case 'l':
1264 : 5095538 : case 'n':
1265 : 5095538 : case 's':
1266 : 5095538 : (void) va_arg (argp, void **);
1267 : 5095538 : break;
1268 : :
1269 : 2319069 : case 'e':
1270 : 2319069 : case 'v':
1271 : 2319069 : vp = va_arg (argp, void **);
1272 : 2319069 : gfc_free_expr ((struct gfc_expr *)*vp);
1273 : 2319069 : *vp = NULL;
1274 : 2319069 : break;
1275 : : }
1276 : : }
1277 : :
1278 : 68698306 : va_end (argp);
1279 : : }
1280 : :
1281 : 86003883 : return m;
1282 : : }
1283 : :
1284 : :
1285 : : /*********************** Statement level matching **********************/
1286 : :
1287 : : /* Matches the start of a program unit, which is the program keyword
1288 : : followed by an obligatory symbol. */
1289 : :
1290 : : match
1291 : 18399 : gfc_match_program (void)
1292 : : {
1293 : 18399 : gfc_symbol *sym;
1294 : 18399 : match m;
1295 : :
1296 : 18399 : m = gfc_match ("% %s%t", &sym);
1297 : :
1298 : 18399 : if (m == MATCH_NO)
1299 : : {
1300 : 0 : gfc_error ("Invalid form of PROGRAM statement at %C");
1301 : 0 : m = MATCH_ERROR;
1302 : : }
1303 : :
1304 : 18399 : if (m == MATCH_ERROR)
1305 : 0 : return m;
1306 : :
1307 : 18399 : if (!gfc_add_flavor (&sym->attr, FL_PROGRAM, sym->name, NULL))
1308 : : return MATCH_ERROR;
1309 : :
1310 : 18399 : gfc_new_block = sym;
1311 : :
1312 : 18399 : return MATCH_YES;
1313 : : }
1314 : :
1315 : :
1316 : : /* Match a simple assignment statement. */
1317 : :
1318 : : match
1319 : 1446715 : gfc_match_assignment (void)
1320 : : {
1321 : 1446715 : gfc_expr *lvalue, *rvalue;
1322 : 1446715 : locus old_loc;
1323 : 1446715 : match m;
1324 : :
1325 : 1446715 : old_loc = gfc_current_locus;
1326 : :
1327 : 1446715 : lvalue = NULL;
1328 : 1446715 : m = gfc_match (" %v =", &lvalue);
1329 : 1446714 : if (m != MATCH_YES)
1330 : : {
1331 : 1158295 : gfc_current_locus = old_loc;
1332 : 1158295 : gfc_free_expr (lvalue);
1333 : 1158295 : return MATCH_NO;
1334 : : }
1335 : :
1336 : 288419 : rvalue = NULL;
1337 : 288419 : m = gfc_match (" %e%t", &rvalue);
1338 : :
1339 : 288419 : if (m == MATCH_YES
1340 : 277087 : && rvalue->ts.type == BT_BOZ
1341 : 4 : && lvalue->ts.type == BT_CLASS)
1342 : : {
1343 : 1 : m = MATCH_ERROR;
1344 : 1 : gfc_error ("BOZ literal constant at %L is neither a DATA statement "
1345 : : "value nor an actual argument of INT/REAL/DBLE/CMPLX "
1346 : : "intrinsic subprogram", &rvalue->where);
1347 : : }
1348 : :
1349 : 288419 : if (lvalue->expr_type == EXPR_CONSTANT)
1350 : : {
1351 : : /* This clobbers %len and %kind. */
1352 : 6 : m = MATCH_ERROR;
1353 : 6 : gfc_error ("Assignment to a constant expression at %C");
1354 : : }
1355 : :
1356 : 288419 : if (m != MATCH_YES)
1357 : : {
1358 : 11338 : gfc_current_locus = old_loc;
1359 : 11338 : gfc_free_expr (lvalue);
1360 : 11338 : gfc_free_expr (rvalue);
1361 : 11338 : return m;
1362 : : }
1363 : :
1364 : 277081 : if (!lvalue->symtree)
1365 : : {
1366 : 0 : gfc_free_expr (lvalue);
1367 : 0 : gfc_free_expr (rvalue);
1368 : 0 : return MATCH_ERROR;
1369 : : }
1370 : :
1371 : :
1372 : 277081 : gfc_set_sym_referenced (lvalue->symtree->n.sym);
1373 : :
1374 : 277081 : new_st.op = EXEC_ASSIGN;
1375 : 277081 : new_st.expr1 = lvalue;
1376 : 277081 : new_st.expr2 = rvalue;
1377 : :
1378 : 277081 : gfc_check_do_variable (lvalue->symtree);
1379 : :
1380 : 277081 : return MATCH_YES;
1381 : : }
1382 : :
1383 : :
1384 : : /* Match a pointer assignment statement. */
1385 : :
1386 : : match
1387 : 1169633 : gfc_match_pointer_assignment (void)
1388 : : {
1389 : 1169633 : gfc_expr *lvalue, *rvalue;
1390 : 1169633 : locus old_loc;
1391 : 1169633 : match m;
1392 : :
1393 : 1169633 : old_loc = gfc_current_locus;
1394 : :
1395 : 1169633 : lvalue = rvalue = NULL;
1396 : 1169633 : gfc_matching_ptr_assignment = 0;
1397 : 1169633 : gfc_matching_procptr_assignment = 0;
1398 : :
1399 : 1169633 : m = gfc_match (" %v =>", &lvalue);
1400 : 1169633 : if (m != MATCH_YES || !lvalue->symtree)
1401 : : {
1402 : 1160659 : m = MATCH_NO;
1403 : 1160659 : goto cleanup;
1404 : : }
1405 : :
1406 : 8974 : if (lvalue->symtree->n.sym->attr.proc_pointer
1407 : 8974 : || gfc_is_proc_ptr_comp (lvalue))
1408 : 1244 : gfc_matching_procptr_assignment = 1;
1409 : : else
1410 : 7730 : gfc_matching_ptr_assignment = 1;
1411 : :
1412 : 8974 : m = gfc_match (" %e%t", &rvalue);
1413 : 8974 : gfc_matching_ptr_assignment = 0;
1414 : 8974 : gfc_matching_procptr_assignment = 0;
1415 : 8974 : if (m != MATCH_YES)
1416 : 1 : goto cleanup;
1417 : :
1418 : 8973 : new_st.op = EXEC_POINTER_ASSIGN;
1419 : 8973 : new_st.expr1 = lvalue;
1420 : 8973 : new_st.expr2 = rvalue;
1421 : :
1422 : 8973 : return MATCH_YES;
1423 : :
1424 : 1160660 : cleanup:
1425 : 1160660 : gfc_current_locus = old_loc;
1426 : 1160660 : gfc_free_expr (lvalue);
1427 : 1160660 : gfc_free_expr (rvalue);
1428 : 1160660 : return m;
1429 : : }
1430 : :
1431 : :
1432 : : /* We try to match an easy arithmetic IF statement. This only happens
1433 : : when just after having encountered a simple IF statement. This code
1434 : : is really duplicate with parts of the gfc_match_if code, but this is
1435 : : *much* easier. */
1436 : :
1437 : : static match
1438 : 24 : match_arithmetic_if (void)
1439 : : {
1440 : 24 : gfc_st_label *l1, *l2, *l3;
1441 : 24 : gfc_expr *expr;
1442 : 24 : match m;
1443 : :
1444 : 24 : m = gfc_match (" ( %e ) %l , %l , %l%t", &expr, &l1, &l2, &l3);
1445 : 24 : if (m != MATCH_YES)
1446 : : return m;
1447 : :
1448 : 24 : if (!gfc_reference_st_label (l1, ST_LABEL_TARGET)
1449 : 24 : || !gfc_reference_st_label (l2, ST_LABEL_TARGET)
1450 : 48 : || !gfc_reference_st_label (l3, ST_LABEL_TARGET))
1451 : : {
1452 : 0 : gfc_free_expr (expr);
1453 : 0 : return MATCH_ERROR;
1454 : : }
1455 : :
1456 : 24 : if (!gfc_notify_std (GFC_STD_F95_OBS | GFC_STD_F2018_DEL,
1457 : : "Arithmetic IF statement at %C"))
1458 : : return MATCH_ERROR;
1459 : :
1460 : 24 : new_st.op = EXEC_ARITHMETIC_IF;
1461 : 24 : new_st.expr1 = expr;
1462 : 24 : new_st.label1 = l1;
1463 : 24 : new_st.label2 = l2;
1464 : 24 : new_st.label3 = l3;
1465 : :
1466 : 24 : return MATCH_YES;
1467 : : }
1468 : :
1469 : :
1470 : : /* The IF statement is a bit of a pain. First of all, there are three
1471 : : forms of it, the simple IF, the IF that starts a block and the
1472 : : arithmetic IF.
1473 : :
1474 : : There is a problem with the simple IF and that is the fact that we
1475 : : only have a single level of undo information on symbols. What this
1476 : : means is for a simple IF, we must re-match the whole IF statement
1477 : : multiple times in order to guarantee that the symbol table ends up
1478 : : in the proper state. */
1479 : :
1480 : : static match match_simple_forall (void);
1481 : : static match match_simple_where (void);
1482 : :
1483 : : match
1484 : 720596 : gfc_match_if (gfc_statement *if_type)
1485 : : {
1486 : 720596 : gfc_expr *expr;
1487 : 720596 : gfc_st_label *l1, *l2, *l3;
1488 : 720596 : locus old_loc, old_loc2;
1489 : 720596 : gfc_code *p;
1490 : 720596 : match m, n;
1491 : :
1492 : 720596 : n = gfc_match_label ();
1493 : 720596 : if (n == MATCH_ERROR)
1494 : : return n;
1495 : :
1496 : 720588 : old_loc = gfc_current_locus;
1497 : :
1498 : 720588 : m = gfc_match (" if ", &expr);
1499 : 720588 : if (m != MATCH_YES)
1500 : : return m;
1501 : :
1502 : 219348 : if (gfc_match_char ('(') != MATCH_YES)
1503 : : {
1504 : 3 : gfc_error ("Missing %<(%> in IF-expression at %C");
1505 : 3 : return MATCH_ERROR;
1506 : : }
1507 : :
1508 : 219345 : m = gfc_match ("%e", &expr);
1509 : 219345 : if (m != MATCH_YES)
1510 : : return m;
1511 : :
1512 : 219323 : old_loc2 = gfc_current_locus;
1513 : 219323 : gfc_current_locus = old_loc;
1514 : :
1515 : 219323 : if (gfc_match_parens () == MATCH_ERROR)
1516 : : return MATCH_ERROR;
1517 : :
1518 : 219316 : gfc_current_locus = old_loc2;
1519 : :
1520 : 219316 : if (gfc_match_char (')') != MATCH_YES)
1521 : : {
1522 : 2 : gfc_error ("Syntax error in IF-expression at %C");
1523 : 2 : gfc_free_expr (expr);
1524 : 2 : return MATCH_ERROR;
1525 : : }
1526 : :
1527 : 219314 : m = gfc_match (" %l , %l , %l%t", &l1, &l2, &l3);
1528 : :
1529 : 219314 : if (m == MATCH_YES)
1530 : : {
1531 : 48 : if (n == MATCH_YES)
1532 : : {
1533 : 0 : gfc_error ("Block label not appropriate for arithmetic IF "
1534 : : "statement at %C");
1535 : 0 : gfc_free_expr (expr);
1536 : 0 : return MATCH_ERROR;
1537 : : }
1538 : :
1539 : 48 : if (!gfc_reference_st_label (l1, ST_LABEL_TARGET)
1540 : 48 : || !gfc_reference_st_label (l2, ST_LABEL_TARGET)
1541 : 96 : || !gfc_reference_st_label (l3, ST_LABEL_TARGET))
1542 : : {
1543 : 0 : gfc_free_expr (expr);
1544 : 0 : return MATCH_ERROR;
1545 : : }
1546 : :
1547 : 48 : if (!gfc_notify_std (GFC_STD_F95_OBS | GFC_STD_F2018_DEL,
1548 : : "Arithmetic IF statement at %C"))
1549 : : return MATCH_ERROR;
1550 : :
1551 : 48 : new_st.op = EXEC_ARITHMETIC_IF;
1552 : 48 : new_st.expr1 = expr;
1553 : 48 : new_st.label1 = l1;
1554 : 48 : new_st.label2 = l2;
1555 : 48 : new_st.label3 = l3;
1556 : :
1557 : 48 : *if_type = ST_ARITHMETIC_IF;
1558 : 48 : return MATCH_YES;
1559 : : }
1560 : :
1561 : 219266 : if (gfc_match (" then%t") == MATCH_YES)
1562 : : {
1563 : 14138 : new_st.op = EXEC_IF;
1564 : 14138 : new_st.expr1 = expr;
1565 : 14138 : *if_type = ST_IF_BLOCK;
1566 : 14138 : return MATCH_YES;
1567 : : }
1568 : :
1569 : 205128 : if (n == MATCH_YES)
1570 : : {
1571 : 0 : gfc_error ("Block label is not appropriate for IF statement at %C");
1572 : 0 : gfc_free_expr (expr);
1573 : 0 : return MATCH_ERROR;
1574 : : }
1575 : :
1576 : : /* At this point the only thing left is a simple IF statement. At
1577 : : this point, n has to be MATCH_NO, so we don't have to worry about
1578 : : re-matching a block label. From what we've got so far, try
1579 : : matching an assignment. */
1580 : :
1581 : 205128 : *if_type = ST_SIMPLE_IF;
1582 : :
1583 : 205128 : m = gfc_match_assignment ();
1584 : 205128 : if (m == MATCH_YES)
1585 : 4705 : goto got_match;
1586 : :
1587 : 200423 : gfc_free_expr (expr);
1588 : 200423 : gfc_undo_symbols ();
1589 : 200423 : gfc_current_locus = old_loc;
1590 : :
1591 : : /* m can be MATCH_NO or MATCH_ERROR, here. For MATCH_ERROR, a mangled
1592 : : assignment was found. For MATCH_NO, continue to call the various
1593 : : matchers. */
1594 : 200423 : if (m == MATCH_ERROR)
1595 : : return MATCH_ERROR;
1596 : :
1597 : 200423 : gfc_match (" if ( %e ) ", &expr); /* Guaranteed to match. */
1598 : :
1599 : 200423 : m = gfc_match_pointer_assignment ();
1600 : 200423 : if (m == MATCH_YES)
1601 : 68 : goto got_match;
1602 : :
1603 : 200355 : gfc_free_expr (expr);
1604 : 200355 : gfc_undo_symbols ();
1605 : 200355 : gfc_current_locus = old_loc;
1606 : :
1607 : 200355 : gfc_match (" if ( %e ) ", &expr); /* Guaranteed to match. */
1608 : :
1609 : : /* Look at the next keyword to see which matcher to call. Matching
1610 : : the keyword doesn't affect the symbol table, so we don't have to
1611 : : restore between tries. */
1612 : :
1613 : : #define match(string, subr, statement) \
1614 : : if (gfc_match (string) == MATCH_YES) { m = subr(); goto got_match; }
1615 : :
1616 : 200355 : gfc_clear_error ();
1617 : :
1618 : 200355 : match ("allocate", gfc_match_allocate, ST_ALLOCATE)
1619 : 200279 : match ("assign", gfc_match_assign, ST_LABEL_ASSIGNMENT)
1620 : 200277 : match ("backspace", gfc_match_backspace, ST_BACKSPACE)
1621 : 200271 : match ("call", gfc_match_call, ST_CALL)
1622 : 199591 : match ("change% team", gfc_match_change_team, ST_CHANGE_TEAM)
1623 : 199591 : match ("close", gfc_match_close, ST_CLOSE)
1624 : 199591 : match ("continue", gfc_match_continue, ST_CONTINUE)
1625 : 199591 : match ("cycle", gfc_match_cycle, ST_CYCLE)
1626 : 199502 : match ("deallocate", gfc_match_deallocate, ST_DEALLOCATE)
1627 : 199117 : match ("end file", gfc_match_endfile, ST_END_FILE)
1628 : 199117 : match ("end team", gfc_match_end_team, ST_END_TEAM)
1629 : 199117 : match ("error% stop", gfc_match_error_stop, ST_ERROR_STOP)
1630 : 161478 : match ("event% post", gfc_match_event_post, ST_EVENT_POST)
1631 : 161478 : match ("event% wait", gfc_match_event_wait, ST_EVENT_WAIT)
1632 : 161478 : match ("exit", gfc_match_exit, ST_EXIT)
1633 : 161175 : match ("fail% image", gfc_match_fail_image, ST_FAIL_IMAGE)
1634 : 161174 : match ("flush", gfc_match_flush, ST_FLUSH)
1635 : 161174 : match ("forall", match_simple_forall, ST_FORALL)
1636 : 161168 : match ("form% team", gfc_match_form_team, ST_FORM_TEAM)
1637 : 161168 : match ("go to", gfc_match_goto, ST_GOTO)
1638 : 160790 : match ("if", match_arithmetic_if, ST_ARITHMETIC_IF)
1639 : 160766 : match ("inquire", gfc_match_inquire, ST_INQUIRE)
1640 : 160766 : match ("lock", gfc_match_lock, ST_LOCK)
1641 : 160766 : match ("nullify", gfc_match_nullify, ST_NULLIFY)
1642 : 160766 : match ("open", gfc_match_open, ST_OPEN)
1643 : 160766 : match ("pause", gfc_match_pause, ST_NONE)
1644 : 160766 : match ("print", gfc_match_print, ST_WRITE)
1645 : 160365 : match ("read", gfc_match_read, ST_READ)
1646 : 160363 : match ("return", gfc_match_return, ST_RETURN)
1647 : 159983 : match ("rewind", gfc_match_rewind, ST_REWIND)
1648 : 159983 : match ("stop", gfc_match_stop, ST_STOP)
1649 : 377 : match ("wait", gfc_match_wait, ST_WAIT)
1650 : 377 : match ("sync% all", gfc_match_sync_all, ST_SYNC_CALL);
1651 : 377 : match ("sync% images", gfc_match_sync_images, ST_SYNC_IMAGES);
1652 : 377 : match ("sync% memory", gfc_match_sync_memory, ST_SYNC_MEMORY);
1653 : 377 : match ("sync% team", gfc_match_sync_team, ST_SYNC_TEAM)
1654 : 377 : match ("unlock", gfc_match_unlock, ST_UNLOCK)
1655 : 377 : match ("where", match_simple_where, ST_WHERE)
1656 : 370 : match ("write", gfc_match_write, ST_WRITE)
1657 : :
1658 : 6 : if (flag_dec)
1659 : 1 : match ("type", gfc_match_print, ST_WRITE)
1660 : :
1661 : : /* All else has failed, so give up. See if any of the matchers has
1662 : : stored an error message of some sort. */
1663 : 5 : if (!gfc_error_check ())
1664 : 5 : gfc_error ("Syntax error in IF-clause after %C");
1665 : :
1666 : 5 : gfc_free_expr (expr);
1667 : 5 : return MATCH_ERROR;
1668 : :
1669 : 205123 : got_match:
1670 : 205123 : if (m == MATCH_NO)
1671 : 0 : gfc_error ("Syntax error in IF-clause after %C");
1672 : 205123 : if (m != MATCH_YES)
1673 : : {
1674 : 77 : gfc_free_expr (expr);
1675 : 77 : return MATCH_ERROR;
1676 : : }
1677 : :
1678 : : /* At this point, we've matched the single IF and the action clause
1679 : : is in new_st. Rearrange things so that the IF statement appears
1680 : : in new_st. */
1681 : :
1682 : 205046 : p = gfc_get_code (EXEC_IF);
1683 : 205046 : p->next = XCNEW (gfc_code);
1684 : 205046 : *p->next = new_st;
1685 : 205046 : p->next->loc = gfc_current_locus;
1686 : :
1687 : 205046 : p->expr1 = expr;
1688 : :
1689 : 205046 : gfc_clear_new_st ();
1690 : :
1691 : 205046 : new_st.op = EXEC_IF;
1692 : 205046 : new_st.block = p;
1693 : :
1694 : 205046 : return MATCH_YES;
1695 : : }
1696 : :
1697 : : #undef match
1698 : :
1699 : :
1700 : : /* Match an ELSE statement. */
1701 : :
1702 : : match
1703 : 6168 : gfc_match_else (void)
1704 : : {
1705 : 6168 : char name[GFC_MAX_SYMBOL_LEN + 1];
1706 : :
1707 : 6168 : if (gfc_match_eos () == MATCH_YES)
1708 : : return MATCH_YES;
1709 : :
1710 : 2250 : if (gfc_match_name (name) != MATCH_YES
1711 : 2249 : || gfc_current_block () == NULL
1712 : 2267 : || gfc_match_eos () != MATCH_YES)
1713 : : {
1714 : 2248 : gfc_error ("Invalid character(s) in ELSE statement after %C");
1715 : 2248 : return MATCH_ERROR;
1716 : : }
1717 : :
1718 : 2 : if (strcmp (name, gfc_current_block ()->name) != 0)
1719 : : {
1720 : 1 : gfc_error ("Label %qs at %C doesn't match IF label %qs",
1721 : : name, gfc_current_block ()->name);
1722 : 1 : return MATCH_ERROR;
1723 : : }
1724 : :
1725 : : return MATCH_YES;
1726 : : }
1727 : :
1728 : :
1729 : : /* Match an ELSE IF statement. */
1730 : :
1731 : : match
1732 : 1933 : gfc_match_elseif (void)
1733 : : {
1734 : 1933 : char name[GFC_MAX_SYMBOL_LEN + 1];
1735 : 1933 : gfc_expr *expr, *then;
1736 : 1933 : locus where;
1737 : 1933 : match m;
1738 : :
1739 : 1933 : if (gfc_match_char ('(') != MATCH_YES)
1740 : : {
1741 : 1 : gfc_error ("Missing %<(%> in ELSE IF expression at %C");
1742 : 1 : return MATCH_ERROR;
1743 : : }
1744 : :
1745 : 1932 : m = gfc_match (" %e ", &expr);
1746 : 1932 : if (m != MATCH_YES)
1747 : : return m;
1748 : :
1749 : 1932 : if (gfc_match_char (')') != MATCH_YES)
1750 : : {
1751 : 1 : gfc_error ("Missing %<)%> in ELSE IF expression at %C");
1752 : 1 : goto cleanup;
1753 : : }
1754 : :
1755 : 1931 : m = gfc_match (" then ", &then);
1756 : :
1757 : 1931 : where = gfc_current_locus;
1758 : :
1759 : 1931 : if (m == MATCH_YES && (gfc_match_eos () == MATCH_YES
1760 : 3 : || (gfc_current_block ()
1761 : 2 : && gfc_match_name (name) == MATCH_YES)))
1762 : 1928 : goto done;
1763 : :
1764 : 3 : if (gfc_match_eos () == MATCH_YES)
1765 : : {
1766 : 1 : gfc_error ("Missing THEN in ELSE IF statement after %L", &where);
1767 : 1 : goto cleanup;
1768 : : }
1769 : :
1770 : 2 : if (gfc_match_name (name) != MATCH_YES
1771 : 2 : || gfc_current_block () == NULL
1772 : 3 : || gfc_match_eos () != MATCH_YES)
1773 : : {
1774 : 1 : gfc_error ("Syntax error in ELSE IF statement after %L", &where);
1775 : 1 : goto cleanup;
1776 : : }
1777 : :
1778 : 1 : if (strcmp (name, gfc_current_block ()->name) != 0)
1779 : : {
1780 : 1 : gfc_error ("Label %qs after %L doesn't match IF label %qs",
1781 : : name, &where, gfc_current_block ()->name);
1782 : 1 : goto cleanup;
1783 : : }
1784 : :
1785 : 0 : if (m != MATCH_YES)
1786 : : return m;
1787 : :
1788 : 0 : done:
1789 : 1928 : new_st.op = EXEC_IF;
1790 : 1928 : new_st.expr1 = expr;
1791 : 1928 : return MATCH_YES;
1792 : :
1793 : 4 : cleanup:
1794 : 4 : gfc_free_expr (expr);
1795 : 4 : return MATCH_ERROR;
1796 : : }
1797 : :
1798 : :
1799 : : /* Free a gfc_iterator structure. */
1800 : :
1801 : : void
1802 : 91936 : gfc_free_iterator (gfc_iterator *iter, int flag)
1803 : : {
1804 : :
1805 : 91936 : if (iter == NULL)
1806 : : return;
1807 : :
1808 : 52141 : gfc_free_expr (iter->var);
1809 : 52141 : gfc_free_expr (iter->start);
1810 : 52141 : gfc_free_expr (iter->end);
1811 : 52141 : gfc_free_expr (iter->step);
1812 : :
1813 : 52141 : if (flag)
1814 : 47069 : free (iter);
1815 : : }
1816 : :
1817 : :
1818 : : /* Match a CRITICAL statement. */
1819 : : match
1820 : 464315 : gfc_match_critical (void)
1821 : : {
1822 : 464315 : gfc_st_label *label = NULL;
1823 : :
1824 : 464315 : if (gfc_match_label () == MATCH_ERROR)
1825 : : return MATCH_ERROR;
1826 : :
1827 : 464307 : if (gfc_match (" critical") != MATCH_YES)
1828 : : return MATCH_NO;
1829 : :
1830 : 40 : if (gfc_match_st_label (&label) == MATCH_ERROR)
1831 : : return MATCH_ERROR;
1832 : :
1833 : 40 : if (gfc_match_eos () != MATCH_YES)
1834 : : {
1835 : 1 : gfc_syntax_error (ST_CRITICAL);
1836 : 1 : return MATCH_ERROR;
1837 : : }
1838 : :
1839 : 39 : if (gfc_pure (NULL))
1840 : : {
1841 : 1 : gfc_error ("Image control statement CRITICAL at %C in PURE procedure");
1842 : 1 : return MATCH_ERROR;
1843 : : }
1844 : :
1845 : 38 : if (gfc_find_state (COMP_DO_CONCURRENT))
1846 : : {
1847 : 1 : gfc_error ("Image control statement CRITICAL at %C in DO CONCURRENT "
1848 : : "block");
1849 : 1 : return MATCH_ERROR;
1850 : : }
1851 : :
1852 : 37 : gfc_unset_implicit_pure (NULL);
1853 : :
1854 : 37 : if (!gfc_notify_std (GFC_STD_F2008, "CRITICAL statement at %C"))
1855 : : return MATCH_ERROR;
1856 : :
1857 : 36 : if (flag_coarray == GFC_FCOARRAY_NONE)
1858 : : {
1859 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to "
1860 : : "enable");
1861 : : return MATCH_ERROR;
1862 : : }
1863 : :
1864 : 36 : if (gfc_find_state (COMP_CRITICAL))
1865 : : {
1866 : 1 : gfc_error ("Nested CRITICAL block at %C");
1867 : 1 : return MATCH_ERROR;
1868 : : }
1869 : :
1870 : 35 : new_st.op = EXEC_CRITICAL;
1871 : :
1872 : 35 : if (label != NULL
1873 : 35 : && !gfc_reference_st_label (label, ST_LABEL_TARGET))
1874 : : return MATCH_ERROR;
1875 : :
1876 : : return MATCH_YES;
1877 : : }
1878 : :
1879 : :
1880 : : /* Match a BLOCK statement. */
1881 : :
1882 : : match
1883 : 466870 : gfc_match_block (void)
1884 : : {
1885 : 466870 : match m;
1886 : :
1887 : 466870 : if (gfc_match_label () == MATCH_ERROR)
1888 : : return MATCH_ERROR;
1889 : :
1890 : 466862 : if (gfc_match (" block") != MATCH_YES)
1891 : : return MATCH_NO;
1892 : :
1893 : : /* For this to be a correct BLOCK statement, the line must end now. */
1894 : 1348 : m = gfc_match_eos ();
1895 : 1348 : if (m == MATCH_ERROR)
1896 : : return MATCH_ERROR;
1897 : 1348 : if (m == MATCH_NO)
1898 : : return MATCH_NO;
1899 : :
1900 : : return MATCH_YES;
1901 : : }
1902 : :
1903 : :
1904 : : /* Match an ASSOCIATE statement. */
1905 : :
1906 : : match
1907 : 465608 : gfc_match_associate (void)
1908 : : {
1909 : 465608 : if (gfc_match_label () == MATCH_ERROR)
1910 : : return MATCH_ERROR;
1911 : :
1912 : 465600 : if (gfc_match (" associate") != MATCH_YES)
1913 : : return MATCH_NO;
1914 : :
1915 : : /* Match the association list. */
1916 : 1309 : if (gfc_match_char ('(') != MATCH_YES)
1917 : : {
1918 : 1 : gfc_error ("Expected association list at %C");
1919 : 1 : return MATCH_ERROR;
1920 : : }
1921 : 1308 : new_st.ext.block.assoc = NULL;
1922 : 1528 : while (true)
1923 : : {
1924 : 1418 : gfc_association_list* newAssoc = gfc_get_association_list ();
1925 : 1418 : gfc_association_list* a;
1926 : :
1927 : : /* Match the next association. */
1928 : 1418 : if (gfc_match (" %n ", newAssoc->name) != MATCH_YES)
1929 : : {
1930 : 3 : gfc_error ("Expected associate name at %C");
1931 : 3 : goto assocListError;
1932 : : }
1933 : :
1934 : : /* Required for an assumed rank target. */
1935 : 1415 : if (gfc_peek_char () == '(')
1936 : : {
1937 : 26 : newAssoc->ar = gfc_get_array_ref ();
1938 : 26 : if (gfc_match_array_ref (newAssoc->ar, NULL, 0, 0) != MATCH_YES)
1939 : : {
1940 : 0 : gfc_error ("Bad bounds remapping list at %C");
1941 : 0 : goto assocListError;
1942 : : }
1943 : : }
1944 : :
1945 : 1415 : if (newAssoc->ar && !(gfc_option.allow_std & GFC_STD_F202Y))
1946 : 2 : gfc_error_now ("The bounds remapping list at %C is an experimental "
1947 : : "F202y feature. Use std=f202y to enable");
1948 : :
1949 : : /* Match the next association. */
1950 : 1415 : if (gfc_match (" =>", newAssoc->name) != MATCH_YES)
1951 : : {
1952 : 0 : gfc_error ("Expected association at %C");
1953 : 0 : goto assocListError;
1954 : : }
1955 : :
1956 : 1415 : if (gfc_match (" %e", &newAssoc->target) != MATCH_YES)
1957 : : {
1958 : : /* Have another go, allowing for procedure pointer selectors. */
1959 : 22 : gfc_matching_procptr_assignment = 1;
1960 : 22 : if (gfc_match (" %e", &newAssoc->target) != MATCH_YES)
1961 : : {
1962 : 8 : gfc_matching_procptr_assignment = 0;
1963 : 8 : gfc_error ("Invalid association target at %C");
1964 : 8 : goto assocListError;
1965 : : }
1966 : 14 : gfc_matching_procptr_assignment = 0;
1967 : : }
1968 : 1407 : newAssoc->where = gfc_current_locus;
1969 : :
1970 : : /* Check that the current name is not yet in the list. */
1971 : 1535 : for (a = new_st.ext.block.assoc; a; a = a->next)
1972 : 129 : if (!strcmp (a->name, newAssoc->name))
1973 : : {
1974 : 1 : gfc_error ("Duplicate name %qs in association at %C",
1975 : : newAssoc->name);
1976 : 1 : goto assocListError;
1977 : : }
1978 : :
1979 : : /* The target expression must not be coindexed. */
1980 : 1406 : if (gfc_is_coindexed (newAssoc->target))
1981 : : {
1982 : 1 : gfc_error ("Association target at %C must not be coindexed");
1983 : 1 : goto assocListError;
1984 : : }
1985 : :
1986 : : /* The target expression cannot be a BOZ literal constant. */
1987 : 1405 : if (newAssoc->target->ts.type == BT_BOZ)
1988 : : {
1989 : 1 : gfc_error ("Association target at %L cannot be a BOZ literal "
1990 : : "constant", &newAssoc->target->where);
1991 : 1 : goto assocListError;
1992 : : }
1993 : :
1994 : 1404 : if (newAssoc->target->expr_type == EXPR_VARIABLE
1995 : 750 : && newAssoc->target->symtree->n.sym->as
1996 : 361 : && newAssoc->target->symtree->n.sym->as->type == AS_ASSUMED_RANK)
1997 : : {
1998 : 14 : bool bounds_remapping_list = true;
1999 : 14 : if (!newAssoc->ar)
2000 : : bounds_remapping_list = false;
2001 : : else
2002 : 35 : for (int dim = 0; dim < newAssoc->ar->dimen; dim++)
2003 : 21 : if (!newAssoc->ar->start[dim] || !newAssoc->ar->end[dim]
2004 : 21 : || newAssoc->ar->stride[dim] != NULL)
2005 : 0 : bounds_remapping_list = false;
2006 : :
2007 : 14 : if (!bounds_remapping_list)
2008 : : {
2009 : 0 : gfc_error ("The associate name %s with an assumed rank "
2010 : : "target at %L must have a bounds remapping list "
2011 : : "(list of lbound:ubound for each dimension)",
2012 : : newAssoc->name, &newAssoc->target->where);
2013 : 0 : goto assocListError;
2014 : : }
2015 : :
2016 : 14 : if (!newAssoc->target->symtree->n.sym->attr.contiguous)
2017 : : {
2018 : 0 : gfc_error ("The assumed rank target at %C must be contiguous");
2019 : 0 : goto assocListError;
2020 : : }
2021 : : }
2022 : :
2023 : : /* The `variable' field is left blank for now; because the target is not
2024 : : yet resolved, we can't use gfc_has_vector_subscript to determine it
2025 : : for now. This is set during resolution. */
2026 : :
2027 : : /* Put it into the list. */
2028 : 1404 : newAssoc->next = new_st.ext.block.assoc;
2029 : 1404 : new_st.ext.block.assoc = newAssoc;
2030 : :
2031 : : /* Try next one or end if closing parenthesis is found. */
2032 : 1404 : gfc_gobble_whitespace ();
2033 : 1404 : if (gfc_peek_char () == ')')
2034 : : break;
2035 : 110 : if (gfc_match_char (',') != MATCH_YES)
2036 : : {
2037 : 0 : gfc_error ("Expected %<)%> or %<,%> at %C");
2038 : 0 : return MATCH_ERROR;
2039 : : }
2040 : :
2041 : 110 : continue;
2042 : :
2043 : 14 : assocListError:
2044 : 14 : free (newAssoc);
2045 : 14 : goto error;
2046 : 110 : }
2047 : 1294 : if (gfc_match_char (')') != MATCH_YES)
2048 : : {
2049 : : /* This should never happen as we peek above. */
2050 : 0 : gcc_unreachable ();
2051 : : }
2052 : :
2053 : 1294 : if (gfc_match_eos () != MATCH_YES)
2054 : : {
2055 : 1 : gfc_error ("Junk after ASSOCIATE statement at %C");
2056 : 1 : goto error;
2057 : : }
2058 : :
2059 : : return MATCH_YES;
2060 : :
2061 : 15 : error:
2062 : 15 : gfc_free_association_list (new_st.ext.block.assoc);
2063 : 15 : return MATCH_ERROR;
2064 : : }
2065 : :
2066 : :
2067 : : /* Match a Fortran 2003 derived-type-spec (F03:R455), which is just the name of
2068 : : an accessible derived type. */
2069 : :
2070 : : static match
2071 : 31390 : match_derived_type_spec (gfc_typespec *ts)
2072 : : {
2073 : 31390 : char name[GFC_MAX_SYMBOL_LEN + 1];
2074 : 31390 : locus old_locus;
2075 : 31390 : gfc_symbol *derived, *der_type;
2076 : 31390 : match m = MATCH_YES;
2077 : 31390 : gfc_actual_arglist *decl_type_param_list = NULL;
2078 : 31390 : bool is_pdt_template = false;
2079 : :
2080 : 31390 : old_locus = gfc_current_locus;
2081 : :
2082 : 31390 : if (gfc_match ("%n", name) != MATCH_YES)
2083 : : {
2084 : 1 : gfc_current_locus = old_locus;
2085 : 1 : return MATCH_NO;
2086 : : }
2087 : :
2088 : 31389 : gfc_find_symbol (name, NULL, 1, &derived);
2089 : :
2090 : : /* Match the PDT spec list, if there. */
2091 : 31389 : if (derived && derived->attr.flavor == FL_PROCEDURE)
2092 : : {
2093 : 6621 : gfc_find_symbol (gfc_dt_upper_string (name), NULL, 1, &der_type);
2094 : 6621 : is_pdt_template = der_type
2095 : : && der_type->attr.flavor == FL_DERIVED
2096 : 6621 : && der_type->attr.pdt_template;
2097 : : }
2098 : :
2099 : 70 : if (is_pdt_template)
2100 : 70 : m = gfc_match_actual_arglist (1, &decl_type_param_list, true);
2101 : :
2102 : 7357 : if (m == MATCH_ERROR)
2103 : : {
2104 : 0 : gfc_free_actual_arglist (decl_type_param_list);
2105 : 0 : return m;
2106 : : }
2107 : :
2108 : 31389 : if (derived && derived->attr.flavor == FL_PROCEDURE && derived->attr.generic)
2109 : 4574 : derived = gfc_find_dt_in_generic (derived);
2110 : :
2111 : : /* If this is a PDT, find the specific instance. */
2112 : 31389 : if (m == MATCH_YES && is_pdt_template)
2113 : : {
2114 : 70 : gfc_namespace *old_ns;
2115 : :
2116 : 70 : old_ns = gfc_current_ns;
2117 : 107 : while (gfc_current_ns && gfc_current_ns->parent)
2118 : 37 : gfc_current_ns = gfc_current_ns->parent;
2119 : :
2120 : 70 : if (type_param_spec_list)
2121 : 0 : gfc_free_actual_arglist (type_param_spec_list);
2122 : 70 : m = gfc_get_pdt_instance (decl_type_param_list, &der_type,
2123 : : &type_param_spec_list);
2124 : 70 : gfc_free_actual_arglist (decl_type_param_list);
2125 : :
2126 : 70 : if (m != MATCH_YES)
2127 : : return m;
2128 : 69 : derived = der_type;
2129 : 69 : gcc_assert (!derived->attr.pdt_template && derived->attr.pdt_type);
2130 : 69 : gfc_set_sym_referenced (derived);
2131 : :
2132 : 69 : gfc_current_ns = old_ns;
2133 : : }
2134 : :
2135 : 31388 : if (derived && derived->attr.flavor == FL_DERIVED)
2136 : : {
2137 : 4549 : ts->type = BT_DERIVED;
2138 : 4549 : ts->u.derived = derived;
2139 : 4549 : return MATCH_YES;
2140 : : }
2141 : :
2142 : 26839 : gfc_current_locus = old_locus;
2143 : 26839 : return MATCH_NO;
2144 : : }
2145 : :
2146 : :
2147 : : /* Match a Fortran 2003 type-spec (F03:R401). This is similar to
2148 : : gfc_match_decl_type_spec() from decl.cc, with the following exceptions:
2149 : : It only includes the intrinsic types from the Fortran 2003 standard
2150 : : (thus, neither BYTE nor forms like REAL*4 are allowed). Additionally,
2151 : : the implicit_flag is not needed, so it was removed. Derived types are
2152 : : identified by their name alone. */
2153 : :
2154 : : match
2155 : 141707 : gfc_match_type_spec (gfc_typespec *ts)
2156 : : {
2157 : 141707 : match m;
2158 : 141707 : locus old_locus;
2159 : 141707 : char c, name[GFC_MAX_SYMBOL_LEN + 1];
2160 : :
2161 : 141707 : gfc_clear_ts (ts);
2162 : 141707 : gfc_gobble_whitespace ();
2163 : 141707 : old_locus = gfc_current_locus;
2164 : :
2165 : : /* If c isn't [a-z], then return immediately. */
2166 : 141707 : c = gfc_peek_ascii_char ();
2167 : 141707 : if (!ISALPHA(c))
2168 : : return MATCH_NO;
2169 : :
2170 : 31072 : type_param_spec_list = NULL;
2171 : :
2172 : 31072 : if (match_derived_type_spec (ts) == MATCH_YES)
2173 : : {
2174 : : /* Enforce F03:C401. */
2175 : 4235 : if (ts->u.derived->attr.abstract)
2176 : : {
2177 : 1 : gfc_error ("Derived type %qs at %L may not be ABSTRACT",
2178 : : ts->u.derived->name, &old_locus);
2179 : 1 : return MATCH_ERROR;
2180 : : }
2181 : : return MATCH_YES;
2182 : : }
2183 : :
2184 : 26837 : if (gfc_match ("integer") == MATCH_YES)
2185 : : {
2186 : 1471 : ts->type = BT_INTEGER;
2187 : 1471 : ts->kind = gfc_default_integer_kind;
2188 : 1471 : goto kind_selector;
2189 : : }
2190 : :
2191 : 25366 : if (flag_unsigned && gfc_match ("unsigned") == MATCH_YES)
2192 : : {
2193 : 6 : ts->type = BT_UNSIGNED;
2194 : 6 : ts->kind = gfc_default_integer_kind;
2195 : 6 : goto kind_selector;
2196 : : }
2197 : :
2198 : 25360 : if (gfc_match ("double precision") == MATCH_YES)
2199 : : {
2200 : 59 : ts->type = BT_REAL;
2201 : 59 : ts->kind = gfc_default_double_kind;
2202 : 59 : return MATCH_YES;
2203 : : }
2204 : :
2205 : 25301 : if (gfc_match ("complex") == MATCH_YES)
2206 : : {
2207 : 103 : ts->type = BT_COMPLEX;
2208 : 103 : ts->kind = gfc_default_complex_kind;
2209 : 103 : goto kind_selector;
2210 : : }
2211 : :
2212 : 25198 : if (gfc_match ("character") == MATCH_YES)
2213 : : {
2214 : 1908 : ts->type = BT_CHARACTER;
2215 : :
2216 : 1908 : m = gfc_match_char_spec (ts);
2217 : :
2218 : 1908 : if (m == MATCH_NO)
2219 : 0 : m = MATCH_YES;
2220 : :
2221 : 1908 : return m;
2222 : : }
2223 : :
2224 : : /* REAL is a real pain because it can be a type, intrinsic subprogram,
2225 : : or list item in a type-list of an OpenMP reduction clause. Need to
2226 : : differentiate REAL([KIND]=scalar-int-initialization-expr) from
2227 : : REAL(A,[KIND]) and REAL(KIND,A). Logically, when this code was
2228 : : written the use of LOGICAL as a type-spec or intrinsic subprogram
2229 : : was overlooked. */
2230 : :
2231 : 23290 : m = gfc_match (" %n", name);
2232 : 23290 : if (m == MATCH_YES
2233 : 23289 : && (strcmp (name, "real") == 0 || strcmp (name, "logical") == 0))
2234 : : {
2235 : 3390 : char c;
2236 : 3390 : gfc_expr *e;
2237 : 3390 : locus where;
2238 : :
2239 : 3390 : if (*name == 'r')
2240 : : {
2241 : 2896 : ts->type = BT_REAL;
2242 : 2896 : ts->kind = gfc_default_real_kind;
2243 : : }
2244 : : else
2245 : : {
2246 : 494 : ts->type = BT_LOGICAL;
2247 : 494 : ts->kind = gfc_default_logical_kind;
2248 : : }
2249 : :
2250 : 3390 : gfc_gobble_whitespace ();
2251 : :
2252 : : /* Prevent REAL*4, etc. */
2253 : 3390 : c = gfc_peek_ascii_char ();
2254 : 3390 : if (c == '*')
2255 : : {
2256 : 4 : gfc_error ("Invalid type-spec at %C");
2257 : 3390 : return MATCH_ERROR;
2258 : : }
2259 : :
2260 : : /* Found leading colon in REAL::, a trailing ')' in for example
2261 : : TYPE IS (REAL), or REAL, for an OpenMP list-item. */
2262 : 3386 : if (c == ':' || c == ')' || (flag_openmp && c == ','))
2263 : : return MATCH_YES;
2264 : :
2265 : : /* Found something other than the opening '(' in REAL(... */
2266 : 526 : if (c != '(')
2267 : : return MATCH_NO;
2268 : : else
2269 : 526 : gfc_next_char (); /* Burn the '('. */
2270 : :
2271 : : /* Look for the optional KIND=. */
2272 : 526 : where = gfc_current_locus;
2273 : 526 : m = gfc_match ("%n", name);
2274 : 526 : if (m == MATCH_YES)
2275 : : {
2276 : 384 : gfc_gobble_whitespace ();
2277 : 384 : c = gfc_next_char ();
2278 : 384 : if (c == '=')
2279 : : {
2280 : 144 : if (strcmp(name, "a") == 0 || strcmp(name, "l") == 0)
2281 : : return MATCH_NO;
2282 : 140 : else if (strcmp(name, "kind") == 0)
2283 : 140 : goto found;
2284 : : else
2285 : : return MATCH_ERROR;
2286 : : }
2287 : : else
2288 : 240 : gfc_current_locus = where;
2289 : : }
2290 : : else
2291 : 142 : gfc_current_locus = where;
2292 : :
2293 : 522 : found:
2294 : :
2295 : 522 : m = gfc_match_expr (&e);
2296 : 522 : if (m == MATCH_NO || m == MATCH_ERROR)
2297 : : return m;
2298 : :
2299 : : /* If a comma appears, it is an intrinsic subprogram. */
2300 : 522 : gfc_gobble_whitespace ();
2301 : 522 : c = gfc_peek_ascii_char ();
2302 : 522 : if (c == ',')
2303 : : {
2304 : 11 : gfc_free_expr (e);
2305 : 11 : return MATCH_NO;
2306 : : }
2307 : :
2308 : : /* If ')' appears, we have REAL(initialization-expr), here check for
2309 : : a scalar integer initialization-expr and valid kind parameter. */
2310 : 511 : if (c == ')')
2311 : : {
2312 : 511 : bool ok = true;
2313 : 511 : if (e->expr_type != EXPR_CONSTANT && e->expr_type != EXPR_VARIABLE)
2314 : 7 : ok = gfc_reduce_init_expr (e);
2315 : 511 : if (!ok || e->ts.type != BT_INTEGER || e->rank > 0)
2316 : : {
2317 : 3 : gfc_free_expr (e);
2318 : 3 : return MATCH_NO;
2319 : : }
2320 : :
2321 : 508 : if (e->expr_type != EXPR_CONSTANT)
2322 : 4 : goto ohno;
2323 : :
2324 : 504 : gfc_next_char (); /* Burn the ')'. */
2325 : 504 : ts->kind = (int) mpz_get_si (e->value.integer);
2326 : 504 : if (gfc_validate_kind (ts->type, ts->kind , true) == -1)
2327 : : {
2328 : 1 : gfc_error ("Invalid type-spec at %C");
2329 : 1 : return MATCH_ERROR;
2330 : : }
2331 : :
2332 : 503 : gfc_free_expr (e);
2333 : :
2334 : 503 : return MATCH_YES;
2335 : : }
2336 : : }
2337 : :
2338 : 19900 : ohno:
2339 : :
2340 : : /* If a type is not matched, simply return MATCH_NO. */
2341 : 19904 : gfc_current_locus = old_locus;
2342 : 19904 : return MATCH_NO;
2343 : :
2344 : 1580 : kind_selector:
2345 : :
2346 : 1580 : gfc_gobble_whitespace ();
2347 : :
2348 : : /* This prevents INTEGER*4, etc. */
2349 : 1580 : if (gfc_peek_ascii_char () == '*')
2350 : : {
2351 : 0 : gfc_error ("Invalid type-spec at %C");
2352 : 0 : return MATCH_ERROR;
2353 : : }
2354 : :
2355 : 1580 : m = gfc_match_kind_spec (ts, false);
2356 : :
2357 : : /* No kind specifier found. */
2358 : 1580 : if (m == MATCH_NO)
2359 : 5602 : m = MATCH_YES;
2360 : :
2361 : : return m;
2362 : : }
2363 : :
2364 : :
2365 : : /******************** FORALL subroutines ********************/
2366 : :
2367 : : /* Free a list of FORALL iterators. */
2368 : :
2369 : : void
2370 : 4891 : gfc_free_forall_iterator (gfc_forall_iterator *iter)
2371 : : {
2372 : 4891 : gfc_forall_iterator *next;
2373 : :
2374 : 9701 : while (iter)
2375 : : {
2376 : 4810 : next = iter->next;
2377 : 4810 : gfc_free_expr (iter->var);
2378 : 4810 : gfc_free_expr (iter->start);
2379 : 4810 : gfc_free_expr (iter->end);
2380 : 4810 : gfc_free_expr (iter->stride);
2381 : 4810 : free (iter);
2382 : 4810 : iter = next;
2383 : : }
2384 : 4891 : }
2385 : :
2386 : :
2387 : : /* Match an iterator as part of a FORALL statement. The format is:
2388 : :
2389 : : <var> = <start>:<end>[:<stride>]
2390 : :
2391 : : On MATCH_NO, the caller tests for the possibility that there is a
2392 : : scalar mask expression. */
2393 : :
2394 : : static match
2395 : 4810 : match_forall_iterator (gfc_forall_iterator **result)
2396 : : {
2397 : 4810 : gfc_forall_iterator *iter;
2398 : 4810 : locus where;
2399 : 4810 : match m;
2400 : :
2401 : 4810 : where = gfc_current_locus;
2402 : 4810 : iter = XCNEW (gfc_forall_iterator);
2403 : :
2404 : 4810 : m = gfc_match_expr (&iter->var);
2405 : 4810 : if (m != MATCH_YES)
2406 : 0 : goto cleanup;
2407 : :
2408 : 4810 : if (gfc_match_char ('=') != MATCH_YES
2409 : 4810 : || iter->var->expr_type != EXPR_VARIABLE)
2410 : : {
2411 : 730 : m = MATCH_NO;
2412 : 730 : goto cleanup;
2413 : : }
2414 : :
2415 : 4080 : m = gfc_match_expr (&iter->start);
2416 : 4080 : if (m != MATCH_YES)
2417 : 0 : goto cleanup;
2418 : :
2419 : 4080 : if (gfc_match_char (':') != MATCH_YES)
2420 : 0 : goto syntax;
2421 : :
2422 : 4080 : m = gfc_match_expr (&iter->end);
2423 : 4080 : if (m == MATCH_NO)
2424 : 0 : goto syntax;
2425 : 4080 : if (m == MATCH_ERROR)
2426 : 0 : goto cleanup;
2427 : :
2428 : 4080 : if (gfc_match_char (':') == MATCH_NO)
2429 : 4027 : iter->stride = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
2430 : : else
2431 : : {
2432 : 53 : m = gfc_match_expr (&iter->stride);
2433 : 53 : if (m == MATCH_NO)
2434 : 0 : goto syntax;
2435 : 53 : if (m == MATCH_ERROR)
2436 : 0 : goto cleanup;
2437 : : }
2438 : :
2439 : : /* Mark the iteration variable's symbol as used as a FORALL index. */
2440 : 4080 : iter->var->symtree->n.sym->forall_index = true;
2441 : :
2442 : 4080 : *result = iter;
2443 : 4080 : return MATCH_YES;
2444 : :
2445 : 0 : syntax:
2446 : 0 : gfc_error ("Syntax error in FORALL iterator at %C");
2447 : 0 : m = MATCH_ERROR;
2448 : :
2449 : 730 : cleanup:
2450 : :
2451 : 730 : gfc_current_locus = where;
2452 : 730 : gfc_free_forall_iterator (iter);
2453 : 730 : return m;
2454 : : }
2455 : :
2456 : :
2457 : : /* Match the header of a FORALL statement. */
2458 : :
2459 : : static match
2460 : 2173 : match_forall_header (gfc_forall_iterator **phead, gfc_expr **mask)
2461 : : {
2462 : 2173 : gfc_forall_iterator *head, *tail, *new_iter;
2463 : 2173 : gfc_expr *msk;
2464 : 2173 : match m;
2465 : :
2466 : 2173 : gfc_gobble_whitespace ();
2467 : :
2468 : 2173 : head = tail = NULL;
2469 : 2173 : msk = NULL;
2470 : :
2471 : 2173 : if (gfc_match_char ('(') != MATCH_YES)
2472 : : return MATCH_NO;
2473 : :
2474 : 2171 : m = match_forall_iterator (&new_iter);
2475 : 2171 : if (m == MATCH_ERROR)
2476 : 0 : goto cleanup;
2477 : 2171 : if (m == MATCH_NO)
2478 : 0 : goto syntax;
2479 : :
2480 : 2171 : head = tail = new_iter;
2481 : :
2482 : 5989 : for (;;)
2483 : : {
2484 : 4080 : if (gfc_match_char (',') != MATCH_YES)
2485 : : break;
2486 : :
2487 : 2639 : m = match_forall_iterator (&new_iter);
2488 : 2639 : if (m == MATCH_ERROR)
2489 : 0 : goto cleanup;
2490 : :
2491 : 2639 : if (m == MATCH_YES)
2492 : : {
2493 : 1909 : tail->next = new_iter;
2494 : 1909 : tail = new_iter;
2495 : 1909 : continue;
2496 : : }
2497 : :
2498 : : /* Have to have a mask expression. */
2499 : :
2500 : 730 : m = gfc_match_expr (&msk);
2501 : 730 : if (m == MATCH_NO)
2502 : 0 : goto syntax;
2503 : 730 : if (m == MATCH_ERROR)
2504 : 0 : goto cleanup;
2505 : :
2506 : : break;
2507 : : }
2508 : :
2509 : 2171 : if (gfc_match_char (')') == MATCH_NO)
2510 : 0 : goto syntax;
2511 : :
2512 : 2171 : *phead = head;
2513 : 2171 : *mask = msk;
2514 : 2171 : return MATCH_YES;
2515 : :
2516 : 0 : syntax:
2517 : 0 : gfc_syntax_error (ST_FORALL);
2518 : :
2519 : 0 : cleanup:
2520 : 0 : gfc_free_expr (msk);
2521 : 0 : gfc_free_forall_iterator (head);
2522 : :
2523 : 0 : return MATCH_ERROR;
2524 : : }
2525 : :
2526 : : /* Match the rest of a simple FORALL statement that follows an
2527 : : IF statement. */
2528 : :
2529 : : static match
2530 : 6 : match_simple_forall (void)
2531 : : {
2532 : 6 : gfc_forall_iterator *head;
2533 : 6 : gfc_expr *mask;
2534 : 6 : gfc_code *c;
2535 : 6 : match m;
2536 : :
2537 : 6 : mask = NULL;
2538 : 6 : head = NULL;
2539 : 6 : c = NULL;
2540 : :
2541 : 6 : m = match_forall_header (&head, &mask);
2542 : :
2543 : 6 : if (m == MATCH_NO)
2544 : 0 : goto syntax;
2545 : 6 : if (m != MATCH_YES)
2546 : 0 : goto cleanup;
2547 : :
2548 : 6 : m = gfc_match_assignment ();
2549 : :
2550 : 6 : if (m == MATCH_ERROR)
2551 : 0 : goto cleanup;
2552 : 6 : if (m == MATCH_NO)
2553 : : {
2554 : 0 : m = gfc_match_pointer_assignment ();
2555 : 0 : if (m == MATCH_ERROR)
2556 : 0 : goto cleanup;
2557 : 0 : if (m == MATCH_NO)
2558 : 0 : goto syntax;
2559 : : }
2560 : :
2561 : 6 : c = XCNEW (gfc_code);
2562 : 6 : *c = new_st;
2563 : 6 : c->loc = gfc_current_locus;
2564 : :
2565 : 6 : if (gfc_match_eos () != MATCH_YES)
2566 : 0 : goto syntax;
2567 : :
2568 : 6 : gfc_clear_new_st ();
2569 : 6 : new_st.op = EXEC_FORALL;
2570 : 6 : new_st.expr1 = mask;
2571 : 6 : new_st.ext.concur.forall_iterator = head;
2572 : 6 : new_st.block = gfc_get_code (EXEC_FORALL);
2573 : 6 : new_st.block->next = c;
2574 : :
2575 : 6 : return MATCH_YES;
2576 : :
2577 : 0 : syntax:
2578 : 0 : gfc_syntax_error (ST_FORALL);
2579 : :
2580 : 0 : cleanup:
2581 : 0 : gfc_free_forall_iterator (head);
2582 : 0 : gfc_free_expr (mask);
2583 : :
2584 : 0 : return MATCH_ERROR;
2585 : : }
2586 : :
2587 : :
2588 : : /* Match a FORALL statement. */
2589 : :
2590 : : match
2591 : 500921 : gfc_match_forall (gfc_statement *st)
2592 : : {
2593 : 500921 : gfc_forall_iterator *head;
2594 : 500921 : gfc_expr *mask;
2595 : 500921 : gfc_code *c;
2596 : 500921 : match m0, m;
2597 : :
2598 : 500921 : head = NULL;
2599 : 500921 : mask = NULL;
2600 : 500921 : c = NULL;
2601 : :
2602 : 500921 : m0 = gfc_match_label ();
2603 : 500921 : if (m0 == MATCH_ERROR)
2604 : : return MATCH_ERROR;
2605 : :
2606 : 500913 : m = gfc_match (" forall");
2607 : 500913 : if (m != MATCH_YES)
2608 : : return m;
2609 : :
2610 : 1984 : m = match_forall_header (&head, &mask);
2611 : 1984 : if (m == MATCH_ERROR)
2612 : 0 : goto cleanup;
2613 : 1984 : if (m == MATCH_NO)
2614 : 0 : goto syntax;
2615 : :
2616 : 1984 : if (gfc_match_eos () == MATCH_YES)
2617 : : {
2618 : 504 : *st = ST_FORALL_BLOCK;
2619 : 504 : new_st.op = EXEC_FORALL;
2620 : 504 : new_st.expr1 = mask;
2621 : 504 : new_st.ext.concur.forall_iterator = head;
2622 : 504 : return MATCH_YES;
2623 : : }
2624 : :
2625 : 1480 : m = gfc_match_assignment ();
2626 : 1480 : if (m == MATCH_ERROR)
2627 : 0 : goto cleanup;
2628 : 1480 : if (m == MATCH_NO)
2629 : : {
2630 : 0 : m = gfc_match_pointer_assignment ();
2631 : 0 : if (m == MATCH_ERROR)
2632 : 0 : goto cleanup;
2633 : 0 : if (m == MATCH_NO)
2634 : 0 : goto syntax;
2635 : : }
2636 : :
2637 : 1480 : c = XCNEW (gfc_code);
2638 : 1480 : *c = new_st;
2639 : 1480 : c->loc = gfc_current_locus;
2640 : :
2641 : 1480 : gfc_clear_new_st ();
2642 : 1480 : new_st.op = EXEC_FORALL;
2643 : 1480 : new_st.expr1 = mask;
2644 : 1480 : new_st.ext.concur.forall_iterator = head;
2645 : 1480 : new_st.block = gfc_get_code (EXEC_FORALL);
2646 : 1480 : new_st.block->next = c;
2647 : :
2648 : 1480 : *st = ST_FORALL;
2649 : 1480 : return MATCH_YES;
2650 : :
2651 : 0 : syntax:
2652 : 0 : gfc_syntax_error (ST_FORALL);
2653 : :
2654 : 0 : cleanup:
2655 : 0 : gfc_free_forall_iterator (head);
2656 : 0 : gfc_free_expr (mask);
2657 : 0 : gfc_free_statements (c);
2658 : 0 : return MATCH_NO;
2659 : : }
2660 : :
2661 : :
2662 : : /* Match a DO statement. */
2663 : :
2664 : : match
2665 : 498918 : gfc_match_do (void)
2666 : : {
2667 : 498918 : gfc_iterator iter, *ip;
2668 : 498918 : locus old_loc;
2669 : 498918 : gfc_st_label *label;
2670 : 498918 : match m;
2671 : :
2672 : 498918 : old_loc = gfc_current_locus;
2673 : :
2674 : 498918 : memset (&iter, '\0', sizeof (gfc_iterator));
2675 : 498918 : label = NULL;
2676 : :
2677 : 498918 : m = gfc_match_label ();
2678 : 498918 : if (m == MATCH_ERROR)
2679 : : return m;
2680 : :
2681 : 498910 : if (gfc_match (" do") != MATCH_YES)
2682 : : return MATCH_NO;
2683 : :
2684 : 32063 : m = gfc_match_st_label (&label);
2685 : 32063 : if (m == MATCH_ERROR)
2686 : 0 : goto cleanup;
2687 : :
2688 : : /* Match an infinite DO, make it like a DO WHILE(.TRUE.). */
2689 : :
2690 : 32063 : if (gfc_match_eos () == MATCH_YES)
2691 : : {
2692 : 243 : iter.end = gfc_get_logical_expr (gfc_default_logical_kind, NULL, true);
2693 : 243 : new_st.op = EXEC_DO_WHILE;
2694 : 243 : goto done;
2695 : : }
2696 : :
2697 : : /* Match an optional comma, if no comma is found, a space is obligatory. */
2698 : 31820 : if (gfc_match_char (',') != MATCH_YES && gfc_match ("% ") != MATCH_YES)
2699 : : return MATCH_NO;
2700 : :
2701 : : /* Check for balanced parens. */
2702 : :
2703 : 31820 : if (gfc_match_parens () == MATCH_ERROR)
2704 : : return MATCH_ERROR;
2705 : :
2706 : : /* Handle DO CONCURRENT construct. */
2707 : :
2708 : 31818 : if (gfc_match (" concurrent") == MATCH_YES)
2709 : : {
2710 : 183 : gfc_forall_iterator *head = NULL;
2711 : 183 : gfc_expr_list *local = NULL;
2712 : 183 : gfc_expr_list *local_tail = NULL;
2713 : 183 : gfc_expr_list *local_init = NULL;
2714 : 183 : gfc_expr_list *local_init_tail = NULL;
2715 : 183 : gfc_expr_list *shared = NULL;
2716 : 183 : gfc_expr_list *shared_tail = NULL;
2717 : 183 : gfc_expr_list *reduce = NULL;
2718 : 183 : gfc_expr_list *reduce_tail = NULL;
2719 : 183 : bool default_none = false;
2720 : 183 : gfc_expr *mask;
2721 : :
2722 : 183 : if (!gfc_notify_std (GFC_STD_F2008, "DO CONCURRENT construct at %C"))
2723 : 181 : return MATCH_ERROR;
2724 : :
2725 : :
2726 : 183 : mask = NULL;
2727 : 183 : head = NULL;
2728 : 183 : m = match_forall_header (&head, &mask);
2729 : :
2730 : 183 : if (m == MATCH_NO)
2731 : 2 : goto match_do_loop;
2732 : 181 : if (m == MATCH_ERROR)
2733 : 0 : goto concurr_cleanup;
2734 : :
2735 : 599 : while (true)
2736 : : {
2737 : 390 : gfc_gobble_whitespace ();
2738 : 390 : locus where = gfc_current_locus;
2739 : :
2740 : 390 : if (gfc_match_eos () == MATCH_YES)
2741 : : break;
2742 : :
2743 : 216 : else if (gfc_match ("local ( ") == MATCH_YES)
2744 : : {
2745 : 106 : gfc_expr *e;
2746 : 164 : while (true)
2747 : : {
2748 : 106 : if (gfc_match_variable (&e, 0) != MATCH_YES)
2749 : 0 : goto concurr_cleanup;
2750 : :
2751 : 106 : if (local == NULL)
2752 : 42 : local = local_tail = gfc_get_expr_list ();
2753 : :
2754 : : else
2755 : : {
2756 : 64 : local_tail->next = gfc_get_expr_list ();
2757 : 64 : local_tail = local_tail->next;
2758 : : }
2759 : 106 : local_tail->expr = e;
2760 : :
2761 : 106 : if (gfc_match_char (',') == MATCH_YES)
2762 : 58 : continue;
2763 : 48 : if (gfc_match_char (')') == MATCH_YES)
2764 : : break;
2765 : 0 : goto concurr_cleanup;
2766 : : }
2767 : : }
2768 : :
2769 : 168 : else if (gfc_match ("local_init ( ") == MATCH_YES)
2770 : : {
2771 : 77 : gfc_expr *e;
2772 : :
2773 : 117 : while (true)
2774 : : {
2775 : 77 : if (gfc_match_variable (&e, 0) != MATCH_YES)
2776 : 0 : goto concurr_cleanup;
2777 : :
2778 : 77 : if (local_init == NULL)
2779 : 31 : local_init = local_init_tail = gfc_get_expr_list ();
2780 : :
2781 : : else
2782 : : {
2783 : 46 : local_init_tail->next = gfc_get_expr_list ();
2784 : 46 : local_init_tail = local_init_tail->next;
2785 : : }
2786 : 77 : local_init_tail->expr = e;
2787 : :
2788 : 77 : if (gfc_match_char (',') == MATCH_YES)
2789 : 40 : continue;
2790 : 37 : if (gfc_match_char (')') == MATCH_YES)
2791 : : break;
2792 : 0 : goto concurr_cleanup;
2793 : : }
2794 : : }
2795 : :
2796 : 131 : else if (gfc_match ("shared ( ") == MATCH_YES)
2797 : : {
2798 : 157 : gfc_expr *e;
2799 : 261 : while (true)
2800 : : {
2801 : 157 : if (gfc_match_variable (&e, 0) != MATCH_YES)
2802 : 0 : goto concurr_cleanup;
2803 : :
2804 : 157 : if (shared == NULL)
2805 : 53 : shared = shared_tail = gfc_get_expr_list ();
2806 : :
2807 : : else
2808 : : {
2809 : 104 : shared_tail->next = gfc_get_expr_list ();
2810 : 104 : shared_tail = shared_tail->next;
2811 : : }
2812 : 157 : shared_tail->expr = e;
2813 : :
2814 : 157 : if (gfc_match_char (',') == MATCH_YES)
2815 : 104 : continue;
2816 : 53 : if (gfc_match_char (')') == MATCH_YES)
2817 : : break;
2818 : 0 : goto concurr_cleanup;
2819 : : }
2820 : : }
2821 : :
2822 : 78 : else if (gfc_match ("default (none)") == MATCH_YES)
2823 : : {
2824 : 48 : if (default_none)
2825 : : {
2826 : 1 : gfc_error ("DEFAULT (NONE) specified more than once in DO "
2827 : : "CONCURRENT at %C");
2828 : 1 : goto concurr_cleanup;
2829 : : }
2830 : : default_none = true;
2831 : : }
2832 : :
2833 : 30 : else if (gfc_match ("reduce ( ") == MATCH_YES)
2834 : : {
2835 : 29 : gfc_expr *reduction_expr;
2836 : 29 : where = gfc_current_locus;
2837 : :
2838 : 29 : if (gfc_match_char ('+') == MATCH_YES)
2839 : 15 : reduction_expr = gfc_get_operator_expr (&where,
2840 : : INTRINSIC_PLUS,
2841 : : NULL, NULL);
2842 : :
2843 : 14 : else if (gfc_match_char ('*') == MATCH_YES)
2844 : 6 : reduction_expr = gfc_get_operator_expr (&where,
2845 : : INTRINSIC_TIMES,
2846 : : NULL, NULL);
2847 : :
2848 : 8 : else if (gfc_match (".and.") == MATCH_YES)
2849 : 0 : reduction_expr = gfc_get_operator_expr (&where,
2850 : : INTRINSIC_AND,
2851 : : NULL, NULL);
2852 : :
2853 : 8 : else if (gfc_match (".or.") == MATCH_YES)
2854 : 0 : reduction_expr = gfc_get_operator_expr (&where,
2855 : : INTRINSIC_OR,
2856 : : NULL, NULL);
2857 : :
2858 : 8 : else if (gfc_match (".eqv.") == MATCH_YES)
2859 : 0 : reduction_expr = gfc_get_operator_expr (&where,
2860 : : INTRINSIC_EQV,
2861 : : NULL, NULL);
2862 : :
2863 : 8 : else if (gfc_match (".neqv.") == MATCH_YES)
2864 : 0 : reduction_expr = gfc_get_operator_expr (&where,
2865 : : INTRINSIC_NEQV,
2866 : : NULL, NULL);
2867 : :
2868 : 8 : else if (gfc_match ("min") == MATCH_YES)
2869 : : {
2870 : 1 : reduction_expr = gfc_get_expr ();
2871 : 1 : reduction_expr->expr_type = EXPR_FUNCTION;
2872 : 1 : reduction_expr->value.function.isym
2873 : 1 : = gfc_intrinsic_function_by_id (GFC_ISYM_MIN);
2874 : 1 : reduction_expr->where = where;
2875 : : }
2876 : :
2877 : 7 : else if (gfc_match ("max") == MATCH_YES)
2878 : : {
2879 : 5 : reduction_expr = gfc_get_expr ();
2880 : 5 : reduction_expr->expr_type = EXPR_FUNCTION;
2881 : 5 : reduction_expr->value.function.isym
2882 : 5 : = gfc_intrinsic_function_by_id (GFC_ISYM_MAX);
2883 : 5 : reduction_expr->where = where;
2884 : : }
2885 : :
2886 : 2 : else if (gfc_match ("iand") == MATCH_YES)
2887 : : {
2888 : 1 : reduction_expr = gfc_get_expr ();
2889 : 1 : reduction_expr->expr_type = EXPR_FUNCTION;
2890 : 1 : reduction_expr->value.function.isym
2891 : 1 : = gfc_intrinsic_function_by_id (GFC_ISYM_IAND);
2892 : 1 : reduction_expr->where = where;
2893 : : }
2894 : :
2895 : 1 : else if (gfc_match ("ior") == MATCH_YES)
2896 : : {
2897 : 0 : reduction_expr = gfc_get_expr ();
2898 : 0 : reduction_expr->expr_type = EXPR_FUNCTION;
2899 : 0 : reduction_expr->value.function.isym
2900 : 0 : = gfc_intrinsic_function_by_id (GFC_ISYM_IOR);
2901 : 0 : reduction_expr->where = where;
2902 : : }
2903 : :
2904 : 1 : else if (gfc_match ("ieor") == MATCH_YES)
2905 : : {
2906 : 0 : reduction_expr = gfc_get_expr ();
2907 : 0 : reduction_expr->expr_type = EXPR_FUNCTION;
2908 : 0 : reduction_expr->value.function.isym
2909 : 0 : = gfc_intrinsic_function_by_id (GFC_ISYM_IEOR);
2910 : 0 : reduction_expr->where = where;
2911 : : }
2912 : :
2913 : : else
2914 : : {
2915 : 1 : gfc_error ("Expected reduction operator or function name "
2916 : : "at %C");
2917 : 1 : goto concurr_cleanup;
2918 : : }
2919 : :
2920 : 28 : if (!reduce)
2921 : : {
2922 : 20 : reduce = reduce_tail = gfc_get_expr_list ();
2923 : : }
2924 : : else
2925 : : {
2926 : 8 : reduce_tail->next = gfc_get_expr_list ();
2927 : 8 : reduce_tail = reduce_tail->next;
2928 : : }
2929 : 28 : reduce_tail->expr = reduction_expr;
2930 : :
2931 : 28 : gfc_gobble_whitespace ();
2932 : :
2933 : 28 : if (gfc_match_char (':') != MATCH_YES)
2934 : : {
2935 : 2 : gfc_error ("Expected %<:%> at %C");
2936 : 2 : goto concurr_cleanup;
2937 : : }
2938 : :
2939 : 26 : while (true)
2940 : : {
2941 : 26 : gfc_expr *reduction_expr;
2942 : :
2943 : 26 : if (gfc_match_variable (&reduction_expr, 0) != MATCH_YES)
2944 : : {
2945 : 0 : gfc_error ("Expected variable name in reduction list "
2946 : : "at %C");
2947 : 0 : goto concurr_cleanup;
2948 : : }
2949 : :
2950 : 26 : if (reduce == NULL)
2951 : : reduce = reduce_tail = gfc_get_expr_list ();
2952 : : else
2953 : : {
2954 : 26 : reduce_tail = reduce_tail->next = gfc_get_expr_list ();
2955 : 26 : reduce_tail->expr = reduction_expr;
2956 : : }
2957 : :
2958 : 26 : if (gfc_match_char (',') == MATCH_YES)
2959 : 0 : continue;
2960 : 26 : else if (gfc_match_char (')') == MATCH_YES)
2961 : : break;
2962 : : else
2963 : : {
2964 : 0 : gfc_error ("Expected ',' or ')' in reduction list "
2965 : : "at %C");
2966 : 0 : goto concurr_cleanup;
2967 : : }
2968 : : }
2969 : :
2970 : 26 : if (!gfc_notify_std (GFC_STD_F2023, "REDUCE locality spec at "
2971 : : "%L", &where))
2972 : 2 : goto concurr_cleanup;
2973 : : }
2974 : : else
2975 : 1 : goto concurr_cleanup;
2976 : :
2977 : 209 : if (!gfc_notify_std (GFC_STD_F2018, "Locality spec at %L",
2978 : : &gfc_current_locus))
2979 : 0 : goto concurr_cleanup;
2980 : 209 : }
2981 : :
2982 : 174 : if (m == MATCH_NO)
2983 : : return m;
2984 : 174 : if (m == MATCH_ERROR)
2985 : : goto concurr_cleanup;
2986 : :
2987 : 174 : if (gfc_match_eos () != MATCH_YES)
2988 : 0 : goto concurr_cleanup;
2989 : :
2990 : 174 : if (label != NULL
2991 : 174 : && !gfc_reference_st_label (label, ST_LABEL_DO_TARGET))
2992 : 0 : goto concurr_cleanup;
2993 : :
2994 : 174 : new_st.label1 = label;
2995 : 174 : new_st.op = EXEC_DO_CONCURRENT;
2996 : 174 : new_st.expr1 = mask;
2997 : 174 : new_st.ext.concur.forall_iterator = head;
2998 : 174 : new_st.ext.concur.locality[LOCALITY_LOCAL] = local;
2999 : 174 : new_st.ext.concur.locality[LOCALITY_LOCAL_INIT] = local_init;
3000 : 174 : new_st.ext.concur.locality[LOCALITY_SHARED] = shared;
3001 : 174 : new_st.ext.concur.locality[LOCALITY_REDUCE] = reduce;
3002 : 174 : new_st.ext.concur.default_none = default_none;
3003 : :
3004 : 174 : return MATCH_YES;
3005 : :
3006 : 7 : concurr_cleanup:
3007 : 7 : gfc_free_expr (mask);
3008 : 7 : gfc_free_forall_iterator (head);
3009 : 7 : gfc_free_expr_list (local);
3010 : 7 : gfc_free_expr_list (local_init);
3011 : 7 : gfc_free_expr_list (shared);
3012 : 7 : gfc_free_expr_list (reduce);
3013 : :
3014 : 7 : if (!gfc_error_check ())
3015 : 1 : gfc_syntax_error (ST_DO);
3016 : :
3017 : 7 : return MATCH_ERROR;
3018 : : }
3019 : :
3020 : : /* See if we have a DO WHILE. */
3021 : 31635 : if (gfc_match (" while ( %e )%t", &iter.end) == MATCH_YES)
3022 : : {
3023 : 282 : new_st.op = EXEC_DO_WHILE;
3024 : 282 : goto done;
3025 : : }
3026 : :
3027 : 31353 : match_do_loop:
3028 : : /* The abortive DO WHILE may have done something to the symbol
3029 : : table, so we start over. */
3030 : 31355 : gfc_undo_symbols ();
3031 : 31355 : gfc_current_locus = old_loc;
3032 : :
3033 : 31355 : gfc_match_label (); /* This won't error. */
3034 : 31355 : gfc_match (" do "); /* This will work. */
3035 : :
3036 : 31355 : gfc_match_st_label (&label); /* Can't error out. */
3037 : 31355 : gfc_match_char (','); /* Optional comma. */
3038 : :
3039 : 31355 : m = gfc_match_iterator (&iter, 0);
3040 : 31355 : if (m == MATCH_NO)
3041 : : return MATCH_NO;
3042 : 31354 : if (m == MATCH_ERROR)
3043 : 5 : goto cleanup;
3044 : :
3045 : 31349 : iter.var->symtree->n.sym->attr.implied_index = 0;
3046 : 31349 : gfc_check_do_variable (iter.var->symtree);
3047 : :
3048 : 31349 : if (gfc_match_eos () != MATCH_YES)
3049 : : {
3050 : 0 : gfc_syntax_error (ST_DO);
3051 : 0 : goto cleanup;
3052 : : }
3053 : :
3054 : 31349 : new_st.op = EXEC_DO;
3055 : :
3056 : 31874 : done:
3057 : 31874 : if (label != NULL
3058 : 31874 : && !gfc_reference_st_label (label, ST_LABEL_DO_TARGET))
3059 : 0 : goto cleanup;
3060 : :
3061 : 31874 : new_st.label1 = label;
3062 : :
3063 : 31874 : if (new_st.op == EXEC_DO_WHILE)
3064 : 525 : new_st.expr1 = iter.end;
3065 : : else
3066 : : {
3067 : 31349 : new_st.ext.iterator = ip = gfc_get_iterator ();
3068 : 31349 : *ip = iter;
3069 : : }
3070 : :
3071 : : return MATCH_YES;
3072 : :
3073 : 5 : cleanup:
3074 : 5 : gfc_free_iterator (&iter, 0);
3075 : :
3076 : 5 : return MATCH_ERROR;
3077 : : }
3078 : :
3079 : :
3080 : : /* Match an EXIT or CYCLE statement. */
3081 : :
3082 : : static match
3083 : 736 : match_exit_cycle (gfc_statement st, gfc_exec_op op)
3084 : : {
3085 : 736 : gfc_state_data *p, *o;
3086 : 736 : gfc_symbol *sym;
3087 : 736 : match m;
3088 : 736 : int cnt;
3089 : :
3090 : 736 : if (gfc_match_eos () == MATCH_YES)
3091 : : sym = NULL;
3092 : : else
3093 : : {
3094 : 237 : char name[GFC_MAX_SYMBOL_LEN + 1];
3095 : 237 : gfc_symtree* stree;
3096 : :
3097 : 237 : m = gfc_match ("% %n%t", name);
3098 : 237 : if (m == MATCH_ERROR)
3099 : 3 : return MATCH_ERROR;
3100 : 237 : if (m == MATCH_NO)
3101 : : {
3102 : 0 : gfc_syntax_error (st);
3103 : 0 : return MATCH_ERROR;
3104 : : }
3105 : :
3106 : : /* Find the corresponding symbol. If there's a BLOCK statement
3107 : : between here and the label, it is not in gfc_current_ns but a parent
3108 : : namespace! */
3109 : 237 : stree = gfc_find_symtree_in_proc (name, gfc_current_ns);
3110 : 237 : if (!stree)
3111 : : {
3112 : 2 : gfc_error ("Name %qs in %s statement at %C is unknown",
3113 : : name, gfc_ascii_statement (st));
3114 : 2 : return MATCH_ERROR;
3115 : : }
3116 : :
3117 : 235 : sym = stree->n.sym;
3118 : 235 : if (sym->attr.flavor != FL_LABEL)
3119 : : {
3120 : 1 : gfc_error ("Name %qs in %s statement at %C is not a construct name",
3121 : : name, gfc_ascii_statement (st));
3122 : 1 : return MATCH_ERROR;
3123 : : }
3124 : : }
3125 : :
3126 : : /* Find the loop specified by the label (or lack of a label). */
3127 : 1067 : for (o = NULL, p = gfc_state_stack; p; p = p->previous)
3128 : 1065 : if (o == NULL && p->state == COMP_OMP_STRUCTURED_BLOCK)
3129 : : o = p;
3130 : 1062 : else if (p->state == COMP_CRITICAL)
3131 : : {
3132 : 3 : gfc_error("%s statement at %C leaves CRITICAL construct",
3133 : : gfc_ascii_statement (st));
3134 : 3 : return MATCH_ERROR;
3135 : : }
3136 : 1059 : else if (p->state == COMP_DO_CONCURRENT
3137 : 11 : && (op == EXEC_EXIT || (sym && sym != p->sym)))
3138 : : {
3139 : : /* F2008, C821 & C845. */
3140 : 3 : gfc_error("%s statement at %C leaves DO CONCURRENT construct",
3141 : : gfc_ascii_statement (st));
3142 : 3 : return MATCH_ERROR;
3143 : : }
3144 : 1049 : else if ((sym && sym == p->sym)
3145 : 827 : || (!sym && (p->state == COMP_DO
3146 : 212 : || p->state == COMP_DO_CONCURRENT)))
3147 : : break;
3148 : :
3149 : 727 : if (p == NULL)
3150 : : {
3151 : 2 : if (sym == NULL)
3152 : 1 : gfc_error ("%s statement at %C is not within a construct",
3153 : : gfc_ascii_statement (st));
3154 : : else
3155 : 1 : gfc_error ("%s statement at %C is not within construct %qs",
3156 : : gfc_ascii_statement (st), sym->name);
3157 : :
3158 : 2 : return MATCH_ERROR;
3159 : : }
3160 : :
3161 : : /* Special checks for EXIT from non-loop constructs. */
3162 : 725 : switch (p->state)
3163 : : {
3164 : : case COMP_DO:
3165 : : case COMP_DO_CONCURRENT:
3166 : : break;
3167 : :
3168 : 0 : case COMP_CRITICAL:
3169 : : /* This is already handled above. */
3170 : 0 : gcc_unreachable ();
3171 : :
3172 : 90 : case COMP_ASSOCIATE:
3173 : 90 : case COMP_BLOCK:
3174 : 90 : case COMP_IF:
3175 : 90 : case COMP_SELECT:
3176 : 90 : case COMP_SELECT_TYPE:
3177 : 90 : case COMP_SELECT_RANK:
3178 : 90 : gcc_assert (sym);
3179 : 90 : if (op == EXEC_CYCLE)
3180 : : {
3181 : 2 : gfc_error ("CYCLE statement at %C is not applicable to non-loop"
3182 : : " construct %qs", sym->name);
3183 : 2 : return MATCH_ERROR;
3184 : : }
3185 : 88 : gcc_assert (op == EXEC_EXIT);
3186 : 88 : if (!gfc_notify_std (GFC_STD_F2008, "EXIT statement with no"
3187 : : " do-construct-name at %C"))
3188 : : return MATCH_ERROR;
3189 : : break;
3190 : :
3191 : 1 : default:
3192 : 1 : gfc_error ("%s statement at %C is not applicable to construct %qs",
3193 : : gfc_ascii_statement (st), sym->name);
3194 : 1 : return MATCH_ERROR;
3195 : : }
3196 : :
3197 : 721 : if (o != NULL)
3198 : : {
3199 : 3 : gfc_error (is_oacc (p)
3200 : : ? G_("%s statement at %C leaving OpenACC structured block")
3201 : : : G_("%s statement at %C leaving OpenMP structured block"),
3202 : : gfc_ascii_statement (st));
3203 : 3 : return MATCH_ERROR;
3204 : : }
3205 : :
3206 : 1514 : for (o = p, cnt = 0; o->state == COMP_DO && o->previous != NULL; cnt++)
3207 : 796 : o = o->previous;
3208 : :
3209 : 718 : int count = 1;
3210 : 718 : if (cnt > 0
3211 : : && o != NULL
3212 : 623 : && o->state == COMP_OMP_STRUCTURED_BLOCK)
3213 : 150 : switch (o->head->op)
3214 : : {
3215 : 20 : case EXEC_OACC_LOOP:
3216 : 20 : case EXEC_OACC_KERNELS_LOOP:
3217 : 20 : case EXEC_OACC_PARALLEL_LOOP:
3218 : 20 : case EXEC_OACC_SERIAL_LOOP:
3219 : 20 : gcc_assert (o->head->next != NULL
3220 : : && (o->head->next->op == EXEC_DO
3221 : : || o->head->next->op == EXEC_DO_WHILE)
3222 : : && o->previous != NULL
3223 : : && o->previous->tail->op == o->head->op);
3224 : 20 : if (o->previous->tail->ext.omp_clauses != NULL)
3225 : : {
3226 : : /* Both collapsed and tiled loops are lowered the same way, but are
3227 : : not compatible. In gfc_trans_omp_do, the tile is prioritized. */
3228 : 20 : if (o->previous->tail->ext.omp_clauses->tile_list)
3229 : : {
3230 : : count = 0;
3231 : : gfc_expr_list *el
3232 : : = o->previous->tail->ext.omp_clauses->tile_list;
3233 : 6 : for ( ; el; el = el->next)
3234 : 4 : ++count;
3235 : : }
3236 : 18 : else if (o->previous->tail->ext.omp_clauses->collapse > 1)
3237 : 20 : count = o->previous->tail->ext.omp_clauses->collapse;
3238 : : }
3239 : 20 : if (st == ST_EXIT && cnt <= count)
3240 : : {
3241 : 14 : gfc_error ("EXIT statement at %C terminating !$ACC LOOP loop");
3242 : 14 : return MATCH_ERROR;
3243 : : }
3244 : 6 : if (st == ST_CYCLE && cnt < count)
3245 : : {
3246 : 4 : gfc_error (o->previous->tail->ext.omp_clauses->tile_list
3247 : : ? G_("CYCLE statement at %C to non-innermost tiled "
3248 : : "!$ACC LOOP loop")
3249 : : : G_("CYCLE statement at %C to non-innermost collapsed "
3250 : : "!$ACC LOOP loop"));
3251 : 4 : return MATCH_ERROR;
3252 : : }
3253 : : break;
3254 : 127 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
3255 : 127 : case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
3256 : 127 : case EXEC_OMP_TARGET_SIMD:
3257 : 127 : case EXEC_OMP_TASKLOOP_SIMD:
3258 : 127 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
3259 : 127 : case EXEC_OMP_MASTER_TASKLOOP_SIMD:
3260 : 127 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
3261 : 127 : case EXEC_OMP_MASKED_TASKLOOP_SIMD:
3262 : 127 : case EXEC_OMP_PARALLEL_DO_SIMD:
3263 : 127 : case EXEC_OMP_DISTRIBUTE_SIMD:
3264 : 127 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
3265 : 127 : case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
3266 : 127 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
3267 : 127 : case EXEC_OMP_LOOP:
3268 : 127 : case EXEC_OMP_PARALLEL_LOOP:
3269 : 127 : case EXEC_OMP_TEAMS_LOOP:
3270 : 127 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
3271 : 127 : case EXEC_OMP_TARGET_TEAMS_LOOP:
3272 : 127 : case EXEC_OMP_DO:
3273 : 127 : case EXEC_OMP_PARALLEL_DO:
3274 : 127 : case EXEC_OMP_SIMD:
3275 : 127 : case EXEC_OMP_DO_SIMD:
3276 : 127 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
3277 : 127 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
3278 : 127 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
3279 : 127 : case EXEC_OMP_TARGET_PARALLEL_DO:
3280 : 127 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
3281 : :
3282 : 127 : gcc_assert (o->head->next != NULL
3283 : : && (o->head->next->op == EXEC_DO
3284 : : || o->head->next->op == EXEC_DO_WHILE)
3285 : : && o->previous != NULL
3286 : : && o->previous->tail->op == o->head->op);
3287 : 127 : if (o->previous->tail->ext.omp_clauses != NULL)
3288 : : {
3289 : 127 : if (o->previous->tail->ext.omp_clauses->collapse > 1)
3290 : : count = o->previous->tail->ext.omp_clauses->collapse;
3291 : 127 : if (o->previous->tail->ext.omp_clauses->orderedc)
3292 : 0 : count = o->previous->tail->ext.omp_clauses->orderedc;
3293 : : }
3294 : 127 : if (st == ST_EXIT && cnt <= count)
3295 : : {
3296 : 63 : gfc_error ("EXIT statement at %C terminating !$OMP DO loop");
3297 : 63 : return MATCH_ERROR;
3298 : : }
3299 : 64 : if (st == ST_CYCLE && cnt < count)
3300 : : {
3301 : 3 : gfc_error ("CYCLE statement at %C to non-innermost collapsed "
3302 : : "!$OMP DO loop");
3303 : 3 : return MATCH_ERROR;
3304 : : }
3305 : : break;
3306 : : default:
3307 : : break;
3308 : : }
3309 : :
3310 : : /* Save the first statement in the construct - needed by the backend. */
3311 : 634 : new_st.ext.which_construct = p->construct;
3312 : :
3313 : 634 : new_st.op = op;
3314 : :
3315 : 634 : return MATCH_YES;
3316 : : }
3317 : :
3318 : :
3319 : : /* Match the EXIT statement. */
3320 : :
3321 : : match
3322 : 608 : gfc_match_exit (void)
3323 : : {
3324 : 608 : return match_exit_cycle (ST_EXIT, EXEC_EXIT);
3325 : : }
3326 : :
3327 : :
3328 : : /* Match the CYCLE statement. */
3329 : :
3330 : : match
3331 : 128 : gfc_match_cycle (void)
3332 : : {
3333 : 128 : return match_exit_cycle (ST_CYCLE, EXEC_CYCLE);
3334 : : }
3335 : :
3336 : :
3337 : : /* Match a stop-code after an (ERROR) STOP or PAUSE statement. The
3338 : : requirements for a stop-code differ in the standards.
3339 : :
3340 : : Fortran 95 has
3341 : :
3342 : : R840 stop-stmt is STOP [ stop-code ]
3343 : : R841 stop-code is scalar-char-constant
3344 : : or digit [ digit [ digit [ digit [ digit ] ] ] ]
3345 : :
3346 : : Fortran 2003 matches Fortran 95 except R840 and R841 are now R849 and R850.
3347 : : Fortran 2008 has
3348 : :
3349 : : R855 stop-stmt is STOP [ stop-code ]
3350 : : R856 allstop-stmt is ALL STOP [ stop-code ]
3351 : : R857 stop-code is scalar-default-char-constant-expr
3352 : : or scalar-int-constant-expr
3353 : : Fortran 2018 has
3354 : :
3355 : : R1160 stop-stmt is STOP [ stop-code ] [ , QUIET = scalar-logical-expr]
3356 : : R1161 error-stop-stmt is
3357 : : ERROR STOP [ stop-code ] [ , QUIET = scalar-logical-expr]
3358 : : R1162 stop-code is scalar-default-char-expr
3359 : : or scalar-int-expr
3360 : :
3361 : : For free-form source code, all standards contain a statement of the form:
3362 : :
3363 : : A blank shall be used to separate names, constants, or labels from
3364 : : adjacent keywords, names, constants, or labels.
3365 : :
3366 : : A stop-code is not a name, constant, or label. So, under Fortran 95 and 2003,
3367 : :
3368 : : STOP123
3369 : :
3370 : : is valid, but it is invalid Fortran 2008. */
3371 : :
3372 : : static match
3373 : 206714 : gfc_match_stopcode (gfc_statement st)
3374 : : {
3375 : 206714 : gfc_expr *e = NULL;
3376 : 206714 : gfc_expr *quiet = NULL;
3377 : 206714 : match m;
3378 : 206714 : bool f95, f03, f08;
3379 : 206714 : char c;
3380 : :
3381 : : /* Set f95 for -std=f95. */
3382 : 206714 : f95 = (gfc_option.allow_std == GFC_STD_OPT_F95);
3383 : :
3384 : : /* Set f03 for -std=f2003. */
3385 : 206714 : f03 = (gfc_option.allow_std == GFC_STD_OPT_F03);
3386 : :
3387 : : /* Set f08 for -std=f2008. */
3388 : 206714 : f08 = (gfc_option.allow_std == GFC_STD_OPT_F08);
3389 : :
3390 : : /* Plain STOP statement? */
3391 : 206714 : if (gfc_match_eos () == MATCH_YES)
3392 : 20213 : goto checks;
3393 : :
3394 : : /* Look for a blank between STOP and the stop-code for F2008 or later.
3395 : : But allow for F2018's ,QUIET= specifier. */
3396 : 186501 : c = gfc_peek_ascii_char ();
3397 : :
3398 : 186501 : if (gfc_current_form != FORM_FIXED && !(f95 || f03) && c != ',')
3399 : : {
3400 : : /* Look for end-of-statement. There is no stop-code. */
3401 : : if (c == '\n' || c == '!' || c == ';')
3402 : 0 : goto done;
3403 : :
3404 : : if (c != ' ')
3405 : : {
3406 : 3 : gfc_error ("Blank required in %s statement near %C",
3407 : : gfc_ascii_statement (st));
3408 : 3 : return MATCH_ERROR;
3409 : : }
3410 : : }
3411 : :
3412 : 5007 : if (c == ' ')
3413 : : {
3414 : 182097 : gfc_gobble_whitespace ();
3415 : 182097 : c = gfc_peek_ascii_char ();
3416 : : }
3417 : 186498 : if (c != ',')
3418 : : {
3419 : 186494 : int stopcode;
3420 : 186494 : locus old_locus;
3421 : :
3422 : : /* First look for the F95 or F2003 digit [...] construct. */
3423 : 186494 : old_locus = gfc_current_locus;
3424 : 186494 : m = gfc_match_small_int (&stopcode);
3425 : 186494 : if (m == MATCH_YES && (f95 || f03))
3426 : : {
3427 : 611 : if (stopcode < 0)
3428 : : {
3429 : 2 : gfc_error ("STOP code at %C cannot be negative");
3430 : 4 : return MATCH_ERROR;
3431 : : }
3432 : :
3433 : 609 : if (stopcode > 99999)
3434 : : {
3435 : 2 : gfc_error ("STOP code at %C contains too many digits");
3436 : 2 : return MATCH_ERROR;
3437 : : }
3438 : : }
3439 : :
3440 : : /* Reset the locus and now load gfc_expr. */
3441 : 186490 : gfc_current_locus = old_locus;
3442 : 186490 : m = gfc_match_expr (&e);
3443 : 186490 : if (m == MATCH_ERROR)
3444 : 0 : goto cleanup;
3445 : 186490 : if (m == MATCH_NO)
3446 : 0 : goto syntax;
3447 : : }
3448 : :
3449 : 186494 : if (gfc_match (" , quiet = %e", &quiet) == MATCH_YES)
3450 : : {
3451 : 38 : if (!gfc_notify_std (GFC_STD_F2018, "QUIET= specifier for %s at %L",
3452 : 38 : gfc_ascii_statement (st), &quiet->where))
3453 : 0 : goto cleanup;
3454 : : }
3455 : :
3456 : 186494 : if (gfc_match_eos () != MATCH_YES)
3457 : 1 : goto syntax;
3458 : :
3459 : 186493 : checks:
3460 : :
3461 : 206706 : if (gfc_pure (NULL))
3462 : : {
3463 : 249 : if (st == ST_ERROR_STOP)
3464 : : {
3465 : 249 : if (!gfc_notify_std (GFC_STD_F2018, "%s statement at %C in PURE "
3466 : : "procedure", gfc_ascii_statement (st)))
3467 : 1 : goto cleanup;
3468 : : }
3469 : : else
3470 : : {
3471 : 0 : gfc_error ("%s statement not allowed in PURE procedure at %C",
3472 : : gfc_ascii_statement (st));
3473 : 0 : goto cleanup;
3474 : : }
3475 : : }
3476 : :
3477 : 206705 : gfc_unset_implicit_pure (NULL);
3478 : :
3479 : 206705 : if (st == ST_STOP && gfc_find_state (COMP_CRITICAL))
3480 : : {
3481 : 1 : gfc_error ("Image control statement STOP at %C in CRITICAL block");
3482 : 1 : goto cleanup;
3483 : : }
3484 : 206704 : if (st == ST_STOP && gfc_find_state (COMP_DO_CONCURRENT))
3485 : : {
3486 : 1 : gfc_error ("Image control statement STOP at %C in DO CONCURRENT block");
3487 : 1 : goto cleanup;
3488 : : }
3489 : :
3490 : 206703 : if (e != NULL)
3491 : : {
3492 : 186487 : if (!gfc_simplify_expr (e, 0))
3493 : 1 : goto cleanup;
3494 : :
3495 : : /* Test for F95 and F2003 style STOP stop-code. */
3496 : 186486 : if (e->expr_type != EXPR_CONSTANT && (f95 || f03))
3497 : : {
3498 : 0 : gfc_error ("STOP code at %L must be a scalar CHARACTER constant "
3499 : : "or digit[digit[digit[digit[digit]]]]", &e->where);
3500 : 0 : goto cleanup;
3501 : : }
3502 : :
3503 : : /* Use the machinery for an initialization expression to reduce the
3504 : : stop-code to a constant. */
3505 : 186486 : gfc_reduce_init_expr (e);
3506 : :
3507 : : /* Test for F2008 style STOP stop-code. */
3508 : 186486 : if (e->expr_type != EXPR_CONSTANT && f08)
3509 : : {
3510 : 1 : gfc_error ("STOP code at %L must be a scalar default CHARACTER or "
3511 : : "INTEGER constant expression", &e->where);
3512 : 1 : goto cleanup;
3513 : : }
3514 : :
3515 : 186485 : if (!(e->ts.type == BT_CHARACTER || e->ts.type == BT_INTEGER))
3516 : : {
3517 : 2 : gfc_error ("STOP code at %L must be either INTEGER or CHARACTER type",
3518 : : &e->where);
3519 : 2 : goto cleanup;
3520 : : }
3521 : :
3522 : 186483 : if (e->rank != 0)
3523 : : {
3524 : 1 : gfc_error ("STOP code at %L must be scalar", &e->where);
3525 : 1 : goto cleanup;
3526 : : }
3527 : :
3528 : 186482 : if (e->ts.type == BT_CHARACTER
3529 : 416 : && e->ts.kind != gfc_default_character_kind)
3530 : : {
3531 : 0 : gfc_error ("STOP code at %L must be default character KIND=%d",
3532 : : &e->where, (int) gfc_default_character_kind);
3533 : 0 : goto cleanup;
3534 : : }
3535 : :
3536 : 186066 : if (e->ts.type == BT_INTEGER && e->ts.kind != gfc_default_integer_kind
3537 : 186490 : && !gfc_notify_std (GFC_STD_F2018,
3538 : : "STOP code at %L must be default integer KIND=%d",
3539 : : &e->where, (int) gfc_default_integer_kind))
3540 : 0 : goto cleanup;
3541 : : }
3542 : :
3543 : 206698 : if (quiet != NULL)
3544 : : {
3545 : 38 : if (!gfc_simplify_expr (quiet, 0))
3546 : 0 : goto cleanup;
3547 : :
3548 : 38 : if (quiet->rank != 0)
3549 : : {
3550 : 1 : gfc_error ("QUIET specifier at %L must be a scalar LOGICAL",
3551 : : &quiet->where);
3552 : 1 : goto cleanup;
3553 : : }
3554 : : }
3555 : :
3556 : 206660 : done:
3557 : :
3558 : 206697 : switch (st)
3559 : : {
3560 : 168120 : case ST_STOP:
3561 : 168120 : new_st.op = EXEC_STOP;
3562 : 168120 : break;
3563 : 38549 : case ST_ERROR_STOP:
3564 : 38549 : new_st.op = EXEC_ERROR_STOP;
3565 : 38549 : break;
3566 : 28 : case ST_PAUSE:
3567 : 28 : new_st.op = EXEC_PAUSE;
3568 : 28 : break;
3569 : 0 : default:
3570 : 0 : gcc_unreachable ();
3571 : : }
3572 : :
3573 : 206697 : new_st.expr1 = e;
3574 : 206697 : new_st.expr2 = quiet;
3575 : 206697 : new_st.ext.stop_code = -1;
3576 : :
3577 : 206697 : return MATCH_YES;
3578 : :
3579 : 1 : syntax:
3580 : 1 : gfc_syntax_error (st);
3581 : :
3582 : 10 : cleanup:
3583 : :
3584 : 10 : gfc_free_expr (e);
3585 : 10 : gfc_free_expr (quiet);
3586 : 10 : return MATCH_ERROR;
3587 : : }
3588 : :
3589 : :
3590 : : /* Match the (deprecated) PAUSE statement. */
3591 : :
3592 : : match
3593 : 28 : gfc_match_pause (void)
3594 : : {
3595 : 28 : match m;
3596 : :
3597 : 28 : m = gfc_match_stopcode (ST_PAUSE);
3598 : 28 : if (m == MATCH_YES)
3599 : : {
3600 : 28 : if (!gfc_notify_std (GFC_STD_F95_DEL, "PAUSE statement at %C"))
3601 : 0 : m = MATCH_ERROR;
3602 : : }
3603 : 28 : return m;
3604 : : }
3605 : :
3606 : :
3607 : : /* Match the STOP statement. */
3608 : :
3609 : : match
3610 : 168136 : gfc_match_stop (void)
3611 : : {
3612 : 168136 : return gfc_match_stopcode (ST_STOP);
3613 : : }
3614 : :
3615 : :
3616 : : /* Match the ERROR STOP statement. */
3617 : :
3618 : : match
3619 : 38551 : gfc_match_error_stop (void)
3620 : : {
3621 : 38551 : if (!gfc_notify_std (GFC_STD_F2008, "ERROR STOP statement at %C"))
3622 : : return MATCH_ERROR;
3623 : :
3624 : 38550 : return gfc_match_stopcode (ST_ERROR_STOP);
3625 : : }
3626 : :
3627 : : /* Match EVENT POST/WAIT statement. Syntax:
3628 : : EVENT POST ( event-variable [, sync-stat-list] )
3629 : : EVENT WAIT ( event-variable [, wait-spec-list] )
3630 : : with
3631 : : wait-spec-list is sync-stat-list or until-spec
3632 : : until-spec is UNTIL_COUNT = scalar-int-expr
3633 : : sync-stat is STAT= or ERRMSG=. */
3634 : :
3635 : : static match
3636 : 40 : event_statement (gfc_statement st)
3637 : : {
3638 : 40 : match m;
3639 : 40 : gfc_expr *tmp, *eventvar, *until_count, *stat, *errmsg;
3640 : 40 : bool saw_until_count, saw_stat, saw_errmsg;
3641 : :
3642 : 40 : tmp = eventvar = until_count = stat = errmsg = NULL;
3643 : 40 : saw_until_count = saw_stat = saw_errmsg = false;
3644 : :
3645 : 40 : if (gfc_pure (NULL))
3646 : : {
3647 : 0 : gfc_error ("Image control statement EVENT %s at %C in PURE procedure",
3648 : : st == ST_EVENT_POST ? "POST" : "WAIT");
3649 : 0 : return MATCH_ERROR;
3650 : : }
3651 : :
3652 : 40 : gfc_unset_implicit_pure (NULL);
3653 : :
3654 : 40 : if (flag_coarray == GFC_FCOARRAY_NONE)
3655 : : {
3656 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
3657 : : return MATCH_ERROR;
3658 : : }
3659 : :
3660 : 40 : if (gfc_find_state (COMP_CRITICAL))
3661 : : {
3662 : 0 : gfc_error ("Image control statement EVENT %s at %C in CRITICAL block",
3663 : : st == ST_EVENT_POST ? "POST" : "WAIT");
3664 : 0 : return MATCH_ERROR;
3665 : : }
3666 : :
3667 : 40 : if (gfc_find_state (COMP_DO_CONCURRENT))
3668 : : {
3669 : 0 : gfc_error ("Image control statement EVENT %s at %C in DO CONCURRENT "
3670 : : "block", st == ST_EVENT_POST ? "POST" : "WAIT");
3671 : 0 : return MATCH_ERROR;
3672 : : }
3673 : :
3674 : 40 : if (gfc_match_char ('(') != MATCH_YES)
3675 : 0 : goto syntax;
3676 : :
3677 : 40 : if (gfc_match ("%e", &eventvar) != MATCH_YES)
3678 : 1 : goto syntax;
3679 : 39 : m = gfc_match_char (',');
3680 : 39 : if (m == MATCH_ERROR)
3681 : 0 : goto syntax;
3682 : 39 : if (m == MATCH_NO)
3683 : : {
3684 : 23 : m = gfc_match_char (')');
3685 : 23 : if (m == MATCH_YES)
3686 : 23 : goto done;
3687 : 0 : goto syntax;
3688 : : }
3689 : :
3690 : 20 : for (;;)
3691 : : {
3692 : 20 : m = gfc_match (" stat = %v", &tmp);
3693 : 20 : if (m == MATCH_ERROR)
3694 : 0 : goto syntax;
3695 : 20 : if (m == MATCH_YES)
3696 : : {
3697 : 8 : if (saw_stat)
3698 : : {
3699 : 0 : gfc_error ("Redundant STAT tag found at %L", &tmp->where);
3700 : 0 : goto cleanup;
3701 : : }
3702 : 8 : stat = tmp;
3703 : 8 : saw_stat = true;
3704 : :
3705 : 8 : m = gfc_match_char (',');
3706 : 8 : if (m == MATCH_YES)
3707 : 4 : continue;
3708 : :
3709 : 4 : tmp = NULL;
3710 : 4 : break;
3711 : : }
3712 : :
3713 : 12 : m = gfc_match (" errmsg = %v", &tmp);
3714 : 12 : if (m == MATCH_ERROR)
3715 : 0 : goto syntax;
3716 : 12 : if (m == MATCH_YES)
3717 : : {
3718 : 0 : if (saw_errmsg)
3719 : : {
3720 : 0 : gfc_error ("Redundant ERRMSG tag found at %L", &tmp->where);
3721 : 0 : goto cleanup;
3722 : : }
3723 : 0 : errmsg = tmp;
3724 : 0 : saw_errmsg = true;
3725 : :
3726 : 0 : m = gfc_match_char (',');
3727 : 0 : if (m == MATCH_YES)
3728 : 0 : continue;
3729 : :
3730 : 0 : tmp = NULL;
3731 : 0 : break;
3732 : : }
3733 : :
3734 : 12 : m = gfc_match (" until_count = %e", &tmp);
3735 : 12 : if (m == MATCH_ERROR || st == ST_EVENT_POST)
3736 : 0 : goto syntax;
3737 : 12 : if (m == MATCH_YES)
3738 : : {
3739 : 12 : if (saw_until_count)
3740 : : {
3741 : 0 : gfc_error ("Redundant UNTIL_COUNT tag found at %L",
3742 : 0 : &tmp->where);
3743 : 0 : goto cleanup;
3744 : : }
3745 : 12 : until_count = tmp;
3746 : 12 : saw_until_count = true;
3747 : :
3748 : 12 : m = gfc_match_char (',');
3749 : 12 : if (m == MATCH_YES)
3750 : 0 : continue;
3751 : :
3752 : 12 : tmp = NULL;
3753 : 12 : break;
3754 : : }
3755 : :
3756 : : break;
3757 : : }
3758 : :
3759 : 16 : if (m == MATCH_ERROR)
3760 : 0 : goto syntax;
3761 : :
3762 : 16 : if (gfc_match (" )%t") != MATCH_YES)
3763 : 0 : goto syntax;
3764 : :
3765 : 16 : done:
3766 : 39 : switch (st)
3767 : : {
3768 : 23 : case ST_EVENT_POST:
3769 : 23 : new_st.op = EXEC_EVENT_POST;
3770 : 23 : break;
3771 : 16 : case ST_EVENT_WAIT:
3772 : 16 : new_st.op = EXEC_EVENT_WAIT;
3773 : 16 : break;
3774 : 0 : default:
3775 : 0 : gcc_unreachable ();
3776 : : }
3777 : :
3778 : 39 : new_st.expr1 = eventvar;
3779 : 39 : new_st.expr2 = stat;
3780 : 39 : new_st.expr3 = errmsg;
3781 : 39 : new_st.expr4 = until_count;
3782 : :
3783 : 39 : return MATCH_YES;
3784 : :
3785 : 1 : syntax:
3786 : 1 : gfc_syntax_error (st);
3787 : :
3788 : 1 : cleanup:
3789 : 1 : if (until_count != tmp)
3790 : 0 : gfc_free_expr (until_count);
3791 : 1 : if (errmsg != tmp)
3792 : 0 : gfc_free_expr (errmsg);
3793 : 1 : if (stat != tmp)
3794 : 0 : gfc_free_expr (stat);
3795 : :
3796 : 1 : gfc_free_expr (tmp);
3797 : 1 : gfc_free_expr (eventvar);
3798 : :
3799 : 1 : return MATCH_ERROR;
3800 : :
3801 : : }
3802 : :
3803 : :
3804 : : match
3805 : 24 : gfc_match_event_post (void)
3806 : : {
3807 : 24 : if (!gfc_notify_std (GFC_STD_F2018, "EVENT POST statement at %C"))
3808 : : return MATCH_ERROR;
3809 : :
3810 : 24 : return event_statement (ST_EVENT_POST);
3811 : : }
3812 : :
3813 : :
3814 : : match
3815 : 16 : gfc_match_event_wait (void)
3816 : : {
3817 : 16 : if (!gfc_notify_std (GFC_STD_F2018, "EVENT WAIT statement at %C"))
3818 : : return MATCH_ERROR;
3819 : :
3820 : 16 : return event_statement (ST_EVENT_WAIT);
3821 : : }
3822 : :
3823 : :
3824 : : /* Match a FAIL IMAGE statement. */
3825 : :
3826 : : match
3827 : 7 : gfc_match_fail_image (void)
3828 : : {
3829 : 7 : if (!gfc_notify_std (GFC_STD_F2018, "FAIL IMAGE statement at %C"))
3830 : : return MATCH_ERROR;
3831 : :
3832 : 7 : if (gfc_match_char ('(') == MATCH_YES)
3833 : 2 : goto syntax;
3834 : :
3835 : 5 : new_st.op = EXEC_FAIL_IMAGE;
3836 : :
3837 : 5 : return MATCH_YES;
3838 : :
3839 : 2 : syntax:
3840 : 2 : gfc_syntax_error (ST_FAIL_IMAGE);
3841 : :
3842 : 2 : return MATCH_ERROR;
3843 : : }
3844 : :
3845 : : /* Match a FORM TEAM statement. */
3846 : :
3847 : : match
3848 : 30 : gfc_match_form_team (void)
3849 : : {
3850 : 30 : match m;
3851 : 30 : gfc_expr *teamid,*team;
3852 : :
3853 : 30 : if (!gfc_notify_std (GFC_STD_F2018, "FORM TEAM statement at %C"))
3854 : : return MATCH_ERROR;
3855 : :
3856 : 30 : if (gfc_match_char ('(') == MATCH_NO)
3857 : 0 : goto syntax;
3858 : :
3859 : 30 : new_st.op = EXEC_FORM_TEAM;
3860 : :
3861 : 30 : if (gfc_match ("%e", &teamid) != MATCH_YES)
3862 : 0 : goto syntax;
3863 : 30 : m = gfc_match_char (',');
3864 : 30 : if (m == MATCH_ERROR)
3865 : 0 : goto syntax;
3866 : 30 : if (gfc_match ("%e", &team) != MATCH_YES)
3867 : 0 : goto syntax;
3868 : :
3869 : 30 : m = gfc_match_char (')');
3870 : 30 : if (m == MATCH_NO)
3871 : 0 : goto syntax;
3872 : :
3873 : 30 : new_st.expr1 = teamid;
3874 : 30 : new_st.expr2 = team;
3875 : :
3876 : 30 : return MATCH_YES;
3877 : :
3878 : 0 : syntax:
3879 : 0 : gfc_syntax_error (ST_FORM_TEAM);
3880 : :
3881 : 0 : return MATCH_ERROR;
3882 : : }
3883 : :
3884 : : /* Match a CHANGE TEAM statement. */
3885 : :
3886 : : match
3887 : 20 : gfc_match_change_team (void)
3888 : : {
3889 : 20 : match m;
3890 : 20 : gfc_expr *team;
3891 : :
3892 : 20 : if (!gfc_notify_std (GFC_STD_F2018, "CHANGE TEAM statement at %C"))
3893 : : return MATCH_ERROR;
3894 : :
3895 : 20 : if (gfc_match_char ('(') == MATCH_NO)
3896 : 0 : goto syntax;
3897 : :
3898 : 20 : new_st.op = EXEC_CHANGE_TEAM;
3899 : :
3900 : 20 : if (gfc_match ("%e", &team) != MATCH_YES)
3901 : 0 : goto syntax;
3902 : :
3903 : 20 : m = gfc_match_char (')');
3904 : 20 : if (m == MATCH_NO)
3905 : 0 : goto syntax;
3906 : :
3907 : 20 : new_st.expr1 = team;
3908 : :
3909 : 20 : return MATCH_YES;
3910 : :
3911 : 0 : syntax:
3912 : 0 : gfc_syntax_error (ST_CHANGE_TEAM);
3913 : :
3914 : 0 : return MATCH_ERROR;
3915 : : }
3916 : :
3917 : : /* Match a END TEAM statement. */
3918 : :
3919 : : match
3920 : 20 : gfc_match_end_team (void)
3921 : : {
3922 : 20 : if (!gfc_notify_std (GFC_STD_F2018, "END TEAM statement at %C"))
3923 : : return MATCH_ERROR;
3924 : :
3925 : 20 : if (gfc_match_char ('(') == MATCH_YES)
3926 : 0 : goto syntax;
3927 : :
3928 : 20 : new_st.op = EXEC_END_TEAM;
3929 : :
3930 : 20 : return MATCH_YES;
3931 : :
3932 : 0 : syntax:
3933 : 0 : gfc_syntax_error (ST_END_TEAM);
3934 : :
3935 : 0 : return MATCH_ERROR;
3936 : : }
3937 : :
3938 : : /* Match a SYNC TEAM statement. */
3939 : :
3940 : : match
3941 : 1 : gfc_match_sync_team (void)
3942 : : {
3943 : 1 : match m;
3944 : 1 : gfc_expr *team;
3945 : :
3946 : 1 : if (!gfc_notify_std (GFC_STD_F2018, "SYNC TEAM statement at %C"))
3947 : : return MATCH_ERROR;
3948 : :
3949 : 1 : if (gfc_match_char ('(') == MATCH_NO)
3950 : 0 : goto syntax;
3951 : :
3952 : 1 : new_st.op = EXEC_SYNC_TEAM;
3953 : :
3954 : 1 : if (gfc_match ("%e", &team) != MATCH_YES)
3955 : 0 : goto syntax;
3956 : :
3957 : 1 : m = gfc_match_char (')');
3958 : 1 : if (m == MATCH_NO)
3959 : 0 : goto syntax;
3960 : :
3961 : 1 : new_st.expr1 = team;
3962 : :
3963 : 1 : return MATCH_YES;
3964 : :
3965 : 0 : syntax:
3966 : 0 : gfc_syntax_error (ST_SYNC_TEAM);
3967 : :
3968 : 0 : return MATCH_ERROR;
3969 : : }
3970 : :
3971 : : /* Match LOCK/UNLOCK statement. Syntax:
3972 : : LOCK ( lock-variable [ , lock-stat-list ] )
3973 : : UNLOCK ( lock-variable [ , sync-stat-list ] )
3974 : : where lock-stat is ACQUIRED_LOCK or sync-stat
3975 : : and sync-stat is STAT= or ERRMSG=. */
3976 : :
3977 : : static match
3978 : 102 : lock_unlock_statement (gfc_statement st)
3979 : : {
3980 : 102 : match m;
3981 : 102 : gfc_expr *tmp, *lockvar, *acq_lock, *stat, *errmsg;
3982 : 102 : bool saw_acq_lock, saw_stat, saw_errmsg;
3983 : :
3984 : 102 : tmp = lockvar = acq_lock = stat = errmsg = NULL;
3985 : 102 : saw_acq_lock = saw_stat = saw_errmsg = false;
3986 : :
3987 : 102 : if (gfc_pure (NULL))
3988 : : {
3989 : 0 : gfc_error ("Image control statement %s at %C in PURE procedure",
3990 : : st == ST_LOCK ? "LOCK" : "UNLOCK");
3991 : 0 : return MATCH_ERROR;
3992 : : }
3993 : :
3994 : 102 : gfc_unset_implicit_pure (NULL);
3995 : :
3996 : 102 : if (flag_coarray == GFC_FCOARRAY_NONE)
3997 : : {
3998 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
3999 : : return MATCH_ERROR;
4000 : : }
4001 : :
4002 : 102 : if (gfc_find_state (COMP_CRITICAL))
4003 : : {
4004 : 2 : gfc_error ("Image control statement %s at %C in CRITICAL block",
4005 : : st == ST_LOCK ? "LOCK" : "UNLOCK");
4006 : 2 : return MATCH_ERROR;
4007 : : }
4008 : :
4009 : 100 : if (gfc_find_state (COMP_DO_CONCURRENT))
4010 : : {
4011 : 2 : gfc_error ("Image control statement %s at %C in DO CONCURRENT block",
4012 : : st == ST_LOCK ? "LOCK" : "UNLOCK");
4013 : 2 : return MATCH_ERROR;
4014 : : }
4015 : :
4016 : 98 : if (gfc_match_char ('(') != MATCH_YES)
4017 : 0 : goto syntax;
4018 : :
4019 : 98 : if (gfc_match ("%e", &lockvar) != MATCH_YES)
4020 : 1 : goto syntax;
4021 : 97 : m = gfc_match_char (',');
4022 : 97 : if (m == MATCH_ERROR)
4023 : 0 : goto syntax;
4024 : 97 : if (m == MATCH_NO)
4025 : : {
4026 : 53 : m = gfc_match_char (')');
4027 : 53 : if (m == MATCH_YES)
4028 : 53 : goto done;
4029 : 0 : goto syntax;
4030 : : }
4031 : :
4032 : 48 : for (;;)
4033 : : {
4034 : 48 : m = gfc_match (" stat = %v", &tmp);
4035 : 48 : if (m == MATCH_ERROR)
4036 : 0 : goto syntax;
4037 : 48 : if (m == MATCH_YES)
4038 : : {
4039 : 30 : if (saw_stat)
4040 : : {
4041 : 0 : gfc_error ("Redundant STAT tag found at %L", &tmp->where);
4042 : 0 : goto cleanup;
4043 : : }
4044 : 30 : stat = tmp;
4045 : 30 : saw_stat = true;
4046 : :
4047 : 30 : m = gfc_match_char (',');
4048 : 30 : if (m == MATCH_YES)
4049 : 2 : continue;
4050 : :
4051 : 28 : tmp = NULL;
4052 : 28 : break;
4053 : : }
4054 : :
4055 : 18 : m = gfc_match (" errmsg = %v", &tmp);
4056 : 18 : if (m == MATCH_ERROR)
4057 : 0 : goto syntax;
4058 : 18 : if (m == MATCH_YES)
4059 : : {
4060 : 2 : if (saw_errmsg)
4061 : : {
4062 : 0 : gfc_error ("Redundant ERRMSG tag found at %L", &tmp->where);
4063 : 0 : goto cleanup;
4064 : : }
4065 : 2 : errmsg = tmp;
4066 : 2 : saw_errmsg = true;
4067 : :
4068 : 2 : m = gfc_match_char (',');
4069 : 2 : if (m == MATCH_YES)
4070 : 0 : continue;
4071 : :
4072 : 2 : tmp = NULL;
4073 : 2 : break;
4074 : : }
4075 : :
4076 : 16 : m = gfc_match (" acquired_lock = %v", &tmp);
4077 : 16 : if (m == MATCH_ERROR || st == ST_UNLOCK)
4078 : 0 : goto syntax;
4079 : 16 : if (m == MATCH_YES)
4080 : : {
4081 : 16 : if (saw_acq_lock)
4082 : : {
4083 : 0 : gfc_error ("Redundant ACQUIRED_LOCK tag found at %L",
4084 : 0 : &tmp->where);
4085 : 0 : goto cleanup;
4086 : : }
4087 : 16 : acq_lock = tmp;
4088 : 16 : saw_acq_lock = true;
4089 : :
4090 : 16 : m = gfc_match_char (',');
4091 : 16 : if (m == MATCH_YES)
4092 : 2 : continue;
4093 : :
4094 : 14 : tmp = NULL;
4095 : 14 : break;
4096 : : }
4097 : :
4098 : : break;
4099 : : }
4100 : :
4101 : 44 : if (m == MATCH_ERROR)
4102 : 0 : goto syntax;
4103 : :
4104 : 44 : if (gfc_match (" )%t") != MATCH_YES)
4105 : 0 : goto syntax;
4106 : :
4107 : 44 : done:
4108 : 97 : switch (st)
4109 : : {
4110 : 53 : case ST_LOCK:
4111 : 53 : new_st.op = EXEC_LOCK;
4112 : 53 : break;
4113 : 44 : case ST_UNLOCK:
4114 : 44 : new_st.op = EXEC_UNLOCK;
4115 : 44 : break;
4116 : 0 : default:
4117 : 0 : gcc_unreachable ();
4118 : : }
4119 : :
4120 : 97 : new_st.expr1 = lockvar;
4121 : 97 : new_st.expr2 = stat;
4122 : 97 : new_st.expr3 = errmsg;
4123 : 97 : new_st.expr4 = acq_lock;
4124 : :
4125 : 97 : return MATCH_YES;
4126 : :
4127 : 1 : syntax:
4128 : 1 : gfc_syntax_error (st);
4129 : :
4130 : 1 : cleanup:
4131 : 1 : if (acq_lock != tmp)
4132 : 0 : gfc_free_expr (acq_lock);
4133 : 1 : if (errmsg != tmp)
4134 : 0 : gfc_free_expr (errmsg);
4135 : 1 : if (stat != tmp)
4136 : 0 : gfc_free_expr (stat);
4137 : :
4138 : 1 : gfc_free_expr (tmp);
4139 : 1 : gfc_free_expr (lockvar);
4140 : :
4141 : 1 : return MATCH_ERROR;
4142 : : }
4143 : :
4144 : :
4145 : : match
4146 : 57 : gfc_match_lock (void)
4147 : : {
4148 : 57 : if (!gfc_notify_std (GFC_STD_F2008, "LOCK statement at %C"))
4149 : : return MATCH_ERROR;
4150 : :
4151 : 56 : return lock_unlock_statement (ST_LOCK);
4152 : : }
4153 : :
4154 : :
4155 : : match
4156 : 47 : gfc_match_unlock (void)
4157 : : {
4158 : 47 : if (!gfc_notify_std (GFC_STD_F2008, "UNLOCK statement at %C"))
4159 : : return MATCH_ERROR;
4160 : :
4161 : 46 : return lock_unlock_statement (ST_UNLOCK);
4162 : : }
4163 : :
4164 : :
4165 : : /* Match SYNC ALL/IMAGES/MEMORY statement. Syntax:
4166 : : SYNC ALL [(sync-stat-list)]
4167 : : SYNC MEMORY [(sync-stat-list)]
4168 : : SYNC IMAGES (image-set [, sync-stat-list] )
4169 : : with sync-stat is int-expr or *. */
4170 : :
4171 : : static match
4172 : 754 : sync_statement (gfc_statement st)
4173 : : {
4174 : 754 : match m;
4175 : 754 : gfc_expr *tmp, *imageset, *stat, *errmsg;
4176 : 754 : bool saw_stat, saw_errmsg;
4177 : :
4178 : 754 : tmp = imageset = stat = errmsg = NULL;
4179 : 754 : saw_stat = saw_errmsg = false;
4180 : :
4181 : 754 : if (gfc_pure (NULL))
4182 : : {
4183 : 1 : gfc_error ("Image control statement SYNC at %C in PURE procedure");
4184 : 1 : return MATCH_ERROR;
4185 : : }
4186 : :
4187 : 753 : gfc_unset_implicit_pure (NULL);
4188 : :
4189 : 753 : if (!gfc_notify_std (GFC_STD_F2008, "SYNC statement at %C"))
4190 : : return MATCH_ERROR;
4191 : :
4192 : 750 : if (flag_coarray == GFC_FCOARRAY_NONE)
4193 : : {
4194 : 0 : gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to "
4195 : : "enable");
4196 : : return MATCH_ERROR;
4197 : : }
4198 : :
4199 : 750 : if (gfc_find_state (COMP_CRITICAL))
4200 : : {
4201 : 1 : gfc_error ("Image control statement SYNC at %C in CRITICAL block");
4202 : 1 : return MATCH_ERROR;
4203 : : }
4204 : :
4205 : 749 : if (gfc_find_state (COMP_DO_CONCURRENT))
4206 : : {
4207 : 1 : gfc_error ("Image control statement SYNC at %C in DO CONCURRENT block");
4208 : 1 : return MATCH_ERROR;
4209 : : }
4210 : :
4211 : 748 : if (gfc_match_eos () == MATCH_YES)
4212 : : {
4213 : 559 : if (st == ST_SYNC_IMAGES)
4214 : 0 : goto syntax;
4215 : 559 : goto done;
4216 : : }
4217 : :
4218 : 189 : if (gfc_match_char ('(') != MATCH_YES)
4219 : 0 : goto syntax;
4220 : :
4221 : 189 : if (st == ST_SYNC_IMAGES)
4222 : : {
4223 : : /* Denote '*' as imageset == NULL. */
4224 : 78 : m = gfc_match_char ('*');
4225 : 78 : if (m == MATCH_ERROR)
4226 : 0 : goto syntax;
4227 : 78 : if (m == MATCH_NO)
4228 : : {
4229 : 48 : if (gfc_match ("%e", &imageset) != MATCH_YES)
4230 : 0 : goto syntax;
4231 : : }
4232 : 78 : m = gfc_match_char (',');
4233 : 78 : if (m == MATCH_ERROR)
4234 : 0 : goto syntax;
4235 : 78 : if (m == MATCH_NO)
4236 : : {
4237 : 42 : m = gfc_match_char (')');
4238 : 42 : if (m == MATCH_YES)
4239 : 42 : goto done;
4240 : 0 : goto syntax;
4241 : : }
4242 : : }
4243 : :
4244 : 181 : for (;;)
4245 : : {
4246 : 181 : m = gfc_match (" stat = %e", &tmp);
4247 : 181 : if (m == MATCH_ERROR)
4248 : 0 : goto syntax;
4249 : 181 : if (m == MATCH_YES)
4250 : : {
4251 : 86 : if (saw_stat)
4252 : : {
4253 : 1 : gfc_error ("Redundant STAT tag found at %L", &tmp->where);
4254 : 1 : goto cleanup;
4255 : : }
4256 : 85 : stat = tmp;
4257 : 85 : saw_stat = true;
4258 : :
4259 : 85 : if (gfc_match_char (',') == MATCH_YES)
4260 : 13 : continue;
4261 : :
4262 : 72 : tmp = NULL;
4263 : 72 : break;
4264 : : }
4265 : :
4266 : 95 : m = gfc_match (" errmsg = %e", &tmp);
4267 : 95 : if (m == MATCH_ERROR)
4268 : 0 : goto syntax;
4269 : 95 : if (m == MATCH_YES)
4270 : : {
4271 : 75 : if (saw_errmsg)
4272 : : {
4273 : 0 : gfc_error ("Redundant ERRMSG tag found at %L", &tmp->where);
4274 : 0 : goto cleanup;
4275 : : }
4276 : 75 : errmsg = tmp;
4277 : 75 : saw_errmsg = true;
4278 : :
4279 : 75 : if (gfc_match_char (',') == MATCH_YES)
4280 : 21 : continue;
4281 : :
4282 : 54 : tmp = NULL;
4283 : 54 : break;
4284 : : }
4285 : :
4286 : : break;
4287 : : }
4288 : :
4289 : 146 : if (gfc_match (" )%t") != MATCH_YES)
4290 : 0 : goto syntax;
4291 : :
4292 : 146 : done:
4293 : 747 : switch (st)
4294 : : {
4295 : 605 : case ST_SYNC_ALL:
4296 : 605 : new_st.op = EXEC_SYNC_ALL;
4297 : 605 : break;
4298 : 78 : case ST_SYNC_IMAGES:
4299 : 78 : new_st.op = EXEC_SYNC_IMAGES;
4300 : 78 : break;
4301 : 64 : case ST_SYNC_MEMORY:
4302 : 64 : new_st.op = EXEC_SYNC_MEMORY;
4303 : 64 : break;
4304 : 0 : default:
4305 : 0 : gcc_unreachable ();
4306 : : }
4307 : :
4308 : 747 : new_st.expr1 = imageset;
4309 : 747 : new_st.expr2 = stat;
4310 : 747 : new_st.expr3 = errmsg;
4311 : :
4312 : 747 : return MATCH_YES;
4313 : :
4314 : 0 : syntax:
4315 : 0 : gfc_syntax_error (st);
4316 : :
4317 : 1 : cleanup:
4318 : 1 : if (stat != tmp)
4319 : 1 : gfc_free_expr (stat);
4320 : 1 : if (errmsg != tmp)
4321 : 1 : gfc_free_expr (errmsg);
4322 : :
4323 : 1 : gfc_free_expr (tmp);
4324 : 1 : gfc_free_expr (imageset);
4325 : :
4326 : 1 : return MATCH_ERROR;
4327 : : }
4328 : :
4329 : :
4330 : : /* Match SYNC ALL statement. */
4331 : :
4332 : : match
4333 : 610 : gfc_match_sync_all (void)
4334 : : {
4335 : 610 : return sync_statement (ST_SYNC_ALL);
4336 : : }
4337 : :
4338 : :
4339 : : /* Match SYNC IMAGES statement. */
4340 : :
4341 : : match
4342 : 79 : gfc_match_sync_images (void)
4343 : : {
4344 : 79 : return sync_statement (ST_SYNC_IMAGES);
4345 : : }
4346 : :
4347 : :
4348 : : /* Match SYNC MEMORY statement. */
4349 : :
4350 : : match
4351 : 65 : gfc_match_sync_memory (void)
4352 : : {
4353 : 65 : return sync_statement (ST_SYNC_MEMORY);
4354 : : }
4355 : :
4356 : :
4357 : : /* Match a CONTINUE statement. */
4358 : :
4359 : : match
4360 : 2762 : gfc_match_continue (void)
4361 : : {
4362 : 2762 : if (gfc_match_eos () != MATCH_YES)
4363 : : {
4364 : 0 : gfc_syntax_error (ST_CONTINUE);
4365 : 0 : return MATCH_ERROR;
4366 : : }
4367 : :
4368 : 2762 : new_st.op = EXEC_CONTINUE;
4369 : 2762 : return MATCH_YES;
4370 : : }
4371 : :
4372 : :
4373 : : /* Match the (deprecated) ASSIGN statement. */
4374 : :
4375 : : match
4376 : 126 : gfc_match_assign (void)
4377 : : {
4378 : 126 : gfc_expr *expr;
4379 : 126 : gfc_st_label *label;
4380 : :
4381 : 126 : if (gfc_match (" %l", &label) == MATCH_YES)
4382 : : {
4383 : 126 : if (!gfc_reference_st_label (label, ST_LABEL_UNKNOWN))
4384 : : return MATCH_ERROR;
4385 : 126 : if (gfc_match (" to %v%t", &expr) == MATCH_YES)
4386 : : {
4387 : 126 : if (!gfc_notify_std (GFC_STD_F95_DEL, "ASSIGN statement at %C"))
4388 : : return MATCH_ERROR;
4389 : :
4390 : 126 : expr->symtree->n.sym->attr.assign = 1;
4391 : :
4392 : 126 : new_st.op = EXEC_LABEL_ASSIGN;
4393 : 126 : new_st.label1 = label;
4394 : 126 : new_st.expr1 = expr;
4395 : 126 : return MATCH_YES;
4396 : : }
4397 : : }
4398 : : return MATCH_NO;
4399 : : }
4400 : :
4401 : :
4402 : : /* Match the GO TO statement. As a computed GOTO statement is
4403 : : matched, it is transformed into an equivalent SELECT block. No
4404 : : tree is necessary, and the resulting jumps-to-jumps are
4405 : : specifically optimized away by the back end. */
4406 : :
4407 : : match
4408 : 1000 : gfc_match_goto (void)
4409 : : {
4410 : 1000 : gfc_code *head, *tail;
4411 : 1000 : gfc_expr *expr;
4412 : 1000 : gfc_case *cp;
4413 : 1000 : gfc_st_label *label;
4414 : 1000 : int i;
4415 : 1000 : match m;
4416 : :
4417 : 1000 : if (gfc_match (" %l%t", &label) == MATCH_YES)
4418 : : {
4419 : 917 : if (!gfc_reference_st_label (label, ST_LABEL_TARGET))
4420 : : return MATCH_ERROR;
4421 : :
4422 : 917 : new_st.op = EXEC_GOTO;
4423 : 917 : new_st.label1 = label;
4424 : 917 : return MATCH_YES;
4425 : : }
4426 : :
4427 : : /* The assigned GO TO statement. */
4428 : :
4429 : 83 : if (gfc_match_variable (&expr, 0) == MATCH_YES)
4430 : : {
4431 : 78 : if (!gfc_notify_std (GFC_STD_F95_DEL, "Assigned GOTO statement at %C"))
4432 : : return MATCH_ERROR;
4433 : :
4434 : 78 : new_st.op = EXEC_GOTO;
4435 : 78 : new_st.expr1 = expr;
4436 : :
4437 : 78 : if (gfc_match_eos () == MATCH_YES)
4438 : : return MATCH_YES;
4439 : :
4440 : : /* Match label list. */
4441 : 27 : gfc_match_char (',');
4442 : 27 : if (gfc_match_char ('(') != MATCH_YES)
4443 : : {
4444 : 0 : gfc_syntax_error (ST_GOTO);
4445 : 0 : return MATCH_ERROR;
4446 : : }
4447 : : head = tail = NULL;
4448 : :
4449 : 76 : do
4450 : : {
4451 : 76 : m = gfc_match_st_label (&label);
4452 : 76 : if (m != MATCH_YES)
4453 : 0 : goto syntax;
4454 : :
4455 : 76 : if (!gfc_reference_st_label (label, ST_LABEL_TARGET))
4456 : 0 : goto cleanup;
4457 : :
4458 : 76 : if (head == NULL)
4459 : 27 : head = tail = gfc_get_code (EXEC_GOTO);
4460 : : else
4461 : : {
4462 : 49 : tail->block = gfc_get_code (EXEC_GOTO);
4463 : 49 : tail = tail->block;
4464 : : }
4465 : :
4466 : 76 : tail->label1 = label;
4467 : : }
4468 : 76 : while (gfc_match_char (',') == MATCH_YES);
4469 : :
4470 : 27 : if (gfc_match (" )%t") != MATCH_YES)
4471 : 0 : goto syntax;
4472 : :
4473 : 27 : if (head == NULL)
4474 : : {
4475 : 0 : gfc_error ("Statement label list in GOTO at %C cannot be empty");
4476 : 0 : goto syntax;
4477 : : }
4478 : 27 : new_st.block = head;
4479 : :
4480 : 27 : return MATCH_YES;
4481 : : }
4482 : :
4483 : : /* Last chance is a computed GO TO statement. */
4484 : 5 : if (gfc_match_char ('(') != MATCH_YES)
4485 : : {
4486 : 0 : gfc_syntax_error (ST_GOTO);
4487 : 0 : return MATCH_ERROR;
4488 : : }
4489 : :
4490 : : head = tail = NULL;
4491 : : i = 1;
4492 : :
4493 : 13 : do
4494 : : {
4495 : 13 : m = gfc_match_st_label (&label);
4496 : 13 : if (m != MATCH_YES)
4497 : 0 : goto syntax;
4498 : :
4499 : 13 : if (!gfc_reference_st_label (label, ST_LABEL_TARGET))
4500 : 0 : goto cleanup;
4501 : :
4502 : 13 : if (head == NULL)
4503 : 5 : head = tail = gfc_get_code (EXEC_SELECT);
4504 : : else
4505 : : {
4506 : 8 : tail->block = gfc_get_code (EXEC_SELECT);
4507 : 8 : tail = tail->block;
4508 : : }
4509 : :
4510 : 13 : cp = gfc_get_case ();
4511 : 26 : cp->low = cp->high = gfc_get_int_expr (gfc_default_integer_kind,
4512 : 13 : NULL, i++);
4513 : :
4514 : 13 : tail->ext.block.case_list = cp;
4515 : :
4516 : 13 : tail->next = gfc_get_code (EXEC_GOTO);
4517 : 13 : tail->next->label1 = label;
4518 : : }
4519 : 13 : while (gfc_match_char (',') == MATCH_YES);
4520 : :
4521 : 5 : if (gfc_match_char (')') != MATCH_YES)
4522 : 0 : goto syntax;
4523 : :
4524 : 5 : if (head == NULL)
4525 : : {
4526 : 0 : gfc_error ("Statement label list in GOTO at %C cannot be empty");
4527 : 0 : goto syntax;
4528 : : }
4529 : :
4530 : : /* Get the rest of the statement. */
4531 : 5 : gfc_match_char (',');
4532 : :
4533 : 5 : if (gfc_match (" %e%t", &expr) != MATCH_YES)
4534 : 0 : goto syntax;
4535 : :
4536 : 5 : if (!gfc_notify_std (GFC_STD_F95_OBS, "Computed GOTO at %C"))
4537 : : return MATCH_ERROR;
4538 : :
4539 : : /* At this point, a computed GOTO has been fully matched and an
4540 : : equivalent SELECT statement constructed. */
4541 : :
4542 : 5 : new_st.op = EXEC_SELECT;
4543 : 5 : new_st.expr1 = NULL;
4544 : :
4545 : : /* Hack: For a "real" SELECT, the expression is in expr. We put
4546 : : it in expr2 so we can distinguish then and produce the correct
4547 : : diagnostics. */
4548 : 5 : new_st.expr2 = expr;
4549 : 5 : new_st.block = head;
4550 : 5 : return MATCH_YES;
4551 : :
4552 : 0 : syntax:
4553 : 0 : gfc_syntax_error (ST_GOTO);
4554 : 0 : cleanup:
4555 : 0 : gfc_free_statements (head);
4556 : 0 : return MATCH_ERROR;
4557 : : }
4558 : :
4559 : :
4560 : : /* Frees a list of gfc_alloc structures. */
4561 : :
4562 : : void
4563 : 21984 : gfc_free_alloc_list (gfc_alloc *p)
4564 : : {
4565 : 21984 : gfc_alloc *q;
4566 : :
4567 : 48993 : for (; p; p = q)
4568 : : {
4569 : 27009 : q = p->next;
4570 : 27009 : gfc_free_expr (p->expr);
4571 : 27009 : free (p);
4572 : : }
4573 : 21984 : }
4574 : :
4575 : :
4576 : : /* Match an ALLOCATE statement. */
4577 : :
4578 : : match
4579 : 13628 : gfc_match_allocate (void)
4580 : : {
4581 : 13628 : gfc_alloc *head, *tail;
4582 : 13628 : gfc_expr *stat, *errmsg, *tmp, *source, *mold;
4583 : 13628 : gfc_typespec ts;
4584 : 13628 : gfc_symbol *sym;
4585 : 13628 : match m;
4586 : 13628 : locus old_locus, deferred_locus, assumed_locus;
4587 : 13628 : bool saw_stat, saw_errmsg, saw_source, saw_mold, saw_deferred, b1, b2, b3;
4588 : 13628 : bool saw_unlimited = false, saw_assumed = false;
4589 : :
4590 : 13628 : head = tail = NULL;
4591 : 13628 : stat = errmsg = source = mold = tmp = NULL;
4592 : 13628 : saw_stat = saw_errmsg = saw_source = saw_mold = saw_deferred = false;
4593 : :
4594 : 13628 : if (gfc_match_char ('(') != MATCH_YES)
4595 : : {
4596 : 1 : gfc_syntax_error (ST_ALLOCATE);
4597 : 1 : return MATCH_ERROR;
4598 : : }
4599 : :
4600 : : /* Match an optional type-spec. */
4601 : 13627 : old_locus = gfc_current_locus;
4602 : 13627 : m = gfc_match_type_spec (&ts);
4603 : 13627 : if (m == MATCH_ERROR)
4604 : 7 : goto cleanup;
4605 : 13620 : else if (m == MATCH_NO)
4606 : : {
4607 : 12208 : char name[GFC_MAX_SYMBOL_LEN + 3];
4608 : :
4609 : 12208 : if (gfc_match ("%n :: ", name) == MATCH_YES)
4610 : : {
4611 : 7 : gfc_error ("Error in type-spec at %L", &old_locus);
4612 : 7 : goto cleanup;
4613 : : }
4614 : :
4615 : 12201 : ts.type = BT_UNKNOWN;
4616 : : }
4617 : : else
4618 : : {
4619 : : /* Needed for the F2008:C631 check below. */
4620 : 1412 : assumed_locus = gfc_current_locus;
4621 : :
4622 : 1412 : if (gfc_match (" :: ") == MATCH_YES)
4623 : : {
4624 : 1400 : if (!gfc_notify_std (GFC_STD_F2003, "typespec in ALLOCATE at %L",
4625 : : &old_locus))
4626 : 0 : goto cleanup;
4627 : :
4628 : 1400 : if (ts.deferred)
4629 : : {
4630 : 5 : gfc_error ("Type-spec at %L cannot contain a deferred "
4631 : : "type parameter", &old_locus);
4632 : 5 : goto cleanup;
4633 : : }
4634 : :
4635 : 1395 : if (ts.type == BT_CHARACTER)
4636 : : {
4637 : 429 : if (!ts.u.cl->length)
4638 : : saw_assumed = true;
4639 : : else
4640 : 416 : ts.u.cl->length_from_typespec = true;
4641 : : }
4642 : :
4643 : 1395 : if (type_param_spec_list
4644 : 1395 : && gfc_spec_list_type (type_param_spec_list, NULL)
4645 : : == SPEC_DEFERRED)
4646 : : {
4647 : 0 : gfc_error ("The type parameter spec list in the type-spec at "
4648 : : "%L cannot contain DEFERRED parameters", &old_locus);
4649 : 0 : goto cleanup;
4650 : : }
4651 : : }
4652 : : else
4653 : : {
4654 : 12 : ts.type = BT_UNKNOWN;
4655 : 12 : gfc_current_locus = old_locus;
4656 : : }
4657 : : }
4658 : :
4659 : 16586 : for (;;)
4660 : : {
4661 : 16586 : if (head == NULL)
4662 : 13608 : head = tail = gfc_get_alloc ();
4663 : : else
4664 : : {
4665 : 2978 : tail->next = gfc_get_alloc ();
4666 : 2978 : tail = tail->next;
4667 : : }
4668 : :
4669 : 16586 : m = gfc_match_variable (&tail->expr, 0);
4670 : 16586 : if (m == MATCH_NO)
4671 : 0 : goto syntax;
4672 : 16586 : if (m == MATCH_ERROR)
4673 : 11 : goto cleanup;
4674 : :
4675 : 16575 : if (tail->expr->expr_type == EXPR_CONSTANT)
4676 : : {
4677 : 1 : gfc_error ("Unexpected constant at %C");
4678 : 1 : goto cleanup;
4679 : : }
4680 : :
4681 : 16574 : if (gfc_check_do_variable (tail->expr->symtree))
4682 : 0 : goto cleanup;
4683 : :
4684 : 16574 : bool impure = gfc_impure_variable (tail->expr->symtree->n.sym);
4685 : 16574 : if (impure && gfc_pure (NULL))
4686 : : {
4687 : 0 : gfc_error ("Bad allocate-object at %C for a PURE procedure");
4688 : 0 : goto cleanup;
4689 : : }
4690 : :
4691 : 16574 : if (impure)
4692 : 396 : gfc_unset_implicit_pure (NULL);
4693 : :
4694 : : /* F2008:C631 (R626) A type-param-value in a type-spec shall be an
4695 : : asterisk if and only if each allocate-object is a dummy argument
4696 : : for which the corresponding type parameter is assumed. */
4697 : 16574 : if (saw_assumed
4698 : 20 : && (tail->expr->ts.deferred
4699 : 19 : || (tail->expr->ts.u.cl && tail->expr->ts.u.cl->length)
4700 : 17 : || tail->expr->symtree->n.sym->attr.dummy == 0))
4701 : : {
4702 : 4 : gfc_error ("Incompatible allocate-object at %C for CHARACTER "
4703 : : "type-spec at %L", &assumed_locus);
4704 : 4 : goto cleanup;
4705 : : }
4706 : :
4707 : 16570 : if (tail->expr->ts.deferred)
4708 : : {
4709 : 1006 : saw_deferred = true;
4710 : 1006 : deferred_locus = tail->expr->where;
4711 : : }
4712 : :
4713 : 16570 : if (gfc_find_state (COMP_DO_CONCURRENT)
4714 : 16570 : || gfc_find_state (COMP_CRITICAL))
4715 : : {
4716 : 2 : gfc_ref *ref;
4717 : 2 : bool coarray = tail->expr->symtree->n.sym->attr.codimension;
4718 : 4 : for (ref = tail->expr->ref; ref; ref = ref->next)
4719 : 2 : if (ref->type == REF_COMPONENT)
4720 : 0 : coarray = ref->u.c.component->attr.codimension;
4721 : :
4722 : 2 : if (coarray && gfc_find_state (COMP_DO_CONCURRENT))
4723 : : {
4724 : 1 : gfc_error ("ALLOCATE of coarray at %C in DO CONCURRENT block");
4725 : 1 : goto cleanup;
4726 : : }
4727 : 1 : if (coarray && gfc_find_state (COMP_CRITICAL))
4728 : : {
4729 : 1 : gfc_error ("ALLOCATE of coarray at %C in CRITICAL block");
4730 : 1 : goto cleanup;
4731 : : }
4732 : : }
4733 : :
4734 : : /* Check for F08:C628. */
4735 : 16568 : sym = tail->expr->symtree->n.sym;
4736 : 16568 : b1 = !(tail->expr->ref
4737 : 12488 : && (tail->expr->ref->type == REF_COMPONENT
4738 : : || tail->expr->ref->type == REF_ARRAY));
4739 : 16568 : if (sym && sym->ts.type == BT_CLASS && sym->attr.class_ok)
4740 : 3272 : b2 = !(CLASS_DATA (sym)->attr.allocatable
4741 : : || CLASS_DATA (sym)->attr.class_pointer);
4742 : : else
4743 : 13296 : b2 = sym && !(sym->attr.allocatable || sym->attr.pointer
4744 : : || sym->attr.proc_pointer);
4745 : 16568 : b3 = sym && sym->ns && sym->ns->proc_name
4746 : 16568 : && (sym->ns->proc_name->attr.allocatable
4747 : : || sym->ns->proc_name->attr.pointer
4748 : 16568 : || sym->ns->proc_name->attr.proc_pointer);
4749 : 16568 : if (b1 && b2 && !b3)
4750 : : {
4751 : 6 : gfc_error ("Allocate-object at %L is neither a data pointer "
4752 : : "nor an allocatable variable", &tail->expr->where);
4753 : 6 : goto cleanup;
4754 : : }
4755 : :
4756 : : /* The ALLOCATE statement had an optional typespec. Check the
4757 : : constraints. */
4758 : 16562 : if (ts.type != BT_UNKNOWN)
4759 : : {
4760 : : /* Enforce F03:C624. */
4761 : 1607 : if (!gfc_type_compatible (&tail->expr->ts, &ts))
4762 : : {
4763 : 13 : gfc_error ("Type of entity at %L is type incompatible with "
4764 : 13 : "typespec", &tail->expr->where);
4765 : 13 : goto cleanup;
4766 : : }
4767 : :
4768 : : /* Enforce F03:C627. */
4769 : 1594 : if (ts.kind != tail->expr->ts.kind && !UNLIMITED_POLY (tail->expr))
4770 : : {
4771 : 8 : gfc_error ("Kind type parameter for entity at %L differs from "
4772 : : "the kind type parameter of the typespec",
4773 : : &tail->expr->where);
4774 : 8 : goto cleanup;
4775 : : }
4776 : : }
4777 : :
4778 : 16541 : if (tail->expr->ts.type == BT_DERIVED)
4779 : 2453 : tail->expr->ts.u.derived = gfc_use_derived (tail->expr->ts.u.derived);
4780 : :
4781 : 16541 : if (type_param_spec_list)
4782 : 41 : tail->expr->param_list = gfc_copy_actual_arglist (type_param_spec_list);
4783 : :
4784 : 16541 : saw_unlimited = saw_unlimited | UNLIMITED_POLY (tail->expr);
4785 : :
4786 : 16541 : if (gfc_peek_ascii_char () == '(' && !sym->attr.dimension)
4787 : : {
4788 : 2 : gfc_error ("Shape specification for allocatable scalar at %C");
4789 : 2 : goto cleanup;
4790 : : }
4791 : :
4792 : 16539 : if (gfc_match_char (',') != MATCH_YES)
4793 : : break;
4794 : :
4795 : 6846 : alloc_opt_list:
4796 : :
4797 : 6973 : m = gfc_match (" stat = %e", &tmp);
4798 : 6973 : if (m == MATCH_ERROR)
4799 : 7 : goto cleanup;
4800 : 6966 : if (m == MATCH_YES)
4801 : : {
4802 : : /* Enforce C630. */
4803 : 312 : if (saw_stat)
4804 : : {
4805 : 1 : gfc_error ("Redundant STAT tag found at %L", &tmp->where);
4806 : 1 : goto cleanup;
4807 : : }
4808 : :
4809 : 311 : stat = tmp;
4810 : 311 : tmp = NULL;
4811 : 311 : saw_stat = true;
4812 : :
4813 : 311 : if (stat->expr_type == EXPR_CONSTANT)
4814 : : {
4815 : 5 : gfc_error ("STAT tag at %L cannot be a constant", &stat->where);
4816 : 5 : goto cleanup;
4817 : : }
4818 : :
4819 : 306 : if (gfc_check_do_variable (stat->symtree))
4820 : 0 : goto cleanup;
4821 : :
4822 : 306 : if (gfc_match_char (',') == MATCH_YES)
4823 : 80 : goto alloc_opt_list;
4824 : : }
4825 : :
4826 : 6880 : m = gfc_match (" errmsg = %e", &tmp);
4827 : 6880 : if (m == MATCH_ERROR)
4828 : 0 : goto cleanup;
4829 : 6880 : if (m == MATCH_YES)
4830 : : {
4831 : 85 : if (!gfc_notify_std (GFC_STD_F2003, "ERRMSG tag at %L", &tmp->where))
4832 : 1 : goto cleanup;
4833 : :
4834 : : /* Enforce C630. */
4835 : 84 : if (saw_errmsg)
4836 : : {
4837 : 1 : gfc_error ("Redundant ERRMSG tag found at %L", &tmp->where);
4838 : 1 : goto cleanup;
4839 : : }
4840 : :
4841 : 83 : errmsg = tmp;
4842 : 83 : tmp = NULL;
4843 : 83 : saw_errmsg = true;
4844 : :
4845 : 83 : if (gfc_match_char (',') == MATCH_YES)
4846 : 4 : goto alloc_opt_list;
4847 : : }
4848 : :
4849 : 6874 : m = gfc_match (" source = %e", &tmp);
4850 : 6874 : if (m == MATCH_ERROR)
4851 : 2 : goto cleanup;
4852 : 6872 : if (m == MATCH_YES)
4853 : : {
4854 : 3266 : if (!gfc_notify_std (GFC_STD_F2003, "SOURCE tag at %L", &tmp->where))
4855 : 1 : goto cleanup;
4856 : :
4857 : : /* Enforce C630. */
4858 : 3265 : if (saw_source)
4859 : : {
4860 : 1 : gfc_error ("Redundant SOURCE tag found at %L", &tmp->where);
4861 : 1 : goto cleanup;
4862 : : }
4863 : :
4864 : : /* The next 2 conditionals check C631. */
4865 : 3264 : if (ts.type != BT_UNKNOWN)
4866 : : {
4867 : 1 : gfc_error ("SOURCE tag at %L conflicts with the typespec at %L",
4868 : 1 : &tmp->where, &old_locus);
4869 : 1 : goto cleanup;
4870 : : }
4871 : :
4872 : 3263 : if (head->next
4873 : 3286 : && !gfc_notify_std (GFC_STD_F2008, "SOURCE tag at %L"
4874 : : " with more than a single allocate object",
4875 : 23 : &tmp->where))
4876 : 1 : goto cleanup;
4877 : :
4878 : 3262 : source = tmp;
4879 : 3262 : tmp = NULL;
4880 : 3262 : saw_source = true;
4881 : :
4882 : 3262 : if (gfc_match_char (',') == MATCH_YES)
4883 : 40 : goto alloc_opt_list;
4884 : : }
4885 : :
4886 : 6828 : m = gfc_match (" mold = %e", &tmp);
4887 : 6828 : if (m == MATCH_ERROR)
4888 : 0 : goto cleanup;
4889 : 6828 : if (m == MATCH_YES)
4890 : : {
4891 : 323 : if (!gfc_notify_std (GFC_STD_F2008, "MOLD tag at %L", &tmp->where))
4892 : 1 : goto cleanup;
4893 : :
4894 : : /* Check F08:C636. */
4895 : 322 : if (saw_mold)
4896 : : {
4897 : 1 : gfc_error ("Redundant MOLD tag found at %L", &tmp->where);
4898 : 1 : goto cleanup;
4899 : : }
4900 : :
4901 : : /* Check F08:C637. */
4902 : 321 : if (ts.type != BT_UNKNOWN)
4903 : : {
4904 : 1 : gfc_error ("MOLD tag at %L conflicts with the typespec at %L",
4905 : 1 : &tmp->where, &old_locus);
4906 : 1 : goto cleanup;
4907 : : }
4908 : :
4909 : 320 : mold = tmp;
4910 : 320 : tmp = NULL;
4911 : 320 : saw_mold = true;
4912 : 320 : mold->mold = 1;
4913 : :
4914 : 320 : if (gfc_match_char (',') == MATCH_YES)
4915 : 3 : goto alloc_opt_list;
4916 : : }
4917 : :
4918 : 6822 : gfc_gobble_whitespace ();
4919 : :
4920 : 6822 : if (gfc_peek_char () == ')')
4921 : : break;
4922 : : }
4923 : :
4924 : 13537 : if (gfc_match (" )%t") != MATCH_YES)
4925 : 1 : goto syntax;
4926 : :
4927 : : /* Check F08:C637. */
4928 : 13536 : if (source && mold)
4929 : : {
4930 : 1 : gfc_error ("MOLD tag at %L conflicts with SOURCE tag at %L",
4931 : : &mold->where, &source->where);
4932 : 1 : goto cleanup;
4933 : : }
4934 : :
4935 : : /* Check F03:C623, */
4936 : 13535 : if (saw_deferred && ts.type == BT_UNKNOWN && !source && !mold)
4937 : : {
4938 : 1 : gfc_error ("Allocate-object at %L with a deferred type parameter "
4939 : : "requires either a type-spec or SOURCE tag or a MOLD tag",
4940 : : &deferred_locus);
4941 : 1 : goto cleanup;
4942 : : }
4943 : :
4944 : : /* Check F03:C625, */
4945 : 13534 : if (saw_unlimited && ts.type == BT_UNKNOWN && !source && !mold)
4946 : : {
4947 : 2 : for (tail = head; tail; tail = tail->next)
4948 : : {
4949 : 1 : if (UNLIMITED_POLY (tail->expr))
4950 : 1 : gfc_error ("Unlimited polymorphic allocate-object at %L "
4951 : : "requires either a type-spec or SOURCE tag "
4952 : : "or a MOLD tag", &tail->expr->where);
4953 : : }
4954 : 1 : goto cleanup;
4955 : : }
4956 : :
4957 : 13533 : new_st.op = EXEC_ALLOCATE;
4958 : 13533 : new_st.expr1 = stat;
4959 : 13533 : new_st.expr2 = errmsg;
4960 : 13533 : if (source)
4961 : 3260 : new_st.expr3 = source;
4962 : : else
4963 : 10273 : new_st.expr3 = mold;
4964 : 13533 : new_st.ext.alloc.list = head;
4965 : 13533 : new_st.ext.alloc.ts = ts;
4966 : :
4967 : 13533 : if (type_param_spec_list)
4968 : 41 : gfc_free_actual_arglist (type_param_spec_list);
4969 : :
4970 : : return MATCH_YES;
4971 : :
4972 : 1 : syntax:
4973 : 1 : gfc_syntax_error (ST_ALLOCATE);
4974 : :
4975 : 94 : cleanup:
4976 : 94 : gfc_free_expr (errmsg);
4977 : 94 : gfc_free_expr (source);
4978 : 94 : gfc_free_expr (stat);
4979 : 94 : gfc_free_expr (mold);
4980 : 94 : if (tmp && tmp->expr_type) gfc_free_expr (tmp);
4981 : 94 : gfc_free_alloc_list (head);
4982 : 94 : if (type_param_spec_list)
4983 : 0 : gfc_free_actual_arglist (type_param_spec_list);
4984 : : return MATCH_ERROR;
4985 : : }
4986 : :
4987 : :
4988 : : /* Match a NULLIFY statement. A NULLIFY statement is transformed into
4989 : : a set of pointer assignments to intrinsic NULL(). */
4990 : :
4991 : : match
4992 : 574 : gfc_match_nullify (void)
4993 : : {
4994 : 574 : gfc_code *tail;
4995 : 574 : gfc_expr *e, *p;
4996 : 574 : match m;
4997 : :
4998 : 574 : tail = NULL;
4999 : :
5000 : 574 : if (gfc_match_char ('(') != MATCH_YES)
5001 : 0 : goto syntax;
5002 : :
5003 : 978 : for (;;)
5004 : : {
5005 : 978 : m = gfc_match_variable (&p, 0);
5006 : 978 : if (m == MATCH_ERROR)
5007 : 2 : goto cleanup;
5008 : 976 : if (m == MATCH_NO)
5009 : 0 : goto syntax;
5010 : :
5011 : 976 : if (gfc_check_do_variable (p->symtree))
5012 : 0 : goto cleanup;
5013 : :
5014 : : /* F2008, C1242. */
5015 : 976 : if (gfc_is_coindexed (p))
5016 : : {
5017 : 1 : gfc_error ("Pointer object at %C shall not be coindexed");
5018 : 1 : goto cleanup;
5019 : : }
5020 : :
5021 : : /* Check for valid array pointer object. Bounds remapping is not
5022 : : allowed with NULLIFY. */
5023 : 975 : if (p->ref)
5024 : : {
5025 : : gfc_ref *remap = p->ref;
5026 : 924 : for (; remap; remap = remap->next)
5027 : 481 : if (!remap->next && remap->type == REF_ARRAY
5028 : 319 : && remap->u.ar.type != AR_FULL)
5029 : : break;
5030 : : if (remap)
5031 : : {
5032 : 2 : gfc_error ("NULLIFY does not allow bounds remapping for "
5033 : : "pointer object at %C");
5034 : 2 : goto cleanup;
5035 : : }
5036 : : }
5037 : :
5038 : : /* build ' => NULL() '. */
5039 : 973 : e = gfc_get_null_expr (&gfc_current_locus);
5040 : :
5041 : : /* Chain to list. */
5042 : 973 : if (tail == NULL)
5043 : : {
5044 : 570 : tail = &new_st;
5045 : 570 : tail->op = EXEC_POINTER_ASSIGN;
5046 : : }
5047 : : else
5048 : : {
5049 : 403 : tail->next = gfc_get_code (EXEC_POINTER_ASSIGN);
5050 : 403 : tail = tail->next;
5051 : : }
5052 : :
5053 : 973 : tail->expr1 = p;
5054 : 973 : tail->expr2 = e;
5055 : :
5056 : 973 : if (gfc_match (" )%t") == MATCH_YES)
5057 : : break;
5058 : 404 : if (gfc_match_char (',') != MATCH_YES)
5059 : 0 : goto syntax;
5060 : : }
5061 : :
5062 : : return MATCH_YES;
5063 : :
5064 : 0 : syntax:
5065 : 0 : gfc_syntax_error (ST_NULLIFY);
5066 : :
5067 : 5 : cleanup:
5068 : 5 : gfc_free_statements (new_st.next);
5069 : 5 : new_st.next = NULL;
5070 : 5 : gfc_free_expr (new_st.expr1);
5071 : 5 : new_st.expr1 = NULL;
5072 : 5 : gfc_free_expr (new_st.expr2);
5073 : 5 : new_st.expr2 = NULL;
5074 : 5 : gfc_free_expr (p);
5075 : 5 : return MATCH_ERROR;
5076 : : }
5077 : :
5078 : :
5079 : : /* Match a DEALLOCATE statement. */
5080 : :
5081 : : match
5082 : 5668 : gfc_match_deallocate (void)
5083 : : {
5084 : 5668 : gfc_alloc *head, *tail;
5085 : 5668 : gfc_expr *stat, *errmsg, *tmp;
5086 : 5668 : gfc_symbol *sym;
5087 : 5668 : match m;
5088 : 5668 : bool saw_stat, saw_errmsg, b1, b2;
5089 : :
5090 : 5668 : head = tail = NULL;
5091 : 5668 : stat = errmsg = tmp = NULL;
5092 : 5668 : saw_stat = saw_errmsg = false;
5093 : :
5094 : 5668 : if (gfc_match_char ('(') != MATCH_YES)
5095 : 0 : goto syntax;
5096 : :
5097 : 7795 : for (;;)
5098 : : {
5099 : 7795 : if (head == NULL)
5100 : 5668 : head = tail = gfc_get_alloc ();
5101 : : else
5102 : : {
5103 : 2127 : tail->next = gfc_get_alloc ();
5104 : 2127 : tail = tail->next;
5105 : : }
5106 : :
5107 : 7795 : m = gfc_match_variable (&tail->expr, 0);
5108 : 7795 : if (m == MATCH_ERROR)
5109 : 0 : goto cleanup;
5110 : 7795 : if (m == MATCH_NO)
5111 : 0 : goto syntax;
5112 : :
5113 : 7795 : if (tail->expr->expr_type == EXPR_CONSTANT)
5114 : : {
5115 : 1 : gfc_error ("Unexpected constant at %C");
5116 : 1 : goto cleanup;
5117 : : }
5118 : :
5119 : 7794 : if (gfc_check_do_variable (tail->expr->symtree))
5120 : 0 : goto cleanup;
5121 : :
5122 : 7794 : sym = tail->expr->symtree->n.sym;
5123 : :
5124 : 7794 : bool impure = gfc_impure_variable (sym);
5125 : 7794 : if (impure && gfc_pure (NULL))
5126 : : {
5127 : 0 : gfc_error ("Illegal allocate-object at %C for a PURE procedure");
5128 : 0 : goto cleanup;
5129 : : }
5130 : :
5131 : 7794 : if (impure)
5132 : 416 : gfc_unset_implicit_pure (NULL);
5133 : :
5134 : 7794 : if (gfc_is_coarray (tail->expr)
5135 : 7794 : && gfc_find_state (COMP_DO_CONCURRENT))
5136 : : {
5137 : 1 : gfc_error ("DEALLOCATE of coarray at %C in DO CONCURRENT block");
5138 : 1 : goto cleanup;
5139 : : }
5140 : :
5141 : 7793 : if (gfc_is_coarray (tail->expr)
5142 : 7793 : && gfc_find_state (COMP_CRITICAL))
5143 : : {
5144 : 1 : gfc_error ("DEALLOCATE of coarray at %C in CRITICAL block");
5145 : 1 : goto cleanup;
5146 : : }
5147 : :
5148 : : /* FIXME: disable the checking on derived types. */
5149 : 7792 : b1 = !(tail->expr->ref
5150 : 5850 : && (tail->expr->ref->type == REF_COMPONENT
5151 : : || tail->expr->ref->type == REF_ARRAY));
5152 : 7792 : if (sym && sym->ts.type == BT_CLASS)
5153 : 1489 : b2 = !(CLASS_DATA (sym) && (CLASS_DATA (sym)->attr.allocatable
5154 : 1486 : || CLASS_DATA (sym)->attr.class_pointer));
5155 : : else
5156 : 6303 : b2 = sym && !(sym->attr.allocatable || sym->attr.pointer
5157 : : || sym->attr.proc_pointer);
5158 : 1323 : if (b1 && b2)
5159 : : {
5160 : 3 : gfc_error ("Allocate-object at %C is not a nonprocedure pointer "
5161 : : "nor an allocatable variable");
5162 : 3 : goto cleanup;
5163 : : }
5164 : :
5165 : 7789 : if (gfc_match_char (',') != MATCH_YES)
5166 : : break;
5167 : :
5168 : 2441 : dealloc_opt_list:
5169 : :
5170 : 2506 : m = gfc_match (" stat = %e", &tmp);
5171 : 2506 : if (m == MATCH_ERROR)
5172 : 2 : goto cleanup;
5173 : 2504 : if (m == MATCH_YES)
5174 : : {
5175 : 311 : if (saw_stat)
5176 : : {
5177 : 1 : gfc_error ("Redundant STAT tag found at %L", &tmp->where);
5178 : 1 : gfc_free_expr (tmp);
5179 : 1 : goto cleanup;
5180 : : }
5181 : :
5182 : 310 : stat = tmp;
5183 : 310 : saw_stat = true;
5184 : :
5185 : 310 : if (gfc_check_do_variable (stat->symtree))
5186 : 0 : goto cleanup;
5187 : :
5188 : 310 : if (gfc_match_char (',') == MATCH_YES)
5189 : 61 : goto dealloc_opt_list;
5190 : : }
5191 : :
5192 : 2442 : m = gfc_match (" errmsg = %e", &tmp);
5193 : 2442 : if (m == MATCH_ERROR)
5194 : 0 : goto cleanup;
5195 : 2442 : if (m == MATCH_YES)
5196 : : {
5197 : 66 : if (!gfc_notify_std (GFC_STD_F2003, "ERRMSG at %L", &tmp->where))
5198 : 0 : goto cleanup;
5199 : :
5200 : 66 : if (saw_errmsg)
5201 : : {
5202 : 1 : gfc_error ("Redundant ERRMSG tag found at %L", &tmp->where);
5203 : 1 : gfc_free_expr (tmp);
5204 : 1 : goto cleanup;
5205 : : }
5206 : :
5207 : 65 : errmsg = tmp;
5208 : 65 : saw_errmsg = true;
5209 : :
5210 : 65 : if (gfc_match_char (',') == MATCH_YES)
5211 : 4 : goto dealloc_opt_list;
5212 : : }
5213 : :
5214 : 2437 : gfc_gobble_whitespace ();
5215 : :
5216 : 2437 : if (gfc_peek_char () == ')')
5217 : : break;
5218 : : }
5219 : :
5220 : 5658 : if (gfc_match (" )%t") != MATCH_YES)
5221 : 1 : goto syntax;
5222 : :
5223 : 5657 : new_st.op = EXEC_DEALLOCATE;
5224 : 5657 : new_st.expr1 = stat;
5225 : 5657 : new_st.expr2 = errmsg;
5226 : 5657 : new_st.ext.alloc.list = head;
5227 : :
5228 : 5657 : return MATCH_YES;
5229 : :
5230 : 1 : syntax:
5231 : 1 : gfc_syntax_error (ST_DEALLOCATE);
5232 : :
5233 : 11 : cleanup:
5234 : 11 : gfc_free_expr (errmsg);
5235 : 11 : gfc_free_expr (stat);
5236 : 11 : gfc_free_alloc_list (head);
5237 : 11 : return MATCH_ERROR;
5238 : : }
5239 : :
5240 : :
5241 : : /* Match a RETURN statement. */
5242 : :
5243 : : match
5244 : 3080 : gfc_match_return (void)
5245 : : {
5246 : 3080 : gfc_expr *e;
5247 : 3080 : match m;
5248 : 3080 : gfc_compile_state s;
5249 : :
5250 : 3080 : e = NULL;
5251 : :
5252 : 3080 : if (gfc_find_state (COMP_CRITICAL))
5253 : : {
5254 : 1 : gfc_error ("Image control statement RETURN at %C in CRITICAL block");
5255 : 1 : return MATCH_ERROR;
5256 : : }
5257 : :
5258 : 3079 : if (gfc_find_state (COMP_DO_CONCURRENT))
5259 : : {
5260 : 1 : gfc_error ("Image control statement RETURN at %C in DO CONCURRENT block");
5261 : 1 : return MATCH_ERROR;
5262 : : }
5263 : :
5264 : 3078 : if (gfc_match_eos () == MATCH_YES)
5265 : 3024 : goto done;
5266 : :
5267 : 54 : if (!gfc_find_state (COMP_SUBROUTINE))
5268 : : {
5269 : 0 : gfc_error ("Alternate RETURN statement at %C is only allowed within "
5270 : : "a SUBROUTINE");
5271 : 0 : goto cleanup;
5272 : : }
5273 : :
5274 : 54 : if (gfc_current_form == FORM_FREE)
5275 : : {
5276 : : /* The following are valid, so we can't require a blank after the
5277 : : RETURN keyword:
5278 : : return+1
5279 : : return(1) */
5280 : 54 : char c = gfc_peek_ascii_char ();
5281 : 54 : if (ISALPHA (c) || ISDIGIT (c))
5282 : : return MATCH_NO;
5283 : : }
5284 : :
5285 : 53 : m = gfc_match (" %e%t", &e);
5286 : 53 : if (m == MATCH_YES)
5287 : 53 : goto done;
5288 : 0 : if (m == MATCH_ERROR)
5289 : 0 : goto cleanup;
5290 : :
5291 : 0 : gfc_syntax_error (ST_RETURN);
5292 : :
5293 : 0 : cleanup:
5294 : 0 : gfc_free_expr (e);
5295 : 0 : return MATCH_ERROR;
5296 : :
5297 : 3077 : done:
5298 : 3077 : gfc_enclosing_unit (&s);
5299 : 3077 : if (s == COMP_PROGRAM
5300 : 3077 : && !gfc_notify_std (GFC_STD_GNU, "RETURN statement in "
5301 : : "main program at %C"))
5302 : : return MATCH_ERROR;
5303 : :
5304 : 3077 : new_st.op = EXEC_RETURN;
5305 : 3077 : new_st.expr1 = e;
5306 : :
5307 : 3077 : return MATCH_YES;
5308 : : }
5309 : :
5310 : :
5311 : : /* Match the call of a type-bound procedure, if CALL%var has already been
5312 : : matched and var found to be a derived-type variable. */
5313 : :
5314 : : static match
5315 : 1389 : match_typebound_call (gfc_symtree* varst)
5316 : : {
5317 : 1389 : gfc_expr* base;
5318 : 1389 : match m;
5319 : :
5320 : 1389 : base = gfc_get_expr ();
5321 : 1389 : base->expr_type = EXPR_VARIABLE;
5322 : 1389 : base->symtree = varst;
5323 : 1389 : base->where = gfc_current_locus;
5324 : 1389 : gfc_set_sym_referenced (varst->n.sym);
5325 : :
5326 : 1389 : m = gfc_match_varspec (base, 0, true, true);
5327 : 1389 : if (m == MATCH_NO)
5328 : 0 : gfc_error ("Expected component reference at %C");
5329 : 1389 : if (m != MATCH_YES)
5330 : : {
5331 : 5 : gfc_free_expr (base);
5332 : 5 : return MATCH_ERROR;
5333 : : }
5334 : :
5335 : 1384 : if (gfc_match_eos () != MATCH_YES)
5336 : : {
5337 : 1 : gfc_error ("Junk after CALL at %C");
5338 : 1 : gfc_free_expr (base);
5339 : 1 : return MATCH_ERROR;
5340 : : }
5341 : :
5342 : 1383 : if (base->expr_type == EXPR_COMPCALL)
5343 : 1259 : new_st.op = EXEC_COMPCALL;
5344 : 124 : else if (base->expr_type == EXPR_PPC)
5345 : 123 : new_st.op = EXEC_CALL_PPC;
5346 : : else
5347 : : {
5348 : 1 : gfc_error ("Expected type-bound procedure or procedure pointer component "
5349 : : "at %C");
5350 : 1 : gfc_free_expr (base);
5351 : 1 : return MATCH_ERROR;
5352 : : }
5353 : 1382 : new_st.expr1 = base;
5354 : :
5355 : 1382 : return MATCH_YES;
5356 : : }
5357 : :
5358 : :
5359 : : /* Match a CALL statement. The tricky part here are possible
5360 : : alternate return specifiers. We handle these by having all
5361 : : "subroutines" actually return an integer via a register that gives
5362 : : the return number. If the call specifies alternate returns, we
5363 : : generate code for a SELECT statement whose case clauses contain
5364 : : GOTOs to the various labels. */
5365 : :
5366 : : match
5367 : 77782 : gfc_match_call (void)
5368 : : {
5369 : 77782 : char name[GFC_MAX_SYMBOL_LEN + 1];
5370 : 77782 : gfc_actual_arglist *a, *arglist;
5371 : 77782 : gfc_case *new_case;
5372 : 77782 : gfc_symbol *sym;
5373 : 77782 : gfc_symtree *st;
5374 : 77782 : gfc_code *c;
5375 : 77782 : match m;
5376 : 77782 : int i;
5377 : :
5378 : 77782 : arglist = NULL;
5379 : :
5380 : 77782 : m = gfc_match ("% %n", name);
5381 : 77782 : if (m == MATCH_NO)
5382 : 0 : goto syntax;
5383 : 77782 : if (m != MATCH_YES)
5384 : : return m;
5385 : :
5386 : 77782 : if (gfc_get_ha_sym_tree (name, &st))
5387 : : return MATCH_ERROR;
5388 : :
5389 : 77780 : sym = st->n.sym;
5390 : :
5391 : : /* If this is a variable of derived-type, it probably starts a type-bound
5392 : : procedure call. Associate variable targets have to be resolved for the
5393 : : target type. */
5394 : 77780 : if (((sym->attr.flavor != FL_PROCEDURE
5395 : 55482 : || gfc_is_function_return_value (sym, gfc_current_ns))
5396 : 22300 : && (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS))
5397 : 77780 : ||
5398 : 76391 : (sym->assoc && sym->assoc->target
5399 : 0 : && gfc_resolve_expr (sym->assoc->target)
5400 : 0 : && (sym->assoc->target->ts.type == BT_DERIVED
5401 : 0 : || sym->assoc->target->ts.type == BT_CLASS)))
5402 : 1389 : return match_typebound_call (st);
5403 : :
5404 : : /* If it does not seem to be callable (include functions so that the
5405 : : right association is made. They are thrown out in resolution.)
5406 : : ... */
5407 : 76391 : if (!sym->attr.generic
5408 : : && !sym->attr.proc_pointer
5409 : : && !sym->attr.subroutine
5410 : 76391 : && !sym->attr.function)
5411 : : {
5412 : 21656 : if (!(sym->attr.external && !sym->attr.referenced))
5413 : : {
5414 : : /* ...create a symbol in this scope... */
5415 : 21028 : if (sym->ns != gfc_current_ns
5416 : 21028 : && gfc_get_sym_tree (name, NULL, &st, false) == 1)
5417 : : return MATCH_ERROR;
5418 : :
5419 : 21028 : if (sym != st->n.sym)
5420 : 21656 : sym = st->n.sym;
5421 : : }
5422 : :
5423 : : /* ...and then to try to make the symbol into a subroutine. */
5424 : 21656 : if (!gfc_add_subroutine (&sym->attr, sym->name, NULL))
5425 : : return MATCH_ERROR;
5426 : : }
5427 : :
5428 : 76389 : gfc_set_sym_referenced (sym);
5429 : :
5430 : 76389 : if (gfc_match_eos () != MATCH_YES)
5431 : : {
5432 : 69514 : m = gfc_match_actual_arglist (1, &arglist);
5433 : 69514 : if (m == MATCH_NO)
5434 : 0 : goto syntax;
5435 : 69514 : if (m == MATCH_ERROR)
5436 : 8 : goto cleanup;
5437 : :
5438 : 69506 : if (gfc_match_eos () != MATCH_YES)
5439 : 1 : goto syntax;
5440 : : }
5441 : :
5442 : : /* Walk the argument list looking for invalid BOZ. */
5443 : 239933 : for (a = arglist; a; a = a->next)
5444 : 163554 : if (a->expr && a->expr->ts.type == BT_BOZ)
5445 : : {
5446 : 1 : gfc_error ("A BOZ literal constant at %L cannot appear as an actual "
5447 : : "argument in a subroutine reference", &a->expr->where);
5448 : 1 : goto cleanup;
5449 : : }
5450 : :
5451 : :
5452 : : /* If any alternate return labels were found, construct a SELECT
5453 : : statement that will jump to the right place. */
5454 : :
5455 : 239640 : i = 0;
5456 : 239640 : for (a = arglist; a; a = a->next)
5457 : 163411 : if (a->expr == NULL)
5458 : : {
5459 : : i = 1;
5460 : : break;
5461 : : }
5462 : :
5463 : 76379 : if (i)
5464 : : {
5465 : 150 : gfc_symtree *select_st;
5466 : 150 : gfc_symbol *select_sym;
5467 : 150 : char name[GFC_MAX_SYMBOL_LEN + 1];
5468 : :
5469 : 150 : new_st.next = c = gfc_get_code (EXEC_SELECT);
5470 : 150 : sprintf (name, "_result_%s", sym->name);
5471 : 150 : gfc_get_ha_sym_tree (name, &select_st); /* Can't fail. */
5472 : :
5473 : 150 : select_sym = select_st->n.sym;
5474 : 150 : select_sym->ts.type = BT_INTEGER;
5475 : 150 : select_sym->ts.kind = gfc_default_integer_kind;
5476 : 150 : gfc_set_sym_referenced (select_sym);
5477 : 150 : c->expr1 = gfc_get_expr ();
5478 : 150 : c->expr1->expr_type = EXPR_VARIABLE;
5479 : 150 : c->expr1->symtree = select_st;
5480 : 150 : c->expr1->ts = select_sym->ts;
5481 : 150 : c->expr1->where = gfc_current_locus;
5482 : :
5483 : 150 : i = 0;
5484 : 618 : for (a = arglist; a; a = a->next)
5485 : : {
5486 : 468 : if (a->expr != NULL)
5487 : 232 : continue;
5488 : :
5489 : 236 : if (!gfc_reference_st_label (a->label, ST_LABEL_TARGET))
5490 : 0 : continue;
5491 : :
5492 : 236 : i++;
5493 : :
5494 : 236 : c->block = gfc_get_code (EXEC_SELECT);
5495 : 236 : c = c->block;
5496 : :
5497 : 236 : new_case = gfc_get_case ();
5498 : 236 : new_case->high = gfc_get_int_expr (gfc_default_integer_kind, NULL, i);
5499 : 236 : new_case->low = new_case->high;
5500 : 236 : c->ext.block.case_list = new_case;
5501 : :
5502 : 236 : c->next = gfc_get_code (EXEC_GOTO);
5503 : 236 : c->next->label1 = a->label;
5504 : : }
5505 : : }
5506 : :
5507 : 76379 : new_st.op = EXEC_CALL;
5508 : 76379 : new_st.symtree = st;
5509 : 76379 : new_st.ext.actual = arglist;
5510 : :
5511 : 76379 : return MATCH_YES;
5512 : :
5513 : 1 : syntax:
5514 : 1 : gfc_syntax_error (ST_CALL);
5515 : :
5516 : 10 : cleanup:
5517 : 10 : gfc_free_actual_arglist (arglist);
5518 : 10 : return MATCH_ERROR;
5519 : : }
5520 : :
5521 : :
5522 : : /* Given a name, return a pointer to the common head structure,
5523 : : creating it if it does not exist. If FROM_MODULE is nonzero, we
5524 : : mangle the name so that it doesn't interfere with commons defined
5525 : : in the using namespace.
5526 : : TODO: Add to global symbol tree. */
5527 : :
5528 : : gfc_common_head *
5529 : 1995 : gfc_get_common (const char *name, int from_module)
5530 : : {
5531 : 1995 : gfc_symtree *st;
5532 : 1995 : static int serial = 0;
5533 : 1995 : char mangled_name[GFC_MAX_SYMBOL_LEN + 1];
5534 : :
5535 : 1995 : if (from_module)
5536 : : {
5537 : : /* A use associated common block is only needed to correctly layout
5538 : : the variables it contains. */
5539 : 170 : snprintf (mangled_name, GFC_MAX_SYMBOL_LEN, "_%d_%s", serial++, name);
5540 : 170 : st = gfc_new_symtree (&gfc_current_ns->common_root, mangled_name);
5541 : : }
5542 : : else
5543 : : {
5544 : 1825 : st = gfc_find_symtree (gfc_current_ns->common_root, name);
5545 : :
5546 : 1825 : if (st == NULL)
5547 : 1737 : st = gfc_new_symtree (&gfc_current_ns->common_root, name);
5548 : : }
5549 : :
5550 : 1995 : if (st->n.common == NULL)
5551 : : {
5552 : 1907 : st->n.common = gfc_get_common_head ();
5553 : 1907 : st->n.common->where = gfc_current_locus;
5554 : 1907 : strcpy (st->n.common->name, name);
5555 : : }
5556 : :
5557 : 1995 : return st->n.common;
5558 : : }
5559 : :
5560 : :
5561 : : /* Match a common block name. */
5562 : :
5563 : : match
5564 : 2031 : gfc_match_common_name (char *name)
5565 : : {
5566 : 2031 : match m;
5567 : :
5568 : 2031 : if (gfc_match_char ('/') == MATCH_NO)
5569 : : {
5570 : 122 : name[0] = '\0';
5571 : 122 : return MATCH_YES;
5572 : : }
5573 : :
5574 : 1909 : if (gfc_match_char ('/') == MATCH_YES)
5575 : : {
5576 : 85 : name[0] = '\0';
5577 : 85 : return MATCH_YES;
5578 : : }
5579 : :
5580 : 1824 : m = gfc_match_name (name);
5581 : :
5582 : 1824 : if (m == MATCH_ERROR)
5583 : : return MATCH_ERROR;
5584 : 1824 : if (m == MATCH_YES && gfc_match_char ('/') == MATCH_YES)
5585 : : return MATCH_YES;
5586 : :
5587 : 0 : gfc_error ("Syntax error in common block name at %C");
5588 : 0 : return MATCH_ERROR;
5589 : : }
5590 : :
5591 : :
5592 : : /* Match a COMMON statement. */
5593 : :
5594 : : match
5595 : 1951 : gfc_match_common (void)
5596 : : {
5597 : 1951 : gfc_symbol *sym, **head, *tail, *other;
5598 : 1951 : char name[GFC_MAX_SYMBOL_LEN + 1];
5599 : 1951 : gfc_common_head *t;
5600 : 1951 : gfc_array_spec *as;
5601 : 1951 : gfc_equiv *e1, *e2;
5602 : 1951 : match m;
5603 : 1951 : char c;
5604 : :
5605 : : /* COMMON has been matched. In free form source code, the next character
5606 : : needs to be whitespace or '/'. Check that here. Fixed form source
5607 : : code needs to be checked below. */
5608 : 1951 : c = gfc_peek_ascii_char ();
5609 : 1951 : if (gfc_current_form == FORM_FREE && !gfc_is_whitespace (c) && c != '/')
5610 : : return MATCH_NO;
5611 : :
5612 : 1950 : as = NULL;
5613 : :
5614 : 1955 : for (;;)
5615 : : {
5616 : 1955 : m = gfc_match_common_name (name);
5617 : 1955 : if (m == MATCH_ERROR)
5618 : 0 : goto cleanup;
5619 : :
5620 : 1955 : if (name[0] == '\0')
5621 : : {
5622 : 207 : t = &gfc_current_ns->blank_common;
5623 : 207 : if (t->head == NULL)
5624 : 205 : t->where = gfc_current_locus;
5625 : : }
5626 : : else
5627 : : {
5628 : 1748 : t = gfc_get_common (name, 0);
5629 : : }
5630 : 1955 : head = &t->head;
5631 : :
5632 : 1955 : if (*head == NULL)
5633 : : tail = NULL;
5634 : : else
5635 : : {
5636 : : tail = *head;
5637 : 114 : while (tail->common_next)
5638 : : tail = tail->common_next;
5639 : : }
5640 : :
5641 : : /* Grab the list of symbols. */
5642 : 5794 : for (;;)
5643 : : {
5644 : 5794 : m = gfc_match_symbol (&sym, 0);
5645 : 5794 : if (m == MATCH_ERROR)
5646 : 0 : goto cleanup;
5647 : 5794 : if (m == MATCH_NO)
5648 : 7 : goto syntax;
5649 : :
5650 : : /* See if we know the current common block is bind(c), and if
5651 : : so, then see if we can check if the symbol is (which it'll
5652 : : need to be). This can happen if the bind(c) attr stmt was
5653 : : applied to the common block, and the variable(s) already
5654 : : defined, before declaring the common block. */
5655 : 5787 : if (t->is_bind_c == 1)
5656 : : {
5657 : 13 : if (sym->ts.type != BT_UNKNOWN && sym->ts.is_c_interop != 1)
5658 : : {
5659 : : /* If we find an error, just print it and continue,
5660 : : cause it's just semantic, and we can see if there
5661 : : are more errors. */
5662 : 0 : gfc_error_now ("Variable %qs at %L in common block %qs "
5663 : : "at %C must be declared with a C "
5664 : : "interoperable kind since common block "
5665 : : "%qs is bind(c)",
5666 : : sym->name, &(sym->declared_at), t->name,
5667 : 0 : t->name);
5668 : : }
5669 : :
5670 : 13 : if (sym->attr.is_bind_c == 1)
5671 : 0 : gfc_error_now ("Variable %qs in common block %qs at %C cannot "
5672 : : "be bind(c) since it is not global", sym->name,
5673 : 0 : t->name);
5674 : : }
5675 : :
5676 : 5787 : if (sym->attr.in_common)
5677 : : {
5678 : 2 : gfc_error ("Symbol %qs at %C is already in a COMMON block",
5679 : : sym->name);
5680 : 2 : goto cleanup;
5681 : : }
5682 : :
5683 : 5785 : if (((sym->value != NULL && sym->value->expr_type != EXPR_NULL)
5684 : 5785 : || sym->attr.data) && gfc_current_state () != COMP_BLOCK_DATA)
5685 : : {
5686 : 6 : if (!gfc_notify_std (GFC_STD_GNU, "Initialized symbol %qs at "
5687 : : "%C can only be COMMON in BLOCK DATA",
5688 : : sym->name))
5689 : 2 : goto cleanup;
5690 : : }
5691 : :
5692 : : /* F2018:R874: common-block-object is variable-name [ (array-spec) ]
5693 : : F2018:C8121: A variable-name shall not be a name made accessible
5694 : : by use association. */
5695 : 5783 : if (sym->attr.use_assoc)
5696 : : {
5697 : 2 : gfc_error ("Symbol %qs at %C is USE associated from module %qs "
5698 : : "and cannot occur in COMMON", sym->name, sym->module);
5699 : 2 : goto cleanup;
5700 : : }
5701 : :
5702 : : /* Deal with an optional array specification after the
5703 : : symbol name. */
5704 : 5781 : m = gfc_match_array_spec (&as, true, true);
5705 : 5781 : if (m == MATCH_ERROR)
5706 : 2 : goto cleanup;
5707 : :
5708 : 5779 : if (m == MATCH_YES)
5709 : : {
5710 : 2127 : if (as->type != AS_EXPLICIT)
5711 : : {
5712 : 0 : gfc_error ("Array specification for symbol %qs in COMMON "
5713 : : "at %C must be explicit", sym->name);
5714 : 0 : goto cleanup;
5715 : : }
5716 : :
5717 : 2127 : if (as->corank)
5718 : : {
5719 : 1 : gfc_error ("Symbol %qs in COMMON at %C cannot be a "
5720 : : "coarray", sym->name);
5721 : 1 : goto cleanup;
5722 : : }
5723 : :
5724 : 2126 : if (!gfc_add_dimension (&sym->attr, sym->name, NULL))
5725 : 0 : goto cleanup;
5726 : :
5727 : 2126 : if (sym->attr.pointer)
5728 : : {
5729 : 0 : gfc_error ("Symbol %qs in COMMON at %C cannot be a "
5730 : : "POINTER array", sym->name);
5731 : 0 : goto cleanup;
5732 : : }
5733 : :
5734 : 2126 : sym->as = as;
5735 : 2126 : as = NULL;
5736 : :
5737 : : }
5738 : :
5739 : : /* Add the in_common attribute, but ignore the reported errors
5740 : : if any, and continue matching. */
5741 : 5778 : gfc_add_in_common (&sym->attr, sym->name, NULL);
5742 : :
5743 : 5778 : sym->common_block = t;
5744 : 5778 : sym->common_block->refs++;
5745 : :
5746 : 5778 : if (tail != NULL)
5747 : 3851 : tail->common_next = sym;
5748 : : else
5749 : 1927 : *head = sym;
5750 : :
5751 : 5778 : tail = sym;
5752 : :
5753 : 5778 : sym->common_head = t;
5754 : :
5755 : : /* Check to see if the symbol is already in an equivalence group.
5756 : : If it is, set the other members as being in common. */
5757 : 5778 : if (sym->attr.in_equivalence)
5758 : : {
5759 : 20 : for (e1 = gfc_current_ns->equiv; e1; e1 = e1->next)
5760 : : {
5761 : 29 : for (e2 = e1; e2; e2 = e2->eq)
5762 : 23 : if (e2->expr->symtree->n.sym == sym)
5763 : 8 : goto equiv_found;
5764 : :
5765 : 6 : continue;
5766 : :
5767 : 8 : equiv_found:
5768 : :
5769 : 23 : for (e2 = e1; e2; e2 = e2->eq)
5770 : : {
5771 : 16 : other = e2->expr->symtree->n.sym;
5772 : 16 : if (other->common_head
5773 : 9 : && other->common_head != sym->common_head)
5774 : : {
5775 : 1 : gfc_error ("Symbol %qs, in COMMON block %qs at "
5776 : : "%C is being indirectly equivalenced to "
5777 : : "another COMMON block %qs",
5778 : 1 : sym->name, sym->common_head->name,
5779 : 1 : other->common_head->name);
5780 : 1 : goto cleanup;
5781 : : }
5782 : 15 : other->attr.in_common = 1;
5783 : 15 : other->common_head = t;
5784 : : }
5785 : : }
5786 : : }
5787 : :
5788 : :
5789 : 5777 : gfc_gobble_whitespace ();
5790 : 5777 : if (gfc_match_eos () == MATCH_YES)
5791 : 1932 : goto done;
5792 : 3845 : c = gfc_peek_ascii_char ();
5793 : 3845 : if (c == '/')
5794 : : break;
5795 : 3842 : if (c != ',')
5796 : : {
5797 : : /* In Fixed form source code, gfortran can end up here for an
5798 : : expression of the form COMMONI = RHS. This may not be an
5799 : : error, so return MATCH_NO. */
5800 : 1 : if (gfc_current_form == FORM_FIXED && c == '=')
5801 : : {
5802 : 1 : gfc_free_array_spec (as);
5803 : 1 : return MATCH_NO;
5804 : : }
5805 : 0 : goto syntax;
5806 : : }
5807 : : else
5808 : 3841 : gfc_match_char (',');
5809 : :
5810 : 3841 : gfc_gobble_whitespace ();
5811 : 3841 : if (gfc_peek_ascii_char () == '/')
5812 : : break;
5813 : : }
5814 : : }
5815 : :
5816 : 1932 : done:
5817 : 1932 : return MATCH_YES;
5818 : :
5819 : 7 : syntax:
5820 : 7 : gfc_syntax_error (ST_COMMON);
5821 : :
5822 : 17 : cleanup:
5823 : 17 : gfc_free_array_spec (as);
5824 : 17 : return MATCH_ERROR;
5825 : : }
5826 : :
5827 : :
5828 : : /* Match a BLOCK DATA program unit. */
5829 : :
5830 : : match
5831 : 85 : gfc_match_block_data (void)
5832 : : {
5833 : 85 : char name[GFC_MAX_SYMBOL_LEN + 1];
5834 : 85 : gfc_symbol *sym;
5835 : 85 : match m;
5836 : :
5837 : 85 : if (!gfc_notify_std (GFC_STD_F2018_OBS, "BLOCK DATA construct at %L",
5838 : : &gfc_current_locus))
5839 : : return MATCH_ERROR;
5840 : :
5841 : 85 : if (gfc_match_eos () == MATCH_YES)
5842 : : {
5843 : 49 : gfc_new_block = NULL;
5844 : 49 : return MATCH_YES;
5845 : : }
5846 : :
5847 : 36 : m = gfc_match ("% %n%t", name);
5848 : 36 : if (m != MATCH_YES)
5849 : : return MATCH_ERROR;
5850 : :
5851 : 36 : if (gfc_get_symbol (name, NULL, &sym))
5852 : : return MATCH_ERROR;
5853 : :
5854 : 36 : if (!gfc_add_flavor (&sym->attr, FL_BLOCK_DATA, sym->name, NULL))
5855 : : return MATCH_ERROR;
5856 : :
5857 : 36 : gfc_new_block = sym;
5858 : :
5859 : 36 : return MATCH_YES;
5860 : : }
5861 : :
5862 : :
5863 : : /* Free a namelist structure. */
5864 : :
5865 : : void
5866 : 5821739 : gfc_free_namelist (gfc_namelist *name)
5867 : : {
5868 : 5821739 : gfc_namelist *n;
5869 : :
5870 : 5823828 : for (; name; name = n)
5871 : : {
5872 : 2089 : n = name->next;
5873 : 2089 : free (name);
5874 : : }
5875 : 5821739 : }
5876 : :
5877 : :
5878 : : /* Free an OpenMP namelist structure. */
5879 : :
5880 : : void
5881 : 1279279 : gfc_free_omp_namelist (gfc_omp_namelist *name, bool free_ns,
5882 : : bool free_align_allocator,
5883 : : bool free_mem_traits_space, bool free_init)
5884 : : {
5885 : 1279279 : gfc_omp_namelist *n;
5886 : 1279279 : gfc_expr *last_allocator = NULL;
5887 : 1279279 : char *last_init_interop = NULL;
5888 : :
5889 : 1324213 : for (; name; name = n)
5890 : : {
5891 : 44934 : gfc_free_expr (name->expr);
5892 : 44934 : if (free_align_allocator)
5893 : 469 : gfc_free_expr (name->u.align);
5894 : : else if (free_mem_traits_space)
5895 : : { } /* name->u.memspace_sym: shall not call gfc_free_symbol here. */
5896 : :
5897 : 44934 : if (free_ns)
5898 : 1985 : gfc_free_namespace (name->u2.ns);
5899 : 42949 : else if (free_align_allocator)
5900 : : {
5901 : 469 : if (last_allocator != name->u2.allocator)
5902 : : {
5903 : 114 : last_allocator = name->u2.allocator;
5904 : 114 : gfc_free_expr (name->u2.allocator);
5905 : : }
5906 : : }
5907 : 42480 : else if (free_mem_traits_space)
5908 : : { } /* name->u2.traits_sym: shall not call gfc_free_symbol here. */
5909 : 42394 : else if (free_init)
5910 : : {
5911 : 84 : if (name->u2.init_interop != last_init_interop)
5912 : : {
5913 : 31 : last_init_interop = name->u2.init_interop;
5914 : 31 : free (name->u2.init_interop);
5915 : : }
5916 : : }
5917 : 42310 : else if (name->u2.udr)
5918 : : {
5919 : 467 : if (name->u2.udr->combiner)
5920 : 467 : gfc_free_statement (name->u2.udr->combiner);
5921 : 467 : if (name->u2.udr->initializer)
5922 : 330 : gfc_free_statement (name->u2.udr->initializer);
5923 : 467 : free (name->u2.udr);
5924 : : }
5925 : 44934 : n = name->next;
5926 : 44934 : free (name);
5927 : : }
5928 : 1279279 : }
5929 : :
5930 : :
5931 : : /* Match a NAMELIST statement. */
5932 : :
5933 : : match
5934 : 979 : gfc_match_namelist (void)
5935 : : {
5936 : 979 : gfc_symbol *group_name, *sym;
5937 : 979 : gfc_namelist *nl;
5938 : 979 : match m, m2;
5939 : :
5940 : 979 : m = gfc_match (" / %s /", &group_name);
5941 : 979 : if (m == MATCH_NO)
5942 : 0 : goto syntax;
5943 : 979 : if (m == MATCH_ERROR)
5944 : 0 : goto error;
5945 : :
5946 : 979 : for (;;)
5947 : : {
5948 : 979 : if (group_name->ts.type != BT_UNKNOWN)
5949 : : {
5950 : 0 : gfc_error ("Namelist group name %qs at %C already has a basic "
5951 : : "type of %s", group_name->name,
5952 : : gfc_typename (&group_name->ts));
5953 : 0 : return MATCH_ERROR;
5954 : : }
5955 : :
5956 : : /* A use associated name shall not be used as a namelist group name
5957 : : (e.g. F2003:C581). It is only supported as a legacy extension. */
5958 : 979 : if (group_name->attr.flavor == FL_NAMELIST
5959 : 220 : && group_name->attr.use_assoc
5960 : 988 : && !gfc_notify_std (GFC_STD_LEGACY, "Namelist group name %qs "
5961 : : "at %C already is USE associated and can"
5962 : : "not be respecified.", group_name->name))
5963 : : return MATCH_ERROR;
5964 : :
5965 : 976 : if (group_name->attr.flavor != FL_NAMELIST
5966 : 976 : && !gfc_add_flavor (&group_name->attr, FL_NAMELIST,
5967 : : group_name->name, NULL))
5968 : : return MATCH_ERROR;
5969 : :
5970 : 2011 : for (;;)
5971 : : {
5972 : 2011 : m = gfc_match_symbol (&sym, 1);
5973 : 2011 : if (m == MATCH_NO)
5974 : 1 : goto syntax;
5975 : 2010 : if (m == MATCH_ERROR)
5976 : 0 : goto error;
5977 : :
5978 : 2010 : if (sym->ts.type == BT_UNKNOWN)
5979 : : {
5980 : 50 : if (gfc_current_ns->seen_implicit_none)
5981 : : {
5982 : : /* It is required that members of a namelist be declared
5983 : : before the namelist. We check this by checking if the
5984 : : symbol has a defined type for IMPLICIT NONE. */
5985 : 1 : gfc_error ("Symbol %qs in namelist %qs at %C must be "
5986 : : "declared before the namelist is declared.",
5987 : : sym->name, group_name->name);
5988 : 1 : gfc_error_check ();
5989 : : }
5990 : : else
5991 : : {
5992 : : /* Before the symbol is given an implicit type, check to
5993 : : see if the symbol is already available in the namespace,
5994 : : possibly through host association. Importantly, the
5995 : : symbol may be a user defined type. */
5996 : :
5997 : 49 : gfc_symbol *tmp;
5998 : :
5999 : 49 : gfc_find_symbol (sym->name, NULL, 1, &tmp);
6000 : 49 : if (tmp && tmp->attr.generic
6001 : 51 : && (tmp = gfc_find_dt_in_generic (tmp)))
6002 : : {
6003 : 2 : if (tmp->attr.flavor == FL_DERIVED)
6004 : : {
6005 : 2 : gfc_error ("Derived type %qs at %L conflicts with "
6006 : : "namelist object %qs at %C",
6007 : : tmp->name, &tmp->declared_at, sym->name);
6008 : 2 : goto error;
6009 : : }
6010 : : }
6011 : :
6012 : : /* Set type of the symbol to its implicit default type. It is
6013 : : not allowed to set it later to any other type. */
6014 : 47 : gfc_set_default_type (sym, 0, gfc_current_ns);
6015 : : }
6016 : : }
6017 : 2008 : if (sym->attr.in_namelist == 0
6018 : 2008 : && !gfc_add_in_namelist (&sym->attr, sym->name, NULL))
6019 : 2 : goto error;
6020 : :
6021 : : /* Use gfc_error_check here, rather than goto error, so that
6022 : : these are the only errors for the next two lines. */
6023 : 2006 : if (sym->as && sym->as->type == AS_ASSUMED_SIZE)
6024 : : {
6025 : 1 : gfc_error ("Assumed size array %qs in namelist %qs at "
6026 : : "%C is not allowed", sym->name, group_name->name);
6027 : 1 : gfc_error_check ();
6028 : : }
6029 : :
6030 : 2006 : nl = gfc_get_namelist ();
6031 : 2006 : nl->sym = sym;
6032 : 2006 : sym->refs++;
6033 : :
6034 : 2006 : if (group_name->namelist == NULL)
6035 : 753 : group_name->namelist = group_name->namelist_tail = nl;
6036 : : else
6037 : : {
6038 : 1253 : group_name->namelist_tail->next = nl;
6039 : 1253 : group_name->namelist_tail = nl;
6040 : : }
6041 : :
6042 : 2006 : if (gfc_match_eos () == MATCH_YES)
6043 : 969 : goto done;
6044 : :
6045 : 1037 : m = gfc_match_char (',');
6046 : :
6047 : 1037 : if (gfc_match_char ('/') == MATCH_YES)
6048 : : {
6049 : 0 : m2 = gfc_match (" %s /", &group_name);
6050 : 0 : if (m2 == MATCH_YES)
6051 : : break;
6052 : 0 : if (m2 == MATCH_ERROR)
6053 : 0 : goto error;
6054 : 0 : goto syntax;
6055 : : }
6056 : :
6057 : 1037 : if (m != MATCH_YES)
6058 : 0 : goto syntax;
6059 : : }
6060 : : }
6061 : :
6062 : 969 : done:
6063 : 969 : return MATCH_YES;
6064 : :
6065 : 1 : syntax:
6066 : 1 : gfc_syntax_error (ST_NAMELIST);
6067 : :
6068 : : error:
6069 : : return MATCH_ERROR;
6070 : : }
6071 : :
6072 : :
6073 : : /* Match a MODULE statement. */
6074 : :
6075 : : match
6076 : 9208 : gfc_match_module (void)
6077 : : {
6078 : 9208 : match m;
6079 : :
6080 : 9208 : m = gfc_match (" %s%t", &gfc_new_block);
6081 : 9208 : if (m != MATCH_YES)
6082 : : return m;
6083 : :
6084 : 9185 : if (!gfc_add_flavor (&gfc_new_block->attr, FL_MODULE,
6085 : : gfc_new_block->name, NULL))
6086 : 0 : return MATCH_ERROR;
6087 : :
6088 : : return MATCH_YES;
6089 : : }
6090 : :
6091 : :
6092 : : /* Free equivalence sets and lists. Recursively is the easiest way to
6093 : : do this. */
6094 : :
6095 : : void
6096 : 8593872 : gfc_free_equiv_until (gfc_equiv *eq, gfc_equiv *stop)
6097 : : {
6098 : 8593872 : if (eq == stop)
6099 : : return;
6100 : :
6101 : 3199 : gfc_free_equiv (eq->eq);
6102 : 3199 : gfc_free_equiv_until (eq->next, stop);
6103 : 3199 : gfc_free_expr (eq->expr);
6104 : 3199 : free (eq);
6105 : : }
6106 : :
6107 : :
6108 : : void
6109 : 496092 : gfc_free_equiv (gfc_equiv *eq)
6110 : : {
6111 : 496092 : gfc_free_equiv_until (eq, NULL);
6112 : 496092 : }
6113 : :
6114 : :
6115 : : /* Match an EQUIVALENCE statement. */
6116 : :
6117 : : match
6118 : 1020 : gfc_match_equivalence (void)
6119 : : {
6120 : 1020 : gfc_equiv *eq, *set, *tail;
6121 : 1020 : gfc_ref *ref;
6122 : 1020 : gfc_symbol *sym;
6123 : 1020 : match m;
6124 : 1020 : gfc_common_head *common_head = NULL;
6125 : 1020 : bool common_flag;
6126 : 1020 : int cnt;
6127 : 1020 : char c;
6128 : :
6129 : : /* EQUIVALENCE has been matched. After gobbling any possible whitespace,
6130 : : the next character needs to be '('. Check that here, and return
6131 : : MATCH_NO for a variable of the form equivalence. */
6132 : 1020 : gfc_gobble_whitespace ();
6133 : 1020 : c = gfc_peek_ascii_char ();
6134 : 1020 : if (c != '(')
6135 : : return MATCH_NO;
6136 : :
6137 : : tail = NULL;
6138 : :
6139 : 1452 : for (;;)
6140 : : {
6141 : 1452 : eq = gfc_get_equiv ();
6142 : 1452 : if (tail == NULL)
6143 : 1019 : tail = eq;
6144 : :
6145 : 1452 : eq->next = gfc_current_ns->equiv;
6146 : 1452 : gfc_current_ns->equiv = eq;
6147 : :
6148 : 1452 : if (gfc_match_char ('(') != MATCH_YES)
6149 : 0 : goto syntax;
6150 : :
6151 : : set = eq;
6152 : : common_flag = false;
6153 : : cnt = 0;
6154 : :
6155 : 4438 : for (;;)
6156 : : {
6157 : 2945 : m = gfc_match_equiv_variable (&set->expr);
6158 : 2945 : if (m == MATCH_ERROR)
6159 : 1 : goto cleanup;
6160 : 2944 : if (m == MATCH_NO)
6161 : 0 : goto syntax;
6162 : :
6163 : : /* count the number of objects. */
6164 : 2944 : cnt++;
6165 : :
6166 : 2944 : if (gfc_match_char ('%') == MATCH_YES)
6167 : : {
6168 : 0 : gfc_error ("Derived type component %C is not a "
6169 : : "permitted EQUIVALENCE member");
6170 : 0 : goto cleanup;
6171 : : }
6172 : :
6173 : 5018 : for (ref = set->expr->ref; ref; ref = ref->next)
6174 : 2074 : if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION)
6175 : : {
6176 : 0 : gfc_error ("Array reference in EQUIVALENCE at %C cannot "
6177 : : "be an array section");
6178 : 0 : goto cleanup;
6179 : : }
6180 : :
6181 : 2944 : sym = set->expr->symtree->n.sym;
6182 : :
6183 : 2944 : if (!gfc_add_in_equivalence (&sym->attr, sym->name, NULL))
6184 : 6 : goto cleanup;
6185 : 2938 : if (sym->ts.type == BT_CLASS
6186 : 3 : && CLASS_DATA (sym)
6187 : 2941 : && !gfc_add_in_equivalence (&CLASS_DATA (sym)->attr,
6188 : : sym->name, NULL))
6189 : 3 : goto cleanup;
6190 : :
6191 : 2935 : if (sym->attr.in_common)
6192 : : {
6193 : 301 : common_flag = true;
6194 : 301 : common_head = sym->common_head;
6195 : : }
6196 : :
6197 : 2935 : if (gfc_match_char (')') == MATCH_YES)
6198 : : break;
6199 : :
6200 : 1493 : if (gfc_match_char (',') != MATCH_YES)
6201 : 0 : goto syntax;
6202 : :
6203 : 1493 : set->eq = gfc_get_equiv ();
6204 : 1493 : set = set->eq;
6205 : : }
6206 : :
6207 : 1442 : if (cnt < 2)
6208 : : {
6209 : 1 : gfc_error ("EQUIVALENCE at %C requires two or more objects");
6210 : 1 : goto cleanup;
6211 : : }
6212 : :
6213 : : /* If one of the members of an equivalence is in common, then
6214 : : mark them all as being in common. Before doing this, check
6215 : : that members of the equivalence group are not in different
6216 : : common blocks. */
6217 : 1441 : if (common_flag)
6218 : 901 : for (set = eq; set; set = set->eq)
6219 : : {
6220 : 609 : sym = set->expr->symtree->n.sym;
6221 : 609 : if (sym->common_head && sym->common_head != common_head)
6222 : : {
6223 : 1 : gfc_error ("Attempt to indirectly overlap COMMON "
6224 : : "blocks %s and %s by EQUIVALENCE at %C",
6225 : 1 : sym->common_head->name, common_head->name);
6226 : 1 : goto cleanup;
6227 : : }
6228 : 608 : sym->attr.in_common = 1;
6229 : 608 : sym->common_head = common_head;
6230 : : }
6231 : :
6232 : 1440 : if (gfc_match_eos () == MATCH_YES)
6233 : : break;
6234 : 434 : if (gfc_match_char (',') != MATCH_YES)
6235 : : {
6236 : 1 : gfc_error ("Expecting a comma in EQUIVALENCE at %C");
6237 : 1 : goto cleanup;
6238 : : }
6239 : : }
6240 : :
6241 : 1006 : if (!gfc_notify_std (GFC_STD_F2018_OBS, "EQUIVALENCE statement at %C"))
6242 : : return MATCH_ERROR;
6243 : :
6244 : : return MATCH_YES;
6245 : :
6246 : 0 : syntax:
6247 : 0 : gfc_syntax_error (ST_EQUIVALENCE);
6248 : :
6249 : 13 : cleanup:
6250 : 13 : eq = tail->next;
6251 : 13 : tail->next = NULL;
6252 : :
6253 : 13 : gfc_free_equiv (gfc_current_ns->equiv);
6254 : 13 : gfc_current_ns->equiv = eq;
6255 : :
6256 : 13 : return MATCH_ERROR;
6257 : : }
6258 : :
6259 : :
6260 : : /* Check that a statement function is not recursive. This is done by looking
6261 : : for the statement function symbol(sym) by looking recursively through its
6262 : : expression(e). If a reference to sym is found, true is returned.
6263 : : 12.5.4 requires that any variable of function that is implicitly typed
6264 : : shall have that type confirmed by any subsequent type declaration. The
6265 : : implicit typing is conveniently done here. */
6266 : : static bool
6267 : : recursive_stmt_fcn (gfc_expr *, gfc_symbol *);
6268 : :
6269 : : static bool
6270 : 903 : check_stmt_fcn (gfc_expr *e, gfc_symbol *sym, int *f ATTRIBUTE_UNUSED)
6271 : : {
6272 : :
6273 : 903 : if (e == NULL)
6274 : : return false;
6275 : :
6276 : 903 : switch (e->expr_type)
6277 : : {
6278 : 118 : case EXPR_FUNCTION:
6279 : 118 : if (e->symtree == NULL)
6280 : : return false;
6281 : :
6282 : : /* Check the name before testing for nested recursion! */
6283 : 118 : if (sym->name == e->symtree->n.sym->name)
6284 : : return true;
6285 : :
6286 : : /* Catch recursion via other statement functions. */
6287 : 117 : if (e->symtree->n.sym->attr.proc == PROC_ST_FUNCTION
6288 : 4 : && e->symtree->n.sym->value
6289 : 121 : && recursive_stmt_fcn (e->symtree->n.sym->value, sym))
6290 : : return true;
6291 : :
6292 : 115 : if (e->symtree->n.sym->ts.type == BT_UNKNOWN)
6293 : 65 : gfc_set_default_type (e->symtree->n.sym, 0, NULL);
6294 : :
6295 : : break;
6296 : :
6297 : 416 : case EXPR_VARIABLE:
6298 : 416 : if (e->symtree && sym->name == e->symtree->n.sym->name)
6299 : : return true;
6300 : :
6301 : 416 : if (e->symtree->n.sym->ts.type == BT_UNKNOWN)
6302 : 150 : gfc_set_default_type (e->symtree->n.sym, 0, NULL);
6303 : : break;
6304 : :
6305 : : default:
6306 : : break;
6307 : : }
6308 : :
6309 : : return false;
6310 : : }
6311 : :
6312 : :
6313 : : static bool
6314 : 234 : recursive_stmt_fcn (gfc_expr *e, gfc_symbol *sym)
6315 : : {
6316 : 4 : return gfc_traverse_expr (e, sym, check_stmt_fcn, 0);
6317 : : }
6318 : :
6319 : :
6320 : : /* Check for invalid uses of statement function dummy arguments in body. */
6321 : :
6322 : : static bool
6323 : 876 : chk_stmt_fcn_body (gfc_expr *e, gfc_symbol *sym, int *f ATTRIBUTE_UNUSED)
6324 : : {
6325 : 876 : gfc_formal_arglist *formal;
6326 : :
6327 : 876 : if (e == NULL || e->symtree == NULL || e->expr_type != EXPR_FUNCTION)
6328 : : return false;
6329 : :
6330 : 275 : for (formal = sym->formal; formal; formal = formal->next)
6331 : : {
6332 : 165 : if (formal->sym == e->symtree->n.sym)
6333 : : {
6334 : 2 : gfc_error ("Invalid use of statement function argument at %L",
6335 : : &e->where);
6336 : 2 : return true;
6337 : : }
6338 : : }
6339 : :
6340 : : return false;
6341 : : }
6342 : :
6343 : :
6344 : : /* Match a statement function declaration. It is so easy to match
6345 : : non-statement function statements with a MATCH_ERROR as opposed to
6346 : : MATCH_NO that we suppress error message in most cases. */
6347 : :
6348 : : match
6349 : 391721 : gfc_match_st_function (void)
6350 : : {
6351 : 391721 : gfc_error_buffer old_error;
6352 : 391721 : gfc_symbol *sym;
6353 : 391721 : gfc_expr *expr;
6354 : 391721 : match m;
6355 : 391721 : char name[GFC_MAX_SYMBOL_LEN + 1];
6356 : 391721 : locus old_locus;
6357 : 391721 : bool fcn;
6358 : 391721 : gfc_formal_arglist *ptr;
6359 : :
6360 : : /* Read the possible statement function name, and then check to see if
6361 : : a symbol is already present in the namespace. Record if it is a
6362 : : function and whether it has been referenced. */
6363 : 391721 : fcn = false;
6364 : 391721 : ptr = NULL;
6365 : 391721 : old_locus = gfc_current_locus;
6366 : 391721 : m = gfc_match_name (name);
6367 : 391721 : if (m == MATCH_YES)
6368 : : {
6369 : 391721 : gfc_find_symbol (name, NULL, 1, &sym);
6370 : 391721 : if (sym && sym->attr.function && !sym->attr.referenced)
6371 : : {
6372 : 132 : fcn = true;
6373 : 132 : ptr = sym->formal;
6374 : : }
6375 : : }
6376 : :
6377 : 391721 : gfc_current_locus = old_locus;
6378 : 391721 : m = gfc_match_symbol (&sym, 0);
6379 : 391721 : if (m != MATCH_YES)
6380 : : return m;
6381 : :
6382 : 391708 : gfc_push_error (&old_error);
6383 : :
6384 : 391708 : if (!gfc_add_procedure (&sym->attr, PROC_ST_FUNCTION, sym->name, NULL))
6385 : 351 : goto undo_error;
6386 : :
6387 : 391357 : if (gfc_match_formal_arglist (sym, 1, 0) != MATCH_YES)
6388 : 322571 : goto undo_error;
6389 : :
6390 : 68786 : m = gfc_match (" = %e%t", &expr);
6391 : 68786 : if (m == MATCH_NO)
6392 : 68556 : goto undo_error;
6393 : :
6394 : 230 : gfc_free_error (&old_error);
6395 : :
6396 : 230 : if (m == MATCH_ERROR)
6397 : : return m;
6398 : :
6399 : 230 : if (recursive_stmt_fcn (expr, sym))
6400 : : {
6401 : 1 : gfc_error ("Statement function at %L is recursive", &expr->where);
6402 : 1 : return MATCH_ERROR;
6403 : : }
6404 : :
6405 : 229 : if (fcn && ptr != sym->formal)
6406 : : {
6407 : 2 : gfc_error ("Statement function %qs at %L conflicts with function name",
6408 : 2 : sym->name, &expr->where);
6409 : 2 : return MATCH_ERROR;
6410 : : }
6411 : :
6412 : 227 : if (gfc_traverse_expr (expr, sym, chk_stmt_fcn_body, 0))
6413 : : return MATCH_ERROR;
6414 : :
6415 : 225 : sym->value = expr;
6416 : :
6417 : 225 : if ((gfc_current_state () == COMP_FUNCTION
6418 : 225 : || gfc_current_state () == COMP_SUBROUTINE)
6419 : 136 : && gfc_state_stack->previous->state == COMP_INTERFACE)
6420 : : {
6421 : 1 : gfc_error ("Statement function at %L cannot appear within an INTERFACE",
6422 : : &expr->where);
6423 : 1 : return MATCH_ERROR;
6424 : : }
6425 : :
6426 : 224 : if (!gfc_notify_std (GFC_STD_F95_OBS, "Statement function at %C"))
6427 : : return MATCH_ERROR;
6428 : :
6429 : : return MATCH_YES;
6430 : :
6431 : 391478 : undo_error:
6432 : 391478 : gfc_pop_error (&old_error);
6433 : 391478 : return MATCH_NO;
6434 : 391721 : }
6435 : :
6436 : :
6437 : : /* Match an assignment to a pointer function (F2008). This could, in
6438 : : general be ambiguous with a statement function. In this implementation
6439 : : it remains so if it is the first statement after the specification
6440 : : block. */
6441 : :
6442 : : match
6443 : 960062 : gfc_match_ptr_fcn_assign (void)
6444 : : {
6445 : 960062 : gfc_error_buffer old_error;
6446 : 960062 : locus old_loc;
6447 : 960062 : gfc_symbol *sym;
6448 : 960062 : gfc_expr *expr;
6449 : 960062 : match m;
6450 : 960062 : char name[GFC_MAX_SYMBOL_LEN + 1];
6451 : :
6452 : 960062 : old_loc = gfc_current_locus;
6453 : 960062 : m = gfc_match_name (name);
6454 : 960062 : if (m != MATCH_YES)
6455 : : return m;
6456 : :
6457 : 960059 : gfc_find_symbol (name, NULL, 1, &sym);
6458 : 960059 : if (sym && sym->attr.flavor != FL_PROCEDURE)
6459 : : return MATCH_NO;
6460 : :
6461 : 959794 : gfc_push_error (&old_error);
6462 : :
6463 : 959794 : if (sym && sym->attr.function)
6464 : 864 : goto match_actual_arglist;
6465 : :
6466 : 958930 : gfc_current_locus = old_loc;
6467 : 958930 : m = gfc_match_symbol (&sym, 0);
6468 : 958930 : if (m != MATCH_YES)
6469 : : return m;
6470 : :
6471 : 958917 : if (!gfc_add_procedure (&sym->attr, PROC_UNKNOWN, sym->name, NULL))
6472 : 1 : goto undo_error;
6473 : :
6474 : 958916 : match_actual_arglist:
6475 : 959780 : gfc_current_locus = old_loc;
6476 : 959780 : m = gfc_match (" %e", &expr);
6477 : 959780 : if (m != MATCH_YES)
6478 : 597687 : goto undo_error;
6479 : :
6480 : 362093 : new_st.op = EXEC_ASSIGN;
6481 : 362093 : new_st.expr1 = expr;
6482 : 362093 : expr = NULL;
6483 : :
6484 : 362093 : m = gfc_match (" = %e%t", &expr);
6485 : 362093 : if (m != MATCH_YES)
6486 : 361937 : goto undo_error;
6487 : :
6488 : 156 : new_st.expr2 = expr;
6489 : 156 : return MATCH_YES;
6490 : :
6491 : 959625 : undo_error:
6492 : 959625 : gfc_pop_error (&old_error);
6493 : 959625 : return MATCH_NO;
6494 : 960062 : }
6495 : :
6496 : :
6497 : : /***************** SELECT CASE subroutines ******************/
6498 : :
6499 : : /* Free a single case structure. */
6500 : :
6501 : : static void
6502 : 9796 : free_case (gfc_case *p)
6503 : : {
6504 : 9796 : if (p->low == p->high)
6505 : 4594 : p->high = NULL;
6506 : 9796 : gfc_free_expr (p->low);
6507 : 9796 : gfc_free_expr (p->high);
6508 : 9796 : free (p);
6509 : 9796 : }
6510 : :
6511 : :
6512 : : /* Free a list of case structures. */
6513 : :
6514 : : void
6515 : 9600 : gfc_free_case_list (gfc_case *p)
6516 : : {
6517 : 9600 : gfc_case *q;
6518 : :
6519 : 19386 : for (; p; p = q)
6520 : : {
6521 : 9786 : q = p->next;
6522 : 9786 : free_case (p);
6523 : : }
6524 : 9600 : }
6525 : :
6526 : :
6527 : : /* Match a single case selector. Combining the requirements of F08:C830
6528 : : and F08:C832 (R838) means that the case-value must have either CHARACTER,
6529 : : INTEGER, or LOGICAL type. */
6530 : :
6531 : : static match
6532 : 1409 : match_case_selector (gfc_case **cp)
6533 : : {
6534 : 1409 : gfc_case *c;
6535 : 1409 : match m;
6536 : :
6537 : 1409 : c = gfc_get_case ();
6538 : 1409 : c->where = gfc_current_locus;
6539 : :
6540 : 1409 : if (gfc_match_char (':') == MATCH_YES)
6541 : : {
6542 : 48 : m = gfc_match_init_expr (&c->high);
6543 : 48 : if (m == MATCH_NO)
6544 : 0 : goto need_expr;
6545 : 48 : if (m == MATCH_ERROR)
6546 : 0 : goto cleanup;
6547 : :
6548 : 48 : if (c->high->ts.type != BT_LOGICAL && c->high->ts.type != BT_INTEGER
6549 : 2 : && c->high->ts.type != BT_CHARACTER
6550 : 2 : && (!flag_unsigned
6551 : 0 : || (flag_unsigned && c->high->ts.type != BT_UNSIGNED)))
6552 : : {
6553 : 2 : gfc_error ("Expression in CASE selector at %L cannot be %s",
6554 : 2 : &c->high->where, gfc_typename (&c->high->ts));
6555 : 2 : goto cleanup;
6556 : : }
6557 : : }
6558 : : else
6559 : : {
6560 : 1361 : m = gfc_match_init_expr (&c->low);
6561 : 1361 : if (m == MATCH_ERROR)
6562 : 0 : goto cleanup;
6563 : 1361 : if (m == MATCH_NO)
6564 : 0 : goto need_expr;
6565 : :
6566 : 1361 : if (c->low->ts.type != BT_LOGICAL && c->low->ts.type != BT_INTEGER
6567 : 357 : && c->low->ts.type != BT_CHARACTER
6568 : 43 : && (!flag_unsigned
6569 : 42 : || (flag_unsigned && c->low->ts.type != BT_UNSIGNED)))
6570 : : {
6571 : 1 : gfc_error ("Expression in CASE selector at %L cannot be %s",
6572 : 1 : &c->low->where, gfc_typename (&c->low->ts));
6573 : 1 : goto cleanup;
6574 : : }
6575 : :
6576 : : /* If we're not looking at a ':' now, make a range out of a single
6577 : : target. Else get the upper bound for the case range. */
6578 : 1360 : if (gfc_match_char (':') != MATCH_YES)
6579 : 1193 : c->high = c->low;
6580 : : else
6581 : : {
6582 : 167 : m = gfc_match_init_expr (&c->high);
6583 : 167 : if (m == MATCH_ERROR)
6584 : 0 : goto cleanup;
6585 : 167 : if (m == MATCH_YES
6586 : 119 : && c->high->ts.type != BT_LOGICAL
6587 : : && c->high->ts.type != BT_INTEGER
6588 : : && c->high->ts.type != BT_CHARACTER
6589 : 1 : && (!flag_unsigned
6590 : 0 : || (flag_unsigned && c->high->ts.type != BT_UNSIGNED)))
6591 : : {
6592 : 1 : gfc_error ("Expression in CASE selector at %L cannot be %s",
6593 : 1 : &c->high->where, gfc_typename (c->high));
6594 : 1 : goto cleanup;
6595 : : }
6596 : : /* MATCH_NO is fine. It's OK if nothing is there! */
6597 : : }
6598 : : }
6599 : :
6600 : 1405 : if (c->low && c->low->rank != 0)
6601 : : {
6602 : 4 : gfc_error ("Expression in CASE selector at %L must be scalar",
6603 : : &c->low->where);
6604 : 4 : goto cleanup;
6605 : : }
6606 : 1401 : if (c->high && c->high->rank != 0)
6607 : : {
6608 : 2 : gfc_error ("Expression in CASE selector at %L must be scalar",
6609 : : &c->high->where);
6610 : 2 : goto cleanup;
6611 : : }
6612 : :
6613 : 1399 : *cp = c;
6614 : 1399 : return MATCH_YES;
6615 : :
6616 : 0 : need_expr:
6617 : 0 : gfc_error ("Expected initialization expression in CASE at %C");
6618 : :
6619 : 10 : cleanup:
6620 : 10 : free_case (c);
6621 : 10 : return MATCH_ERROR;
6622 : : }
6623 : :
6624 : :
6625 : : /* Match the end of a case statement. */
6626 : :
6627 : : static match
6628 : 9036 : match_case_eos (void)
6629 : : {
6630 : 9036 : char name[GFC_MAX_SYMBOL_LEN + 1];
6631 : 9036 : match m;
6632 : :
6633 : 9036 : if (gfc_match_eos () == MATCH_YES)
6634 : : return MATCH_YES;
6635 : :
6636 : : /* If the case construct doesn't have a case-construct-name, we
6637 : : should have matched the EOS. */
6638 : 21 : if (!gfc_current_block ())
6639 : : return MATCH_NO;
6640 : :
6641 : 17 : gfc_gobble_whitespace ();
6642 : :
6643 : 17 : m = gfc_match_name (name);
6644 : 17 : if (m != MATCH_YES)
6645 : : return m;
6646 : :
6647 : 17 : if (strcmp (name, gfc_current_block ()->name) != 0)
6648 : : {
6649 : 1 : gfc_error ("Expected block name %qs of SELECT construct at %C",
6650 : : gfc_current_block ()->name);
6651 : 1 : return MATCH_ERROR;
6652 : : }
6653 : :
6654 : 16 : return gfc_match_eos ();
6655 : : }
6656 : :
6657 : :
6658 : : /* Match a SELECT statement. */
6659 : :
6660 : : match
6661 : 464280 : gfc_match_select (void)
6662 : : {
6663 : 464280 : gfc_expr *expr;
6664 : 464280 : match m;
6665 : :
6666 : 464280 : m = gfc_match_label ();
6667 : 464280 : if (m == MATCH_ERROR)
6668 : : return m;
6669 : :
6670 : 464272 : m = gfc_match (" select case ( %e )%t", &expr);
6671 : 464272 : if (m != MATCH_YES)
6672 : : return m;
6673 : :
6674 : 528 : new_st.op = EXEC_SELECT;
6675 : 528 : new_st.expr1 = expr;
6676 : :
6677 : 528 : return MATCH_YES;
6678 : : }
6679 : :
6680 : :
6681 : : /* Transfer the selector typespec to the associate name. */
6682 : :
6683 : : static void
6684 : 597 : copy_ts_from_selector_to_associate (gfc_expr *associate, gfc_expr *selector,
6685 : : bool select_type = false)
6686 : : {
6687 : 597 : gfc_ref *ref;
6688 : 597 : gfc_symbol *assoc_sym;
6689 : 597 : int rank = 0, corank = 0;
6690 : :
6691 : 597 : assoc_sym = associate->symtree->n.sym;
6692 : :
6693 : : /* At this stage the expression rank and arrayspec dimensions have
6694 : : not been completely sorted out. We must get the expr2->rank
6695 : : right here, so that the correct class container is obtained. */
6696 : 597 : ref = selector->ref;
6697 : 848 : while (ref && ref->next)
6698 : : ref = ref->next;
6699 : :
6700 : 597 : if (selector->ts.type == BT_CLASS
6701 : 582 : && CLASS_DATA (selector)
6702 : 580 : && CLASS_DATA (selector)->as
6703 : 366 : && CLASS_DATA (selector)->as->type == AS_ASSUMED_RANK)
6704 : : {
6705 : 12 : assoc_sym->attr.dimension = 1;
6706 : 12 : assoc_sym->as = gfc_copy_array_spec (CLASS_DATA (selector)->as);
6707 : 12 : corank = assoc_sym->as->corank;
6708 : 12 : goto build_class_sym;
6709 : : }
6710 : 585 : else if (selector->ts.type == BT_CLASS
6711 : 570 : && CLASS_DATA (selector)
6712 : 568 : && CLASS_DATA (selector)->as
6713 : 354 : && ((ref && ref->type == REF_ARRAY)
6714 : 2 : || selector->expr_type == EXPR_OP))
6715 : : {
6716 : : /* Ensure that the array reference type is set. We cannot use
6717 : : gfc_resolve_expr at this point, so the usable parts of
6718 : : resolve.cc(resolve_array_ref) are employed to do it. */
6719 : 354 : if (ref && ref->u.ar.type == AR_UNKNOWN)
6720 : : {
6721 : 101 : ref->u.ar.type = AR_ELEMENT;
6722 : 171 : for (int i = 0; i < ref->u.ar.dimen + ref->u.ar.codimen; i++)
6723 : 107 : if (ref->u.ar.dimen_type[i] == DIMEN_RANGE
6724 : 107 : || ref->u.ar.dimen_type[i] == DIMEN_VECTOR
6725 : 71 : || (ref->u.ar.dimen_type[i] == DIMEN_UNKNOWN
6726 : 71 : && ref->u.ar.start[i] && ref->u.ar.start[i]->rank))
6727 : : {
6728 : 37 : ref->u.ar.type = AR_SECTION;
6729 : 37 : break;
6730 : : }
6731 : : }
6732 : :
6733 : 352 : if (!ref || ref->u.ar.type == AR_FULL)
6734 : : {
6735 : 253 : selector->rank = CLASS_DATA (selector)->as->rank;
6736 : 253 : selector->corank = CLASS_DATA (selector)->as->corank;
6737 : : }
6738 : 101 : else if (ref->u.ar.type == AR_SECTION)
6739 : : {
6740 : 37 : selector->rank = ref->u.ar.dimen;
6741 : 37 : selector->corank = ref->u.ar.codimen;
6742 : : }
6743 : : else
6744 : 64 : selector->rank = 0;
6745 : :
6746 : 354 : rank = selector->rank;
6747 : 354 : corank = selector->corank;
6748 : : }
6749 : :
6750 : 354 : if (rank)
6751 : : {
6752 : 282 : if (ref)
6753 : : {
6754 : 329 : for (int i = 0; i < ref->u.ar.dimen + ref->u.ar.codimen; i++)
6755 : 49 : if (ref->u.ar.dimen_type[i] == DIMEN_ELEMENT
6756 : 49 : || (ref->u.ar.dimen_type[i] == DIMEN_UNKNOWN
6757 : 7 : && ref->u.ar.end[i] == NULL
6758 : 7 : && ref->u.ar.stride[i] == NULL))
6759 : 7 : rank--;
6760 : : }
6761 : :
6762 : 282 : if (rank)
6763 : : {
6764 : 281 : assoc_sym->attr.dimension = 1;
6765 : 281 : assoc_sym->as = gfc_get_array_spec ();
6766 : 281 : assoc_sym->as->rank = rank;
6767 : 281 : assoc_sym->as->type = AS_DEFERRED;
6768 : : }
6769 : : }
6770 : :
6771 : 585 : if (corank != 0 && rank == 0)
6772 : : {
6773 : 8 : if (!assoc_sym->as)
6774 : 8 : assoc_sym->as = gfc_get_array_spec ();
6775 : 8 : assoc_sym->as->corank = corank;
6776 : 8 : assoc_sym->attr.codimension = 1;
6777 : : }
6778 : 577 : else if (corank == 0 && rank == 0 && assoc_sym->as)
6779 : : {
6780 : 0 : free (assoc_sym->as);
6781 : 0 : assoc_sym->as = NULL;
6782 : : }
6783 : 577 : build_class_sym:
6784 : : /* Deal with the very specific case of a SELECT_TYPE selector being an
6785 : : associate_name whose type has been identified by component references.
6786 : : It must be assumed that it will be identified as a CLASS expression,
6787 : : so convert it now. */
6788 : 597 : if (select_type
6789 : 585 : && IS_INFERRED_TYPE (selector)
6790 : 13 : && selector->ts.type == BT_DERIVED)
6791 : : {
6792 : 13 : gfc_find_derived_vtab (selector->ts.u.derived);
6793 : : /* The correct class container has to be available. */
6794 : 13 : assoc_sym->ts.u.derived = selector->ts.u.derived;
6795 : 13 : assoc_sym->ts.type = BT_CLASS;
6796 : 13 : assoc_sym->attr.pointer = 1;
6797 : 13 : if (!selector->ts.u.derived->attr.is_class)
6798 : 13 : gfc_build_class_symbol (&assoc_sym->ts, &assoc_sym->attr, &assoc_sym->as);
6799 : 13 : associate->ts = assoc_sym->ts;
6800 : : }
6801 : 584 : else if (selector->ts.type == BT_CLASS)
6802 : : {
6803 : : /* The correct class container has to be available. */
6804 : 582 : assoc_sym->ts.type = BT_CLASS;
6805 : 1164 : assoc_sym->ts.u.derived = CLASS_DATA (selector)
6806 : 582 : ? CLASS_DATA (selector)->ts.u.derived
6807 : : : selector->ts.u.derived;
6808 : 582 : assoc_sym->attr.pointer = 1;
6809 : 582 : gfc_build_class_symbol (&assoc_sym->ts, &assoc_sym->attr, &assoc_sym->as);
6810 : : }
6811 : 597 : }
6812 : :
6813 : :
6814 : : /* Build the associate name */
6815 : : static int
6816 : 616 : build_associate_name (const char *name, gfc_expr **e1, gfc_expr **e2)
6817 : : {
6818 : 616 : gfc_expr *expr1 = *e1;
6819 : 616 : gfc_expr *expr2 = *e2;
6820 : 616 : gfc_symbol *sym;
6821 : :
6822 : : /* For the case where the associate name is already an associate name. */
6823 : 616 : if (!expr2)
6824 : 55 : expr2 = expr1;
6825 : 616 : expr1 = gfc_get_expr ();
6826 : 616 : expr1->expr_type = EXPR_VARIABLE;
6827 : 616 : expr1->where = expr2->where;
6828 : 616 : if (gfc_get_sym_tree (name, NULL, &expr1->symtree, false))
6829 : : return 1;
6830 : :
6831 : 616 : sym = expr1->symtree->n.sym;
6832 : 616 : if (expr2->ts.type == BT_UNKNOWN)
6833 : 31 : sym->attr.untyped = 1;
6834 : : else
6835 : 585 : copy_ts_from_selector_to_associate (expr1, expr2, true);
6836 : :
6837 : 616 : sym->attr.flavor = FL_VARIABLE;
6838 : 616 : sym->attr.referenced = 1;
6839 : 616 : sym->attr.class_ok = 1;
6840 : :
6841 : 616 : *e1 = expr1;
6842 : 616 : *e2 = expr2;
6843 : 616 : return 0;
6844 : : }
6845 : :
6846 : :
6847 : : /* Push the current selector onto the SELECT TYPE stack. */
6848 : :
6849 : : static void
6850 : 3890 : select_type_push (gfc_symbol *sel)
6851 : : {
6852 : 3890 : gfc_select_type_stack *top = gfc_get_select_type_stack ();
6853 : 3890 : top->selector = sel;
6854 : 3890 : top->tmp = NULL;
6855 : 3890 : top->prev = select_type_stack;
6856 : :
6857 : 3890 : select_type_stack = top;
6858 : 3890 : }
6859 : :
6860 : :
6861 : : /* Set the temporary for the current intrinsic SELECT TYPE selector. */
6862 : :
6863 : : static gfc_symtree *
6864 : 3597 : select_intrinsic_set_tmp (gfc_typespec *ts)
6865 : : {
6866 : 3597 : char name[GFC_MAX_SYMBOL_LEN];
6867 : 3597 : gfc_symtree *tmp;
6868 : 3597 : HOST_WIDE_INT charlen = 0;
6869 : 3597 : gfc_symbol *selector = select_type_stack->selector;
6870 : 3597 : gfc_symbol *sym;
6871 : :
6872 : 3597 : if (ts->type == BT_CLASS || ts->type == BT_DERIVED)
6873 : : return NULL;
6874 : :
6875 : 1374 : if (selector->ts.type == BT_CLASS && !selector->attr.class_ok)
6876 : : return NULL;
6877 : :
6878 : : /* Case value == NULL corresponds to SELECT TYPE cases otherwise
6879 : : the values correspond to SELECT rank cases. */
6880 : 1373 : if (ts->type == BT_CHARACTER && ts->u.cl && ts->u.cl->length
6881 : 0 : && ts->u.cl->length->expr_type == EXPR_CONSTANT)
6882 : 0 : charlen = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
6883 : :
6884 : 1373 : if (ts->type != BT_CHARACTER)
6885 : 642 : sprintf (name, "__tmp_%s_%d", gfc_basic_typename (ts->type),
6886 : : ts->kind);
6887 : : else
6888 : 731 : snprintf (name, sizeof (name),
6889 : : "__tmp_%s_" HOST_WIDE_INT_PRINT_DEC "_%d",
6890 : : gfc_basic_typename (ts->type), charlen, ts->kind);
6891 : :
6892 : 1373 : gfc_get_sym_tree (name, gfc_current_ns, &tmp, false);
6893 : 1373 : sym = tmp->n.sym;
6894 : 1373 : gfc_add_type (sym, ts, NULL);
6895 : :
6896 : : /* Copy across the array spec to the selector. */
6897 : 1373 : if (selector->ts.type == BT_CLASS
6898 : 1371 : && (CLASS_DATA (selector)->attr.dimension
6899 : 1371 : || CLASS_DATA (selector)->attr.codimension))
6900 : : {
6901 : 696 : sym->attr.pointer = 1;
6902 : 696 : sym->attr.dimension = CLASS_DATA (selector)->attr.dimension;
6903 : 696 : sym->attr.codimension = CLASS_DATA (selector)->attr.codimension;
6904 : 696 : sym->as = gfc_copy_array_spec (CLASS_DATA (selector)->as);
6905 : : }
6906 : :
6907 : 1373 : gfc_set_sym_referenced (sym);
6908 : 1373 : gfc_add_flavor (&sym->attr, FL_VARIABLE, name, NULL);
6909 : 1373 : sym->attr.select_type_temporary = 1;
6910 : :
6911 : 1373 : return tmp;
6912 : : }
6913 : :
6914 : :
6915 : : /* Set up a temporary for the current TYPE IS / CLASS IS branch . */
6916 : :
6917 : : static void
6918 : 5167 : select_type_set_tmp (gfc_typespec *ts)
6919 : : {
6920 : 5167 : char name[GFC_MAX_SYMBOL_LEN + 12 + 1];
6921 : 5167 : gfc_symtree *tmp = NULL;
6922 : 5167 : gfc_symbol *selector = select_type_stack->selector;
6923 : 5167 : gfc_symbol *sym;
6924 : 5167 : gfc_expr *expr2;
6925 : :
6926 : 5167 : if (!ts)
6927 : : {
6928 : 1570 : select_type_stack->tmp = NULL;
6929 : 1571 : return;
6930 : : }
6931 : :
6932 : 3597 : tmp = select_intrinsic_set_tmp (ts);
6933 : :
6934 : 3597 : if (tmp == NULL)
6935 : : {
6936 : 2224 : if (!ts->u.derived)
6937 : : return;
6938 : :
6939 : 2223 : if (ts->type == BT_CLASS)
6940 : 312 : sprintf (name, "__tmp_class_%s", ts->u.derived->name);
6941 : : else
6942 : 1911 : sprintf (name, "__tmp_type_%s", ts->u.derived->name);
6943 : :
6944 : 2223 : gfc_get_sym_tree (name, gfc_current_ns, &tmp, false);
6945 : 2223 : sym = tmp->n.sym;
6946 : 2223 : gfc_add_type (sym, ts, NULL);
6947 : :
6948 : : /* If the SELECT TYPE selector is a function we might be able to obtain
6949 : : a typespec from the result. Since the function might not have been
6950 : : parsed yet we have to check that there is indeed a result symbol. */
6951 : 2223 : if (selector->ts.type == BT_UNKNOWN
6952 : 46 : && gfc_state_stack->construct
6953 : :
6954 : 46 : && (expr2 = gfc_state_stack->construct->expr2)
6955 : 33 : && expr2->expr_type == EXPR_FUNCTION
6956 : 14 : && expr2->symtree
6957 : 2237 : && expr2->symtree->n.sym && expr2->symtree->n.sym->result)
6958 : 14 : selector->ts = expr2->symtree->n.sym->result->ts;
6959 : :
6960 : 2223 : if (selector->ts.type == BT_CLASS
6961 : 2183 : && selector->attr.class_ok
6962 : 2181 : && selector->ts.u.derived && CLASS_DATA (selector))
6963 : : {
6964 : 2179 : sym->attr.pointer
6965 : 2179 : = CLASS_DATA (selector)->attr.class_pointer;
6966 : :
6967 : : /* Copy across the array spec to the selector. */
6968 : 2179 : if (CLASS_DATA (selector)->attr.dimension
6969 : 2179 : || CLASS_DATA (selector)->attr.codimension)
6970 : : {
6971 : 705 : sym->attr.dimension
6972 : 705 : = CLASS_DATA (selector)->attr.dimension;
6973 : 705 : sym->attr.codimension
6974 : 705 : = CLASS_DATA (selector)->attr.codimension;
6975 : 705 : if (CLASS_DATA (selector)->as->type != AS_EXPLICIT)
6976 : 662 : sym->as = gfc_copy_array_spec (CLASS_DATA (selector)->as);
6977 : : else
6978 : : {
6979 : 43 : sym->as = gfc_get_array_spec();
6980 : 43 : sym->as->rank = CLASS_DATA (selector)->as->rank;
6981 : 43 : sym->as->type = AS_DEFERRED;
6982 : : }
6983 : : }
6984 : : }
6985 : :
6986 : 2223 : gfc_set_sym_referenced (sym);
6987 : 2223 : gfc_add_flavor (&sym->attr, FL_VARIABLE, name, NULL);
6988 : 2223 : sym->attr.select_type_temporary = 1;
6989 : :
6990 : 2223 : if (ts->type == BT_CLASS)
6991 : 312 : gfc_build_class_symbol (&sym->ts, &sym->attr, &sym->as);
6992 : : }
6993 : : else
6994 : 1373 : sym = tmp->n.sym;
6995 : :
6996 : :
6997 : : /* Add an association for it, so the rest of the parser knows it is
6998 : : an associate-name. The target will be set during resolution. */
6999 : 3596 : sym->assoc = gfc_get_association_list ();
7000 : 3596 : sym->assoc->dangling = 1;
7001 : 3596 : sym->assoc->st = tmp;
7002 : :
7003 : 3596 : select_type_stack->tmp = tmp;
7004 : : }
7005 : :
7006 : :
7007 : : /* Match a SELECT TYPE statement. */
7008 : :
7009 : : match
7010 : 463752 : gfc_match_select_type (void)
7011 : : {
7012 : 463752 : gfc_expr *expr1, *expr2 = NULL;
7013 : 463752 : match m;
7014 : 463752 : char name[GFC_MAX_SYMBOL_LEN + 1];
7015 : 463752 : bool class_array;
7016 : 463752 : gfc_namespace *ns = gfc_current_ns;
7017 : :
7018 : 463752 : m = gfc_match_label ();
7019 : 463752 : if (m == MATCH_ERROR)
7020 : : return m;
7021 : :
7022 : 463744 : m = gfc_match (" select type ( ");
7023 : 463744 : if (m != MATCH_YES)
7024 : : return m;
7025 : :
7026 : 2880 : if (gfc_current_state() == COMP_MODULE
7027 : 2880 : || gfc_current_state() == COMP_SUBMODULE)
7028 : : {
7029 : 2 : gfc_error ("SELECT TYPE at %C cannot appear in this scope");
7030 : 2 : return MATCH_ERROR;
7031 : : }
7032 : :
7033 : 2878 : gfc_current_ns = gfc_build_block_ns (ns);
7034 : 2878 : m = gfc_match (" %n => %e", name, &expr2);
7035 : 2878 : if (m == MATCH_YES)
7036 : : {
7037 : 561 : if (build_associate_name (name, &expr1, &expr2))
7038 : : {
7039 : 0 : m = MATCH_ERROR;
7040 : 0 : goto cleanup;
7041 : : }
7042 : : }
7043 : : else
7044 : : {
7045 : 2317 : m = gfc_match (" %e ", &expr1);
7046 : 2317 : if (m != MATCH_YES)
7047 : : {
7048 : 0 : std::swap (ns, gfc_current_ns);
7049 : 0 : gfc_free_namespace (ns);
7050 : 0 : return m;
7051 : : }
7052 : : }
7053 : :
7054 : 2878 : m = gfc_match (" )%t");
7055 : 2878 : if (m != MATCH_YES)
7056 : : {
7057 : 2 : gfc_error ("parse error in SELECT TYPE statement at %C");
7058 : 2 : goto cleanup;
7059 : : }
7060 : :
7061 : : /* This ghastly expression seems to be needed to distinguish a CLASS
7062 : : array, which can have a reference, from other expressions that
7063 : : have references, such as derived type components, and are not
7064 : : allowed by the standard.
7065 : : TODO: see if it is sufficient to exclude component and substring
7066 : : references. */
7067 : 5752 : class_array = (expr1->expr_type == EXPR_VARIABLE
7068 : 2875 : && expr1->ts.type == BT_CLASS
7069 : 2304 : && CLASS_DATA (expr1)
7070 : 2302 : && (strcmp (CLASS_DATA (expr1)->name, "_data") == 0)
7071 : 2302 : && (CLASS_DATA (expr1)->attr.dimension
7072 : 2302 : || CLASS_DATA (expr1)->attr.codimension)
7073 : 858 : && expr1->ref
7074 : 858 : && expr1->ref->type == REF_ARRAY
7075 : 858 : && expr1->ref->u.ar.type == AR_FULL
7076 : 3733 : && expr1->ref->next == NULL);
7077 : :
7078 : : /* Check for F03:C811 (F08:C835). */
7079 : 2876 : if (!expr2 && (expr1->expr_type != EXPR_VARIABLE
7080 : 2315 : || (!class_array && expr1->ref != NULL)))
7081 : : {
7082 : 4 : gfc_error ("Selector in SELECT TYPE at %C is not a named variable; "
7083 : : "use associate-name=>");
7084 : 4 : m = MATCH_ERROR;
7085 : 4 : goto cleanup;
7086 : : }
7087 : :
7088 : : /* Prevent an existing associate name from reuse here by pushing expr1 to
7089 : : expr2 and building a new associate name. */
7090 : 2312 : if (!expr2 && expr1->symtree->n.sym->assoc
7091 : : && !expr1->symtree->n.sym->attr.select_type_temporary
7092 : 122 : && !expr1->symtree->n.sym->attr.select_rank_temporary
7093 : 2927 : && build_associate_name (expr1->symtree->n.sym->name, &expr1, &expr2))
7094 : : {
7095 : 0 : m = MATCH_ERROR;
7096 : 0 : goto cleanup;
7097 : : }
7098 : :
7099 : : /* Select type namespaces are not filled until resolution. Therefore, the
7100 : : namespace must be marked as having an inferred type associate name if
7101 : : either expr1 is an inferred type variable or expr2 is. In the latter
7102 : : case, as well as the symbol being marked as inferred type, it might be
7103 : : that it has not been detected to be so. In this case the target has
7104 : : unknown type. Once the namespace is marked, the fixups in resolution can
7105 : : be triggered. */
7106 : 2872 : if (!expr2
7107 : 2257 : && expr1->symtree->n.sym->assoc
7108 : 67 : && expr1->symtree->n.sym->assoc->inferred_type)
7109 : 0 : gfc_current_ns->assoc_name_inferred = 1;
7110 : 2872 : else if (expr2 && expr2->expr_type == EXPR_VARIABLE
7111 : 599 : && expr2->symtree->n.sym->assoc)
7112 : : {
7113 : 173 : if (expr2->symtree->n.sym->assoc->inferred_type)
7114 : 13 : gfc_current_ns->assoc_name_inferred = 1;
7115 : 160 : else if (expr2->symtree->n.sym->assoc->target
7116 : 109 : && expr2->symtree->n.sym->assoc->target->ts.type == BT_UNKNOWN)
7117 : 36 : gfc_current_ns->assoc_name_inferred = 1;
7118 : : }
7119 : :
7120 : 2872 : new_st.op = EXEC_SELECT_TYPE;
7121 : 2872 : new_st.expr1 = expr1;
7122 : 2872 : new_st.expr2 = expr2;
7123 : 2872 : new_st.ext.block.ns = gfc_current_ns;
7124 : :
7125 : 2872 : select_type_push (expr1->symtree->n.sym);
7126 : 2872 : gfc_current_ns = ns;
7127 : :
7128 : 2872 : return MATCH_YES;
7129 : :
7130 : 6 : cleanup:
7131 : 6 : gfc_free_expr (expr1);
7132 : 6 : gfc_free_expr (expr2);
7133 : 6 : gfc_undo_symbols ();
7134 : 6 : std::swap (ns, gfc_current_ns);
7135 : 6 : gfc_free_namespace (ns);
7136 : 6 : return m;
7137 : : }
7138 : :
7139 : :
7140 : : /* Set the temporary for the current intrinsic SELECT RANK selector. */
7141 : :
7142 : : static void
7143 : 1383 : select_rank_set_tmp (gfc_typespec *ts, int *case_value)
7144 : : {
7145 : 1383 : char name[2 * GFC_MAX_SYMBOL_LEN];
7146 : 1383 : char tname[GFC_MAX_SYMBOL_LEN + 7];
7147 : 1383 : gfc_symtree *tmp;
7148 : 1383 : gfc_symbol *selector = select_type_stack->selector;
7149 : 1383 : gfc_symbol *sym;
7150 : 1383 : gfc_symtree *st;
7151 : 1383 : HOST_WIDE_INT charlen = 0;
7152 : :
7153 : 1383 : if (case_value == NULL)
7154 : 2 : return;
7155 : :
7156 : 1383 : if (ts->type == BT_CHARACTER && ts->u.cl && ts->u.cl->length
7157 : 265 : && ts->u.cl->length->expr_type == EXPR_CONSTANT)
7158 : 186 : charlen = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
7159 : :
7160 : 1383 : if (ts->type == BT_CLASS)
7161 : 145 : sprintf (tname, "class_%s", ts->u.derived->name);
7162 : 1238 : else if (ts->type == BT_DERIVED)
7163 : 110 : sprintf (tname, "type_%s", ts->u.derived->name);
7164 : 1128 : else if (ts->type != BT_CHARACTER)
7165 : 569 : sprintf (tname, "%s_%d", gfc_basic_typename (ts->type), ts->kind);
7166 : : else
7167 : 559 : sprintf (tname, "%s_" HOST_WIDE_INT_PRINT_DEC "_%d",
7168 : : gfc_basic_typename (ts->type), charlen, ts->kind);
7169 : :
7170 : : /* Case value == NULL corresponds to SELECT TYPE cases otherwise
7171 : : the values correspond to SELECT rank cases. */
7172 : 1383 : if (*case_value >=0)
7173 : 1350 : sprintf (name, "__tmp_%s_rank_%d", tname, *case_value);
7174 : : else
7175 : 33 : sprintf (name, "__tmp_%s_rank_m%d", tname, -*case_value);
7176 : :
7177 : 1383 : gfc_find_sym_tree (name, gfc_current_ns, 0, &st);
7178 : 1383 : if (st)
7179 : : return;
7180 : :
7181 : 1381 : gfc_get_sym_tree (name, gfc_current_ns, &tmp, false);
7182 : 1381 : sym = tmp->n.sym;
7183 : 1381 : gfc_add_type (sym, ts, NULL);
7184 : :
7185 : : /* Copy across the array spec to the selector. */
7186 : 1381 : if (selector->ts.type == BT_CLASS)
7187 : : {
7188 : 145 : sym->ts.u.derived = CLASS_DATA (selector)->ts.u.derived;
7189 : 145 : sym->attr.pointer = CLASS_DATA (selector)->attr.pointer;
7190 : 145 : sym->attr.allocatable = CLASS_DATA (selector)->attr.allocatable;
7191 : 145 : sym->attr.target = CLASS_DATA (selector)->attr.target;
7192 : 145 : sym->attr.class_ok = 0;
7193 : 145 : if (case_value && *case_value != 0)
7194 : : {
7195 : 114 : sym->attr.dimension = 1;
7196 : 114 : sym->as = gfc_copy_array_spec (CLASS_DATA (selector)->as);
7197 : 114 : if (*case_value > 0)
7198 : : {
7199 : 114 : sym->as->type = AS_DEFERRED;
7200 : 114 : sym->as->rank = *case_value;
7201 : : }
7202 : 0 : else if (*case_value == -1)
7203 : : {
7204 : 0 : sym->as->type = AS_ASSUMED_SIZE;
7205 : 0 : sym->as->rank = 1;
7206 : : }
7207 : : }
7208 : : }
7209 : : else
7210 : : {
7211 : 1236 : sym->attr.pointer = selector->attr.pointer;
7212 : 1236 : sym->attr.allocatable = selector->attr.allocatable;
7213 : 1236 : sym->attr.target = selector->attr.target;
7214 : 1236 : if (case_value && *case_value != 0)
7215 : : {
7216 : 1187 : sym->attr.dimension = 1;
7217 : 1187 : sym->as = gfc_copy_array_spec (selector->as);
7218 : 1187 : if (*case_value > 0)
7219 : : {
7220 : 1155 : sym->as->type = AS_DEFERRED;
7221 : 1155 : sym->as->rank = *case_value;
7222 : : }
7223 : 32 : else if (*case_value == -1)
7224 : : {
7225 : 32 : sym->as->type = AS_ASSUMED_SIZE;
7226 : 32 : sym->as->rank = 1;
7227 : : }
7228 : : }
7229 : : }
7230 : :
7231 : 1381 : gfc_set_sym_referenced (sym);
7232 : 1381 : gfc_add_flavor (&sym->attr, FL_VARIABLE, name, NULL);
7233 : 1381 : sym->attr.select_type_temporary = 1;
7234 : 1381 : if (case_value)
7235 : 1381 : sym->attr.select_rank_temporary = 1;
7236 : :
7237 : 1381 : if (ts->type == BT_CLASS)
7238 : 145 : gfc_build_class_symbol (&sym->ts, &sym->attr, &sym->as);
7239 : :
7240 : : /* Add an association for it, so the rest of the parser knows it is
7241 : : an associate-name. The target will be set during resolution. */
7242 : 1381 : sym->assoc = gfc_get_association_list ();
7243 : 1381 : sym->assoc->dangling = 1;
7244 : 1381 : sym->assoc->st = tmp;
7245 : :
7246 : 1381 : select_type_stack->tmp = tmp;
7247 : : }
7248 : :
7249 : :
7250 : : /* Match a SELECT RANK statement. */
7251 : :
7252 : : match
7253 : 460880 : gfc_match_select_rank (void)
7254 : : {
7255 : 460880 : gfc_expr *expr1, *expr2 = NULL;
7256 : 460880 : match m;
7257 : 460880 : char name[GFC_MAX_SYMBOL_LEN + 1];
7258 : 460880 : gfc_symbol *sym, *sym2;
7259 : 460880 : gfc_namespace *ns = gfc_current_ns;
7260 : 460880 : gfc_array_spec *as = NULL;
7261 : :
7262 : 460880 : m = gfc_match_label ();
7263 : 460880 : if (m == MATCH_ERROR)
7264 : : return m;
7265 : :
7266 : 460872 : m = gfc_match (" select% rank ( ");
7267 : 460872 : if (m != MATCH_YES)
7268 : : return m;
7269 : :
7270 : 1023 : if (!gfc_notify_std (GFC_STD_F2018, "SELECT RANK statement at %C"))
7271 : : return MATCH_NO;
7272 : :
7273 : 1023 : gfc_current_ns = gfc_build_block_ns (ns);
7274 : 1023 : m = gfc_match (" %n => %e", name, &expr2);
7275 : :
7276 : 1023 : if (m == MATCH_YES)
7277 : : {
7278 : : /* If expr2 corresponds to an implicitly typed variable, then the
7279 : : actual type of the variable may not have been set. Set it here. */
7280 : 43 : if (!gfc_current_ns->seen_implicit_none
7281 : 43 : && expr2->expr_type == EXPR_VARIABLE
7282 : 42 : && expr2->ts.type == BT_UNKNOWN
7283 : 1 : && expr2->symtree && expr2->symtree->n.sym)
7284 : : {
7285 : 1 : gfc_set_default_type (expr2->symtree->n.sym, 0, gfc_current_ns);
7286 : 1 : expr2->ts.type = expr2->symtree->n.sym->ts.type;
7287 : : }
7288 : :
7289 : 43 : expr1 = gfc_get_expr ();
7290 : 43 : expr1->expr_type = EXPR_VARIABLE;
7291 : 43 : expr1->where = expr2->where;
7292 : 43 : expr1->ref = gfc_copy_ref (expr2->ref);
7293 : 43 : if (gfc_get_sym_tree (name, NULL, &expr1->symtree, false))
7294 : : {
7295 : 0 : m = MATCH_ERROR;
7296 : 0 : goto cleanup;
7297 : : }
7298 : :
7299 : 43 : sym = expr1->symtree->n.sym;
7300 : :
7301 : 43 : if (expr2->symtree)
7302 : : {
7303 : 42 : sym2 = expr2->symtree->n.sym;
7304 : 42 : as = (sym2->ts.type == BT_CLASS
7305 : 42 : && CLASS_DATA (sym2)) ? CLASS_DATA (sym2)->as : sym2->as;
7306 : : }
7307 : :
7308 : 43 : if (expr2->expr_type != EXPR_VARIABLE
7309 : 42 : || !(as && as->type == AS_ASSUMED_RANK))
7310 : : {
7311 : 1 : gfc_error ("The SELECT RANK selector at %C must be an assumed "
7312 : : "rank variable");
7313 : 1 : m = MATCH_ERROR;
7314 : 1 : goto cleanup;
7315 : : }
7316 : :
7317 : 42 : if (expr2->ts.type == BT_CLASS && CLASS_DATA (sym2))
7318 : : {
7319 : 12 : copy_ts_from_selector_to_associate (expr1, expr2);
7320 : :
7321 : 12 : sym->attr.flavor = FL_VARIABLE;
7322 : 12 : sym->attr.referenced = 1;
7323 : 12 : sym->attr.class_ok = 1;
7324 : 12 : CLASS_DATA (sym)->attr.allocatable = CLASS_DATA (sym2)->attr.allocatable;
7325 : 12 : CLASS_DATA (sym)->attr.pointer = CLASS_DATA (sym2)->attr.pointer;
7326 : 12 : CLASS_DATA (sym)->attr.target = CLASS_DATA (sym2)->attr.target;
7327 : 12 : sym->attr.pointer = 1;
7328 : : }
7329 : : else
7330 : : {
7331 : 30 : sym->ts = sym2->ts;
7332 : 30 : sym->as = gfc_copy_array_spec (sym2->as);
7333 : 30 : sym->attr.dimension = 1;
7334 : :
7335 : 30 : sym->attr.flavor = FL_VARIABLE;
7336 : 30 : sym->attr.referenced = 1;
7337 : 30 : sym->attr.class_ok = sym2->attr.class_ok;
7338 : 30 : sym->attr.allocatable = sym2->attr.allocatable;
7339 : 30 : sym->attr.pointer = sym2->attr.pointer;
7340 : 30 : sym->attr.target = sym2->attr.target;
7341 : : }
7342 : : }
7343 : : else
7344 : : {
7345 : 980 : m = gfc_match (" %e ", &expr1);
7346 : :
7347 : 980 : if (m != MATCH_YES)
7348 : : {
7349 : 1 : gfc_undo_symbols ();
7350 : 1 : std::swap (ns, gfc_current_ns);
7351 : 1 : gfc_free_namespace (ns);
7352 : 1 : return m;
7353 : : }
7354 : :
7355 : 979 : if (expr1->symtree)
7356 : : {
7357 : 978 : sym = expr1->symtree->n.sym;
7358 : 978 : as = (sym->ts.type == BT_CLASS
7359 : 978 : && CLASS_DATA (sym)) ? CLASS_DATA (sym)->as : sym->as;
7360 : : }
7361 : :
7362 : 979 : if (expr1->expr_type != EXPR_VARIABLE
7363 : 978 : || !(as && as->type == AS_ASSUMED_RANK))
7364 : : {
7365 : 3 : gfc_error("The SELECT RANK selector at %C must be an assumed "
7366 : : "rank variable");
7367 : 3 : m = MATCH_ERROR;
7368 : 3 : goto cleanup;
7369 : : }
7370 : : }
7371 : :
7372 : 1018 : m = gfc_match (" )%t");
7373 : 1018 : if (m != MATCH_YES)
7374 : : {
7375 : 0 : gfc_error ("parse error in SELECT RANK statement at %C");
7376 : 0 : goto cleanup;
7377 : : }
7378 : :
7379 : 1018 : new_st.op = EXEC_SELECT_RANK;
7380 : 1018 : new_st.expr1 = expr1;
7381 : 1018 : new_st.expr2 = expr2;
7382 : 1018 : new_st.ext.block.ns = gfc_current_ns;
7383 : :
7384 : 1018 : select_type_push (expr1->symtree->n.sym);
7385 : 1018 : gfc_current_ns = ns;
7386 : :
7387 : 1018 : return MATCH_YES;
7388 : :
7389 : 4 : cleanup:
7390 : 4 : gfc_free_expr (expr1);
7391 : 4 : gfc_free_expr (expr2);
7392 : 4 : gfc_undo_symbols ();
7393 : 4 : std::swap (ns, gfc_current_ns);
7394 : 4 : gfc_free_namespace (ns);
7395 : 4 : return m;
7396 : : }
7397 : :
7398 : :
7399 : : /* Match a CASE statement. */
7400 : :
7401 : : match
7402 : 1576 : gfc_match_case (void)
7403 : : {
7404 : 1576 : gfc_case *c, *head, *tail;
7405 : 1576 : match m;
7406 : :
7407 : 1576 : head = tail = NULL;
7408 : :
7409 : 1576 : if (gfc_current_state () != COMP_SELECT)
7410 : : {
7411 : 3 : gfc_error ("Unexpected CASE statement at %C");
7412 : 3 : return MATCH_ERROR;
7413 : : }
7414 : :
7415 : 1573 : if (gfc_match ("% default") == MATCH_YES)
7416 : : {
7417 : 362 : m = match_case_eos ();
7418 : 362 : if (m == MATCH_NO)
7419 : 1 : goto syntax;
7420 : 361 : if (m == MATCH_ERROR)
7421 : 0 : goto cleanup;
7422 : :
7423 : 361 : new_st.op = EXEC_SELECT;
7424 : 361 : c = gfc_get_case ();
7425 : 361 : c->where = gfc_current_locus;
7426 : 361 : new_st.ext.block.case_list = c;
7427 : 361 : return MATCH_YES;
7428 : : }
7429 : :
7430 : 1211 : if (gfc_match_char ('(') != MATCH_YES)
7431 : 0 : goto syntax;
7432 : :
7433 : 1409 : for (;;)
7434 : : {
7435 : 1409 : if (match_case_selector (&c) == MATCH_ERROR)
7436 : 10 : goto cleanup;
7437 : :
7438 : 1399 : if (head == NULL)
7439 : 1201 : head = c;
7440 : : else
7441 : 198 : tail->next = c;
7442 : :
7443 : 1399 : tail = c;
7444 : :
7445 : 1399 : if (gfc_match_char (')') == MATCH_YES)
7446 : : break;
7447 : 198 : if (gfc_match_char (',') != MATCH_YES)
7448 : 0 : goto syntax;
7449 : : }
7450 : :
7451 : 1201 : m = match_case_eos ();
7452 : 1201 : if (m == MATCH_NO)
7453 : 2 : goto syntax;
7454 : 1199 : if (m == MATCH_ERROR)
7455 : 0 : goto cleanup;
7456 : :
7457 : 1199 : new_st.op = EXEC_SELECT;
7458 : 1199 : new_st.ext.block.case_list = head;
7459 : :
7460 : 1199 : return MATCH_YES;
7461 : :
7462 : 3 : syntax:
7463 : 3 : gfc_error ("Syntax error in CASE specification at %C");
7464 : :
7465 : 13 : cleanup:
7466 : 13 : gfc_free_case_list (head); /* new_st is cleaned up in parse.cc. */
7467 : 13 : return MATCH_ERROR;
7468 : : }
7469 : :
7470 : :
7471 : : /* Match a TYPE IS statement. */
7472 : :
7473 : : match
7474 : 3292 : gfc_match_type_is (void)
7475 : : {
7476 : 3292 : gfc_case *c = NULL;
7477 : 3292 : match m;
7478 : :
7479 : 3292 : if (gfc_current_state () != COMP_SELECT_TYPE)
7480 : : {
7481 : 2 : gfc_error ("Unexpected TYPE IS statement at %C");
7482 : 2 : return MATCH_ERROR;
7483 : : }
7484 : :
7485 : 3290 : if (gfc_match_char ('(') != MATCH_YES)
7486 : 1 : goto syntax;
7487 : :
7488 : 3289 : c = gfc_get_case ();
7489 : 3289 : c->where = gfc_current_locus;
7490 : :
7491 : 3289 : m = gfc_match_type_spec (&c->ts);
7492 : 3289 : if (m == MATCH_NO)
7493 : 2 : goto syntax;
7494 : 3287 : if (m == MATCH_ERROR)
7495 : 0 : goto cleanup;
7496 : :
7497 : 3287 : if (gfc_match_char (')') != MATCH_YES)
7498 : 0 : goto syntax;
7499 : :
7500 : 3287 : m = match_case_eos ();
7501 : 3287 : if (m == MATCH_NO)
7502 : 0 : goto syntax;
7503 : 3287 : if (m == MATCH_ERROR)
7504 : 0 : goto cleanup;
7505 : :
7506 : 3287 : new_st.op = EXEC_SELECT_TYPE;
7507 : 3287 : new_st.ext.block.case_list = c;
7508 : :
7509 : 3287 : if (c->ts.type == BT_DERIVED && c->ts.u.derived
7510 : 1913 : && (c->ts.u.derived->attr.sequence
7511 : 1913 : || c->ts.u.derived->attr.is_bind_c))
7512 : : {
7513 : 1 : gfc_error ("The type-spec shall not specify a sequence derived "
7514 : : "type or a type with the BIND attribute in SELECT "
7515 : : "TYPE at %C [F2003:C815]");
7516 : 1 : return MATCH_ERROR;
7517 : : }
7518 : :
7519 : 3286 : if (c->ts.type == BT_DERIVED
7520 : 1912 : && c->ts.u.derived && c->ts.u.derived->attr.pdt_type
7521 : 3314 : && gfc_spec_list_type (type_param_spec_list, c->ts.u.derived)
7522 : : != SPEC_ASSUMED)
7523 : : {
7524 : 1 : gfc_error ("All the LEN type parameters in the TYPE IS statement "
7525 : : "at %C must be ASSUMED");
7526 : 1 : return MATCH_ERROR;
7527 : : }
7528 : :
7529 : : /* Create temporary variable. */
7530 : 3285 : select_type_set_tmp (&c->ts);
7531 : :
7532 : 3285 : return MATCH_YES;
7533 : :
7534 : 3 : syntax:
7535 : 3 : gfc_error ("Syntax error in TYPE IS specification at %C");
7536 : :
7537 : 3 : cleanup:
7538 : 3 : if (c != NULL)
7539 : 2 : gfc_free_case_list (c); /* new_st is cleaned up in parse.cc. */
7540 : : return MATCH_ERROR;
7541 : : }
7542 : :
7543 : :
7544 : : /* Match a CLASS IS or CLASS DEFAULT statement. */
7545 : :
7546 : : match
7547 : 1913 : gfc_match_class_is (void)
7548 : : {
7549 : 1913 : gfc_case *c = NULL;
7550 : 1913 : match m;
7551 : :
7552 : 1913 : if (gfc_current_state () != COMP_SELECT_TYPE)
7553 : : return MATCH_NO;
7554 : :
7555 : 1888 : if (gfc_match ("% default") == MATCH_YES)
7556 : : {
7557 : 1570 : m = match_case_eos ();
7558 : 1570 : if (m == MATCH_NO)
7559 : 0 : goto syntax;
7560 : 1570 : if (m == MATCH_ERROR)
7561 : 0 : goto cleanup;
7562 : :
7563 : 1570 : new_st.op = EXEC_SELECT_TYPE;
7564 : 1570 : c = gfc_get_case ();
7565 : 1570 : c->where = gfc_current_locus;
7566 : 1570 : c->ts.type = BT_UNKNOWN;
7567 : 1570 : new_st.ext.block.case_list = c;
7568 : 1570 : select_type_set_tmp (NULL);
7569 : 1570 : return MATCH_YES;
7570 : : }
7571 : :
7572 : 318 : m = gfc_match ("% is");
7573 : 318 : if (m == MATCH_NO)
7574 : 0 : goto syntax;
7575 : 318 : if (m == MATCH_ERROR)
7576 : 0 : goto cleanup;
7577 : :
7578 : 318 : if (gfc_match_char ('(') != MATCH_YES)
7579 : 0 : goto syntax;
7580 : :
7581 : 318 : c = gfc_get_case ();
7582 : 318 : c->where = gfc_current_locus;
7583 : :
7584 : 318 : m = match_derived_type_spec (&c->ts);
7585 : 318 : if (m == MATCH_NO)
7586 : 4 : goto syntax;
7587 : 314 : if (m == MATCH_ERROR)
7588 : 0 : goto cleanup;
7589 : :
7590 : 314 : if (c->ts.type == BT_DERIVED)
7591 : 314 : c->ts.type = BT_CLASS;
7592 : :
7593 : 314 : if (gfc_match_char (')') != MATCH_YES)
7594 : 0 : goto syntax;
7595 : :
7596 : 314 : m = match_case_eos ();
7597 : 314 : if (m == MATCH_NO)
7598 : 1 : goto syntax;
7599 : 313 : if (m == MATCH_ERROR)
7600 : 1 : goto cleanup;
7601 : :
7602 : 312 : new_st.op = EXEC_SELECT_TYPE;
7603 : 312 : new_st.ext.block.case_list = c;
7604 : :
7605 : : /* Create temporary variable. */
7606 : 312 : select_type_set_tmp (&c->ts);
7607 : :
7608 : 312 : return MATCH_YES;
7609 : :
7610 : 5 : syntax:
7611 : 5 : gfc_error ("Syntax error in CLASS IS specification at %C");
7612 : :
7613 : 6 : cleanup:
7614 : 6 : if (c != NULL)
7615 : 6 : gfc_free_case_list (c); /* new_st is cleaned up in parse.cc. */
7616 : : return MATCH_ERROR;
7617 : : }
7618 : :
7619 : :
7620 : : /* Match a RANK statement. */
7621 : :
7622 : : match
7623 : 2310 : gfc_match_rank_is (void)
7624 : : {
7625 : 2310 : gfc_case *c = NULL;
7626 : 2310 : match m;
7627 : 2310 : int case_value;
7628 : :
7629 : 2310 : if (gfc_current_state () != COMP_SELECT_RANK)
7630 : : {
7631 : 5 : gfc_error ("Unexpected RANK statement at %C");
7632 : 5 : return MATCH_ERROR;
7633 : : }
7634 : :
7635 : 2305 : if (gfc_match ("% default") == MATCH_YES)
7636 : : {
7637 : 919 : m = match_case_eos ();
7638 : 919 : if (m == MATCH_NO)
7639 : 0 : goto syntax;
7640 : 919 : if (m == MATCH_ERROR)
7641 : 0 : goto cleanup;
7642 : :
7643 : 919 : new_st.op = EXEC_SELECT_RANK;
7644 : 919 : c = gfc_get_case ();
7645 : 919 : c->ts.type = BT_UNKNOWN;
7646 : 919 : c->where = gfc_current_locus;
7647 : 919 : new_st.ext.block.case_list = c;
7648 : 919 : select_type_stack->tmp = NULL;
7649 : 919 : return MATCH_YES;
7650 : : }
7651 : :
7652 : 1386 : if (gfc_match_char ('(') != MATCH_YES)
7653 : 0 : goto syntax;
7654 : :
7655 : 1386 : c = gfc_get_case ();
7656 : 1386 : c->where = gfc_current_locus;
7657 : 1386 : c->ts = select_type_stack->selector->ts;
7658 : :
7659 : 1386 : m = gfc_match_expr (&c->low);
7660 : 1386 : if (m == MATCH_NO)
7661 : : {
7662 : 33 : if (gfc_match_char ('*') == MATCH_YES)
7663 : 33 : c->low = gfc_get_int_expr (gfc_default_integer_kind,
7664 : : NULL, -1);
7665 : : else
7666 : 0 : goto syntax;
7667 : :
7668 : 33 : case_value = -1;
7669 : : }
7670 : 1353 : else if (m == MATCH_YES)
7671 : : {
7672 : : /* F2018: R1150 */
7673 : 1353 : if (c->low->expr_type != EXPR_CONSTANT
7674 : 1352 : || c->low->ts.type != BT_INTEGER
7675 : 1352 : || c->low->rank)
7676 : : {
7677 : 1 : gfc_error ("The SELECT RANK CASE expression at %C must be a "
7678 : : "scalar, integer constant");
7679 : 1 : goto cleanup;
7680 : : }
7681 : :
7682 : 1352 : case_value = (int) mpz_get_si (c->low->value.integer);
7683 : : /* F2018: C1151 */
7684 : 1352 : if ((case_value < 0) || (case_value > GFC_MAX_DIMENSIONS))
7685 : : {
7686 : 2 : gfc_error ("The value of the SELECT RANK CASE expression at "
7687 : : "%C must not be less than zero or greater than %d",
7688 : : GFC_MAX_DIMENSIONS);
7689 : 2 : goto cleanup;
7690 : : }
7691 : : }
7692 : : else
7693 : 0 : goto cleanup;
7694 : :
7695 : 1383 : if (gfc_match_char (')') != MATCH_YES)
7696 : 0 : goto syntax;
7697 : :
7698 : 1383 : m = match_case_eos ();
7699 : 1383 : if (m == MATCH_NO)
7700 : 0 : goto syntax;
7701 : 1383 : if (m == MATCH_ERROR)
7702 : 0 : goto cleanup;
7703 : :
7704 : 1383 : new_st.op = EXEC_SELECT_RANK;
7705 : 1383 : new_st.ext.block.case_list = c;
7706 : :
7707 : : /* Create temporary variable. Recycle the select type code. */
7708 : 1383 : select_rank_set_tmp (&c->ts, &case_value);
7709 : :
7710 : 1383 : return MATCH_YES;
7711 : :
7712 : 0 : syntax:
7713 : 0 : gfc_error ("Syntax error in RANK specification at %C");
7714 : :
7715 : 3 : cleanup:
7716 : 3 : if (c != NULL)
7717 : 3 : gfc_free_case_list (c); /* new_st is cleaned up in parse.cc. */
7718 : : return MATCH_ERROR;
7719 : : }
7720 : :
7721 : : /********************* WHERE subroutines ********************/
7722 : :
7723 : : /* Match the rest of a simple WHERE statement that follows an IF statement.
7724 : : */
7725 : :
7726 : : static match
7727 : 7 : match_simple_where (void)
7728 : : {
7729 : 7 : gfc_expr *expr;
7730 : 7 : gfc_code *c;
7731 : 7 : match m;
7732 : :
7733 : 7 : m = gfc_match (" ( %e )", &expr);
7734 : 7 : if (m != MATCH_YES)
7735 : : return m;
7736 : :
7737 : 7 : m = gfc_match_assignment ();
7738 : 7 : if (m == MATCH_NO)
7739 : 0 : goto syntax;
7740 : 7 : if (m == MATCH_ERROR)
7741 : 0 : goto cleanup;
7742 : :
7743 : 7 : if (gfc_match_eos () != MATCH_YES)
7744 : 0 : goto syntax;
7745 : :
7746 : 7 : c = gfc_get_code (EXEC_WHERE);
7747 : 7 : c->expr1 = expr;
7748 : :
7749 : 7 : c->next = XCNEW (gfc_code);
7750 : 7 : *c->next = new_st;
7751 : 7 : c->next->loc = gfc_current_locus;
7752 : 7 : gfc_clear_new_st ();
7753 : :
7754 : 7 : new_st.op = EXEC_WHERE;
7755 : 7 : new_st.block = c;
7756 : :
7757 : 7 : return MATCH_YES;
7758 : :
7759 : 0 : syntax:
7760 : 0 : gfc_syntax_error (ST_WHERE);
7761 : :
7762 : 0 : cleanup:
7763 : 0 : gfc_free_expr (expr);
7764 : 0 : return MATCH_ERROR;
7765 : : }
7766 : :
7767 : :
7768 : : /* Match a WHERE statement. */
7769 : :
7770 : : match
7771 : 501364 : gfc_match_where (gfc_statement *st)
7772 : : {
7773 : 501364 : gfc_expr *expr;
7774 : 501364 : match m0, m;
7775 : 501364 : gfc_code *c;
7776 : :
7777 : 501364 : m0 = gfc_match_label ();
7778 : 501364 : if (m0 == MATCH_ERROR)
7779 : : return m0;
7780 : :
7781 : 501356 : m = gfc_match (" where ( %e )", &expr);
7782 : 501356 : if (m != MATCH_YES)
7783 : : return m;
7784 : :
7785 : 443 : if (gfc_match_eos () == MATCH_YES)
7786 : : {
7787 : 371 : *st = ST_WHERE_BLOCK;
7788 : 371 : new_st.op = EXEC_WHERE;
7789 : 371 : new_st.expr1 = expr;
7790 : 371 : return MATCH_YES;
7791 : : }
7792 : :
7793 : 72 : m = gfc_match_assignment ();
7794 : 72 : if (m == MATCH_NO)
7795 : 0 : gfc_syntax_error (ST_WHERE);
7796 : :
7797 : 72 : if (m != MATCH_YES)
7798 : : {
7799 : 0 : gfc_free_expr (expr);
7800 : 0 : return MATCH_ERROR;
7801 : : }
7802 : :
7803 : : /* We've got a simple WHERE statement. */
7804 : 72 : *st = ST_WHERE;
7805 : 72 : c = gfc_get_code (EXEC_WHERE);
7806 : 72 : c->expr1 = expr;
7807 : :
7808 : : /* Put in the assignment. It will not be processed by add_statement, so we
7809 : : need to copy the location here. */
7810 : :
7811 : 72 : c->next = XCNEW (gfc_code);
7812 : 72 : *c->next = new_st;
7813 : 72 : c->next->loc = gfc_current_locus;
7814 : 72 : gfc_clear_new_st ();
7815 : :
7816 : 72 : new_st.op = EXEC_WHERE;
7817 : 72 : new_st.block = c;
7818 : :
7819 : 72 : return MATCH_YES;
7820 : : }
7821 : :
7822 : :
7823 : : /* Match an ELSEWHERE statement. We leave behind a WHERE node in
7824 : : new_st if successful. */
7825 : :
7826 : : match
7827 : 313 : gfc_match_elsewhere (void)
7828 : : {
7829 : 313 : char name[GFC_MAX_SYMBOL_LEN + 1];
7830 : 313 : gfc_expr *expr;
7831 : 313 : match m;
7832 : :
7833 : 313 : if (gfc_current_state () != COMP_WHERE)
7834 : : {
7835 : 0 : gfc_error ("ELSEWHERE statement at %C not enclosed in WHERE block");
7836 : 0 : return MATCH_ERROR;
7837 : : }
7838 : :
7839 : 313 : expr = NULL;
7840 : :
7841 : 313 : if (gfc_match_char ('(') == MATCH_YES)
7842 : : {
7843 : 179 : m = gfc_match_expr (&expr);
7844 : 179 : if (m == MATCH_NO)
7845 : 0 : goto syntax;
7846 : 179 : if (m == MATCH_ERROR)
7847 : : return MATCH_ERROR;
7848 : :
7849 : 179 : if (gfc_match_char (')') != MATCH_YES)
7850 : 0 : goto syntax;
7851 : : }
7852 : :
7853 : 313 : if (gfc_match_eos () != MATCH_YES)
7854 : : {
7855 : : /* Only makes sense if we have a where-construct-name. */
7856 : 2 : if (!gfc_current_block ())
7857 : : {
7858 : 1 : m = MATCH_ERROR;
7859 : 1 : goto cleanup;
7860 : : }
7861 : : /* Better be a name at this point. */
7862 : 1 : m = gfc_match_name (name);
7863 : 1 : if (m == MATCH_NO)
7864 : 0 : goto syntax;
7865 : 1 : if (m == MATCH_ERROR)
7866 : 0 : goto cleanup;
7867 : :
7868 : 1 : if (gfc_match_eos () != MATCH_YES)
7869 : 0 : goto syntax;
7870 : :
7871 : 1 : if (strcmp (name, gfc_current_block ()->name) != 0)
7872 : : {
7873 : 0 : gfc_error ("Label %qs at %C doesn't match WHERE label %qs",
7874 : : name, gfc_current_block ()->name);
7875 : 0 : goto cleanup;
7876 : : }
7877 : : }
7878 : :
7879 : 312 : new_st.op = EXEC_WHERE;
7880 : 312 : new_st.expr1 = expr;
7881 : 312 : return MATCH_YES;
7882 : :
7883 : 0 : syntax:
7884 : 0 : gfc_syntax_error (ST_ELSEWHERE);
7885 : :
7886 : 1 : cleanup:
7887 : 1 : gfc_free_expr (expr);
7888 : 1 : return MATCH_ERROR;
7889 : : }
|