]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/parse.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / fortran / parse.cc
1 /* Main parser.
2 Copyright (C) 2000-2024 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 <setjmp.h>
27 #include "match.h"
28 #include "parse.h"
29 #include "tree-core.h"
30 #include "omp-general.h"
31
32 /* Current statement label. Zero means no statement label. Because new_st
33 can get wiped during statement matching, we have to keep it separate. */
34
35 gfc_st_label *gfc_statement_label;
36
37 static locus label_locus;
38 static jmp_buf eof_buf;
39
40 /* Respectively pointer and content of the current interface body being parsed
41 as they were at the beginning of decode_statement. Used to restore the
42 interface to its previous state in case a parsed statement is rejected after
43 some symbols have been added to the interface. */
44 static gfc_interface **current_interface_ptr = nullptr;
45 static gfc_interface *previous_interface_head = nullptr;
46
47 gfc_state_data *gfc_state_stack;
48 static bool last_was_use_stmt = false;
49 bool in_exec_part;
50
51 /* TODO: Re-order functions to kill these forward decls. */
52 static void check_statement_label (gfc_statement);
53 static void undo_new_statement (void);
54 static void reject_statement (void);
55
56
57 /* A sort of half-matching function. We try to match the word on the
58 input with the passed string. If this succeeds, we call the
59 keyword-dependent matching function that will match the rest of the
60 statement. For single keywords, the matching subroutine is
61 gfc_match_eos(). */
62
63 static match
64 match_word (const char *str, match (*subr) (void), locus *old_locus)
65 {
66 match m;
67
68 if (str != NULL)
69 {
70 m = gfc_match (str);
71 if (m != MATCH_YES)
72 return m;
73 }
74
75 m = (*subr) ();
76
77 if (m != MATCH_YES)
78 {
79 gfc_current_locus = *old_locus;
80 reject_statement ();
81 }
82
83 return m;
84 }
85
86
87 /* Like match_word, but if str is matched, set a flag that it
88 was matched. */
89 static match
90 match_word_omp_simd (const char *str, match (*subr) (void), locus *old_locus,
91 bool *simd_matched)
92 {
93 match m;
94
95 if (str != NULL)
96 {
97 m = gfc_match (str);
98 if (m != MATCH_YES)
99 return m;
100 *simd_matched = true;
101 }
102
103 m = (*subr) ();
104
105 if (m != MATCH_YES)
106 {
107 gfc_current_locus = *old_locus;
108 reject_statement ();
109 }
110
111 return m;
112 }
113
114
115 /* Load symbols from all USE statements encountered in this scoping unit. */
116
117 static void
118 use_modules (void)
119 {
120 gfc_error_buffer old_error;
121
122 gfc_push_error (&old_error);
123 gfc_buffer_error (false);
124 gfc_use_modules ();
125 gfc_buffer_error (true);
126 gfc_pop_error (&old_error);
127 gfc_commit_symbols ();
128 gfc_warning_check ();
129 gfc_current_ns->old_equiv = gfc_current_ns->equiv;
130 gfc_current_ns->old_data = gfc_current_ns->data;
131 last_was_use_stmt = false;
132 }
133
134
135 /* Figure out what the next statement is, (mostly) regardless of
136 proper ordering. The do...while(0) is there to prevent if/else
137 ambiguity. */
138
139 #define match(keyword, subr, st) \
140 do { \
141 if (match_word (keyword, subr, &old_locus) == MATCH_YES) \
142 return st; \
143 else \
144 undo_new_statement (); \
145 } while (0)
146
147
148 /* This is a specialist version of decode_statement that is used
149 for the specification statements in a function, whose
150 characteristics are deferred into the specification statements.
151 eg.: INTEGER (king = mykind) foo ()
152 USE mymodule, ONLY mykind.....
153 The KIND parameter needs a return after USE or IMPORT, whereas
154 derived type declarations can occur anywhere, up the executable
155 block. ST_GET_FCN_CHARACTERISTICS is returned when we have run
156 out of the correct kind of specification statements. */
157 static gfc_statement
158 decode_specification_statement (void)
159 {
160 gfc_statement st;
161 locus old_locus;
162 char c;
163
164 if (gfc_match_eos () == MATCH_YES)
165 return ST_NONE;
166
167 old_locus = gfc_current_locus;
168
169 if (match_word ("use", gfc_match_use, &old_locus) == MATCH_YES)
170 {
171 last_was_use_stmt = true;
172 return ST_USE;
173 }
174 else
175 {
176 undo_new_statement ();
177 if (last_was_use_stmt)
178 use_modules ();
179 }
180
181 match ("import", gfc_match_import, ST_IMPORT);
182
183 if (gfc_current_block ()->result->ts.type != BT_DERIVED)
184 goto end_of_block;
185
186 match (NULL, gfc_match_st_function, ST_STATEMENT_FUNCTION);
187 match (NULL, gfc_match_data_decl, ST_DATA_DECL);
188 match (NULL, gfc_match_enumerator_def, ST_ENUMERATOR);
189
190 /* General statement matching: Instead of testing every possible
191 statement, we eliminate most possibilities by peeking at the
192 first character. */
193
194 c = gfc_peek_ascii_char ();
195
196 switch (c)
197 {
198 case 'a':
199 match ("abstract% interface", gfc_match_abstract_interface,
200 ST_INTERFACE);
201 match ("allocatable", gfc_match_allocatable, ST_ATTR_DECL);
202 match ("asynchronous", gfc_match_asynchronous, ST_ATTR_DECL);
203 match ("automatic", gfc_match_automatic, ST_ATTR_DECL);
204 break;
205
206 case 'b':
207 match (NULL, gfc_match_bind_c_stmt, ST_ATTR_DECL);
208 break;
209
210 case 'c':
211 match ("codimension", gfc_match_codimension, ST_ATTR_DECL);
212 match ("contiguous", gfc_match_contiguous, ST_ATTR_DECL);
213 break;
214
215 case 'd':
216 match ("data", gfc_match_data, ST_DATA);
217 match ("dimension", gfc_match_dimension, ST_ATTR_DECL);
218 break;
219
220 case 'e':
221 match ("enum , bind ( c )", gfc_match_enum, ST_ENUM);
222 match ("entry% ", gfc_match_entry, ST_ENTRY);
223 match ("equivalence", gfc_match_equivalence, ST_EQUIVALENCE);
224 match ("external", gfc_match_external, ST_ATTR_DECL);
225 break;
226
227 case 'f':
228 match ("format", gfc_match_format, ST_FORMAT);
229 break;
230
231 case 'g':
232 break;
233
234 case 'i':
235 match ("implicit", gfc_match_implicit, ST_IMPLICIT);
236 match ("implicit% none", gfc_match_implicit_none, ST_IMPLICIT_NONE);
237 match ("interface", gfc_match_interface, ST_INTERFACE);
238 match ("intent", gfc_match_intent, ST_ATTR_DECL);
239 match ("intrinsic", gfc_match_intrinsic, ST_ATTR_DECL);
240 break;
241
242 case 'm':
243 break;
244
245 case 'n':
246 match ("namelist", gfc_match_namelist, ST_NAMELIST);
247 break;
248
249 case 'o':
250 match ("optional", gfc_match_optional, ST_ATTR_DECL);
251 break;
252
253 case 'p':
254 match ("parameter", gfc_match_parameter, ST_PARAMETER);
255 match ("pointer", gfc_match_pointer, ST_ATTR_DECL);
256 if (gfc_match_private (&st) == MATCH_YES)
257 return st;
258 match ("procedure", gfc_match_procedure, ST_PROCEDURE);
259 if (gfc_match_public (&st) == MATCH_YES)
260 return st;
261 match ("protected", gfc_match_protected, ST_ATTR_DECL);
262 break;
263
264 case 'r':
265 break;
266
267 case 's':
268 match ("save", gfc_match_save, ST_ATTR_DECL);
269 match ("static", gfc_match_static, ST_ATTR_DECL);
270 match ("structure", gfc_match_structure_decl, ST_STRUCTURE_DECL);
271 break;
272
273 case 't':
274 match ("target", gfc_match_target, ST_ATTR_DECL);
275 match ("type", gfc_match_derived_decl, ST_DERIVED_DECL);
276 break;
277
278 case 'u':
279 break;
280
281 case 'v':
282 match ("value", gfc_match_value, ST_ATTR_DECL);
283 match ("volatile", gfc_match_volatile, ST_ATTR_DECL);
284 break;
285
286 case 'w':
287 break;
288 }
289
290 /* This is not a specification statement. See if any of the matchers
291 has stored an error message of some sort. */
292
293 end_of_block:
294 gfc_clear_error ();
295 gfc_buffer_error (false);
296 gfc_current_locus = old_locus;
297
298 return ST_GET_FCN_CHARACTERISTICS;
299 }
300
301
302 /* Tells whether gfc_get_current_interface_head can be used safely. */
303
304 static bool
305 current_interface_valid_p ()
306 {
307 switch (current_interface.type)
308 {
309 case INTERFACE_INTRINSIC_OP:
310 return current_interface.ns != nullptr;
311
312 case INTERFACE_GENERIC:
313 case INTERFACE_DTIO:
314 return current_interface.sym != nullptr;
315
316 case INTERFACE_USER_OP:
317 return current_interface.uop != nullptr;
318
319 default:
320 return false;
321 }
322 }
323
324
325 /* Return a pointer to the interface currently being parsed, or nullptr if
326 we are not currently parsing an interface body. */
327
328 static gfc_interface **
329 get_current_interface_ptr ()
330 {
331 if (current_interface_valid_p ())
332 {
333 gfc_interface *& ifc_ptr = gfc_current_interface_head ();
334 return &ifc_ptr;
335 }
336 else
337 return nullptr;
338 }
339
340
341 static bool in_specification_block;
342
343 /* This is the primary 'decode_statement'. */
344 static gfc_statement
345 decode_statement (void)
346 {
347 gfc_statement st;
348 locus old_locus;
349 match m = MATCH_NO;
350 char c;
351
352 gfc_enforce_clean_symbol_state ();
353
354 gfc_clear_error (); /* Clear any pending errors. */
355 gfc_clear_warning (); /* Clear any pending warnings. */
356
357 current_interface_ptr = get_current_interface_ptr ();
358 previous_interface_head = current_interface_ptr == nullptr
359 ? nullptr
360 : *current_interface_ptr;
361
362 gfc_matching_function = false;
363
364 if (gfc_match_eos () == MATCH_YES)
365 return ST_NONE;
366
367 if (gfc_current_state () == COMP_FUNCTION
368 && gfc_current_block ()->result->ts.kind == -1)
369 return decode_specification_statement ();
370
371 old_locus = gfc_current_locus;
372
373 c = gfc_peek_ascii_char ();
374
375 if (c == 'u')
376 {
377 if (match_word ("use", gfc_match_use, &old_locus) == MATCH_YES)
378 {
379 last_was_use_stmt = true;
380 return ST_USE;
381 }
382 else
383 undo_new_statement ();
384 }
385
386 if (last_was_use_stmt)
387 use_modules ();
388
389 /* Try matching a data declaration or function declaration. The
390 input "REALFUNCTIONA(N)" can mean several things in different
391 contexts, so it (and its relatives) get special treatment. */
392
393 if (gfc_current_state () == COMP_NONE
394 || gfc_current_state () == COMP_INTERFACE
395 || gfc_current_state () == COMP_CONTAINS)
396 {
397 gfc_matching_function = true;
398 m = gfc_match_function_decl ();
399 if (m == MATCH_YES)
400 return ST_FUNCTION;
401 else if (m == MATCH_ERROR)
402 reject_statement ();
403 else
404 gfc_undo_symbols ();
405 gfc_current_locus = old_locus;
406 }
407 gfc_matching_function = false;
408
409 /* Legacy parameter statements are ambiguous with assignments so try parameter
410 first. */
411 match ("parameter", gfc_match_parameter, ST_PARAMETER);
412
413 /* Match statements whose error messages are meant to be overwritten
414 by something better. */
415
416 match (NULL, gfc_match_assignment, ST_ASSIGNMENT);
417 match (NULL, gfc_match_pointer_assignment, ST_POINTER_ASSIGNMENT);
418
419 if (in_specification_block)
420 {
421 m = match_word (NULL, gfc_match_st_function, &old_locus);
422 if (m == MATCH_YES)
423 return ST_STATEMENT_FUNCTION;
424 }
425
426 if (!(in_specification_block && m == MATCH_ERROR))
427 {
428 match (NULL, gfc_match_ptr_fcn_assign, ST_ASSIGNMENT);
429 }
430
431 match (NULL, gfc_match_data_decl, ST_DATA_DECL);
432 match (NULL, gfc_match_enumerator_def, ST_ENUMERATOR);
433
434 /* Try to match a subroutine statement, which has the same optional
435 prefixes that functions can have. */
436
437 if (gfc_match_subroutine () == MATCH_YES)
438 return ST_SUBROUTINE;
439 gfc_undo_symbols ();
440 gfc_current_locus = old_locus;
441
442 if (gfc_match_submod_proc () == MATCH_YES)
443 {
444 if (gfc_new_block->attr.subroutine)
445 return ST_SUBROUTINE;
446 else if (gfc_new_block->attr.function)
447 return ST_FUNCTION;
448 }
449 gfc_undo_symbols ();
450 gfc_current_locus = old_locus;
451
452 /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
453 statements, which might begin with a block label. The match functions for
454 these statements are unusual in that their keyword is not seen before
455 the matcher is called. */
456
457 if (gfc_match_if (&st) == MATCH_YES)
458 return st;
459 gfc_undo_symbols ();
460 gfc_current_locus = old_locus;
461
462 if (gfc_match_where (&st) == MATCH_YES)
463 return st;
464 gfc_undo_symbols ();
465 gfc_current_locus = old_locus;
466
467 if (gfc_match_forall (&st) == MATCH_YES)
468 return st;
469 gfc_undo_symbols ();
470 gfc_current_locus = old_locus;
471
472 /* Try to match TYPE as an alias for PRINT. */
473 if (gfc_match_type (&st) == MATCH_YES)
474 return st;
475 gfc_undo_symbols ();
476 gfc_current_locus = old_locus;
477
478 match (NULL, gfc_match_do, ST_DO);
479 match (NULL, gfc_match_block, ST_BLOCK);
480 match (NULL, gfc_match_associate, ST_ASSOCIATE);
481 match (NULL, gfc_match_critical, ST_CRITICAL);
482 match (NULL, gfc_match_select, ST_SELECT_CASE);
483 match (NULL, gfc_match_select_type, ST_SELECT_TYPE);
484 match (NULL, gfc_match_select_rank, ST_SELECT_RANK);
485
486 /* General statement matching: Instead of testing every possible
487 statement, we eliminate most possibilities by peeking at the
488 first character. */
489
490 switch (c)
491 {
492 case 'a':
493 match ("abstract% interface", gfc_match_abstract_interface,
494 ST_INTERFACE);
495 match ("allocate", gfc_match_allocate, ST_ALLOCATE);
496 match ("allocatable", gfc_match_allocatable, ST_ATTR_DECL);
497 match ("assign", gfc_match_assign, ST_LABEL_ASSIGNMENT);
498 match ("asynchronous", gfc_match_asynchronous, ST_ATTR_DECL);
499 match ("automatic", gfc_match_automatic, ST_ATTR_DECL);
500 break;
501
502 case 'b':
503 match ("backspace", gfc_match_backspace, ST_BACKSPACE);
504 match ("block data", gfc_match_block_data, ST_BLOCK_DATA);
505 match (NULL, gfc_match_bind_c_stmt, ST_ATTR_DECL);
506 break;
507
508 case 'c':
509 match ("call", gfc_match_call, ST_CALL);
510 match ("change% team", gfc_match_change_team, ST_CHANGE_TEAM);
511 match ("close", gfc_match_close, ST_CLOSE);
512 match ("continue", gfc_match_continue, ST_CONTINUE);
513 match ("contiguous", gfc_match_contiguous, ST_ATTR_DECL);
514 match ("cycle", gfc_match_cycle, ST_CYCLE);
515 match ("case", gfc_match_case, ST_CASE);
516 match ("common", gfc_match_common, ST_COMMON);
517 match ("contains", gfc_match_eos, ST_CONTAINS);
518 match ("class", gfc_match_class_is, ST_CLASS_IS);
519 match ("codimension", gfc_match_codimension, ST_ATTR_DECL);
520 break;
521
522 case 'd':
523 match ("deallocate", gfc_match_deallocate, ST_DEALLOCATE);
524 match ("data", gfc_match_data, ST_DATA);
525 match ("dimension", gfc_match_dimension, ST_ATTR_DECL);
526 break;
527
528 case 'e':
529 match ("end file", gfc_match_endfile, ST_END_FILE);
530 match ("end team", gfc_match_end_team, ST_END_TEAM);
531 match ("exit", gfc_match_exit, ST_EXIT);
532 match ("else", gfc_match_else, ST_ELSE);
533 match ("else where", gfc_match_elsewhere, ST_ELSEWHERE);
534 match ("else if", gfc_match_elseif, ST_ELSEIF);
535 match ("error% stop", gfc_match_error_stop, ST_ERROR_STOP);
536 match ("enum , bind ( c )", gfc_match_enum, ST_ENUM);
537
538 if (gfc_match_end (&st) == MATCH_YES)
539 return st;
540
541 match ("entry% ", gfc_match_entry, ST_ENTRY);
542 match ("equivalence", gfc_match_equivalence, ST_EQUIVALENCE);
543 match ("external", gfc_match_external, ST_ATTR_DECL);
544 match ("event% post", gfc_match_event_post, ST_EVENT_POST);
545 match ("event% wait", gfc_match_event_wait, ST_EVENT_WAIT);
546 break;
547
548 case 'f':
549 match ("fail% image", gfc_match_fail_image, ST_FAIL_IMAGE);
550 match ("final", gfc_match_final_decl, ST_FINAL);
551 match ("flush", gfc_match_flush, ST_FLUSH);
552 match ("form% team", gfc_match_form_team, ST_FORM_TEAM);
553 match ("format", gfc_match_format, ST_FORMAT);
554 break;
555
556 case 'g':
557 match ("generic", gfc_match_generic, ST_GENERIC);
558 match ("go to", gfc_match_goto, ST_GOTO);
559 break;
560
561 case 'i':
562 match ("inquire", gfc_match_inquire, ST_INQUIRE);
563 match ("implicit", gfc_match_implicit, ST_IMPLICIT);
564 match ("implicit% none", gfc_match_implicit_none, ST_IMPLICIT_NONE);
565 match ("import", gfc_match_import, ST_IMPORT);
566 match ("interface", gfc_match_interface, ST_INTERFACE);
567 match ("intent", gfc_match_intent, ST_ATTR_DECL);
568 match ("intrinsic", gfc_match_intrinsic, ST_ATTR_DECL);
569 break;
570
571 case 'l':
572 match ("lock", gfc_match_lock, ST_LOCK);
573 break;
574
575 case 'm':
576 match ("map", gfc_match_map, ST_MAP);
577 match ("module% procedure", gfc_match_modproc, ST_MODULE_PROC);
578 match ("module", gfc_match_module, ST_MODULE);
579 break;
580
581 case 'n':
582 match ("nullify", gfc_match_nullify, ST_NULLIFY);
583 match ("namelist", gfc_match_namelist, ST_NAMELIST);
584 break;
585
586 case 'o':
587 match ("open", gfc_match_open, ST_OPEN);
588 match ("optional", gfc_match_optional, ST_ATTR_DECL);
589 break;
590
591 case 'p':
592 match ("print", gfc_match_print, ST_WRITE);
593 match ("pause", gfc_match_pause, ST_PAUSE);
594 match ("pointer", gfc_match_pointer, ST_ATTR_DECL);
595 if (gfc_match_private (&st) == MATCH_YES)
596 return st;
597 match ("procedure", gfc_match_procedure, ST_PROCEDURE);
598 match ("program", gfc_match_program, ST_PROGRAM);
599 if (gfc_match_public (&st) == MATCH_YES)
600 return st;
601 match ("protected", gfc_match_protected, ST_ATTR_DECL);
602 break;
603
604 case 'r':
605 match ("rank", gfc_match_rank_is, ST_RANK);
606 match ("read", gfc_match_read, ST_READ);
607 match ("return", gfc_match_return, ST_RETURN);
608 match ("rewind", gfc_match_rewind, ST_REWIND);
609 break;
610
611 case 's':
612 match ("structure", gfc_match_structure_decl, ST_STRUCTURE_DECL);
613 match ("sequence", gfc_match_eos, ST_SEQUENCE);
614 match ("stop", gfc_match_stop, ST_STOP);
615 match ("save", gfc_match_save, ST_ATTR_DECL);
616 match ("static", gfc_match_static, ST_ATTR_DECL);
617 match ("submodule", gfc_match_submodule, ST_SUBMODULE);
618 match ("sync% all", gfc_match_sync_all, ST_SYNC_ALL);
619 match ("sync% images", gfc_match_sync_images, ST_SYNC_IMAGES);
620 match ("sync% memory", gfc_match_sync_memory, ST_SYNC_MEMORY);
621 match ("sync% team", gfc_match_sync_team, ST_SYNC_TEAM);
622 break;
623
624 case 't':
625 match ("target", gfc_match_target, ST_ATTR_DECL);
626 match ("type", gfc_match_derived_decl, ST_DERIVED_DECL);
627 match ("type% is", gfc_match_type_is, ST_TYPE_IS);
628 break;
629
630 case 'u':
631 match ("union", gfc_match_union, ST_UNION);
632 match ("unlock", gfc_match_unlock, ST_UNLOCK);
633 break;
634
635 case 'v':
636 match ("value", gfc_match_value, ST_ATTR_DECL);
637 match ("volatile", gfc_match_volatile, ST_ATTR_DECL);
638 break;
639
640 case 'w':
641 match ("wait", gfc_match_wait, ST_WAIT);
642 match ("write", gfc_match_write, ST_WRITE);
643 break;
644 }
645
646 /* All else has failed, so give up. See if any of the matchers has
647 stored an error message of some sort. Suppress the "Unclassifiable
648 statement" if a previous error message was emitted, e.g., by
649 gfc_error_now (). */
650 if (!gfc_error_check ())
651 {
652 int ecnt;
653 gfc_get_errors (NULL, &ecnt);
654 if (ecnt <= 0)
655 gfc_error_now ("Unclassifiable statement at %C");
656 }
657
658 reject_statement ();
659
660 gfc_error_recovery ();
661
662 return ST_NONE;
663 }
664
665 /* Like match and if spec_only, goto do_spec_only without actually
666 matching. */
667 /* If the directive matched but the clauses failed, do not start
668 matching the next directive in the same switch statement. */
669 #define matcha(keyword, subr, st) \
670 do { \
671 match m2; \
672 if (spec_only && gfc_match (keyword) == MATCH_YES) \
673 goto do_spec_only; \
674 else if ((m2 = match_word (keyword, subr, &old_locus)) \
675 == MATCH_YES) \
676 return st; \
677 else if (m2 == MATCH_ERROR) \
678 goto error_handling; \
679 else \
680 undo_new_statement (); \
681 } while (0)
682
683 static gfc_statement
684 decode_oacc_directive (void)
685 {
686 locus old_locus;
687 char c;
688 bool spec_only = false;
689
690 gfc_enforce_clean_symbol_state ();
691
692 gfc_clear_error (); /* Clear any pending errors. */
693 gfc_clear_warning (); /* Clear any pending warnings. */
694
695 gfc_matching_function = false;
696
697 if (gfc_current_state () == COMP_FUNCTION
698 && gfc_current_block ()->result->ts.kind == -1)
699 spec_only = true;
700
701 old_locus = gfc_current_locus;
702
703 /* General OpenACC directive matching: Instead of testing every possible
704 statement, we eliminate most possibilities by peeking at the
705 first character. */
706
707 c = gfc_peek_ascii_char ();
708
709 switch (c)
710 {
711 case 'r':
712 matcha ("routine", gfc_match_oacc_routine, ST_OACC_ROUTINE);
713 break;
714 }
715
716 gfc_unset_implicit_pure (NULL);
717 if (gfc_pure (NULL))
718 {
719 gfc_error_now ("OpenACC directives other than ROUTINE may not appear in PURE "
720 "procedures at %C");
721 goto error_handling;
722 }
723
724 switch (c)
725 {
726 case 'a':
727 matcha ("atomic", gfc_match_oacc_atomic, ST_OACC_ATOMIC);
728 break;
729 case 'c':
730 matcha ("cache", gfc_match_oacc_cache, ST_OACC_CACHE);
731 break;
732 case 'd':
733 matcha ("data", gfc_match_oacc_data, ST_OACC_DATA);
734 match ("declare", gfc_match_oacc_declare, ST_OACC_DECLARE);
735 break;
736 case 'e':
737 matcha ("end atomic", gfc_match_omp_eos_error, ST_OACC_END_ATOMIC);
738 matcha ("end data", gfc_match_omp_eos_error, ST_OACC_END_DATA);
739 matcha ("end host_data", gfc_match_omp_eos_error, ST_OACC_END_HOST_DATA);
740 matcha ("end kernels loop", gfc_match_omp_eos_error, ST_OACC_END_KERNELS_LOOP);
741 matcha ("end kernels", gfc_match_omp_eos_error, ST_OACC_END_KERNELS);
742 matcha ("end loop", gfc_match_omp_eos_error, ST_OACC_END_LOOP);
743 matcha ("end parallel loop", gfc_match_omp_eos_error,
744 ST_OACC_END_PARALLEL_LOOP);
745 matcha ("end parallel", gfc_match_omp_eos_error, ST_OACC_END_PARALLEL);
746 matcha ("end serial loop", gfc_match_omp_eos_error,
747 ST_OACC_END_SERIAL_LOOP);
748 matcha ("end serial", gfc_match_omp_eos_error, ST_OACC_END_SERIAL);
749 matcha ("enter data", gfc_match_oacc_enter_data, ST_OACC_ENTER_DATA);
750 matcha ("exit data", gfc_match_oacc_exit_data, ST_OACC_EXIT_DATA);
751 break;
752 case 'h':
753 matcha ("host_data", gfc_match_oacc_host_data, ST_OACC_HOST_DATA);
754 break;
755 case 'p':
756 matcha ("parallel loop", gfc_match_oacc_parallel_loop,
757 ST_OACC_PARALLEL_LOOP);
758 matcha ("parallel", gfc_match_oacc_parallel, ST_OACC_PARALLEL);
759 break;
760 case 'k':
761 matcha ("kernels loop", gfc_match_oacc_kernels_loop,
762 ST_OACC_KERNELS_LOOP);
763 matcha ("kernels", gfc_match_oacc_kernels, ST_OACC_KERNELS);
764 break;
765 case 'l':
766 matcha ("loop", gfc_match_oacc_loop, ST_OACC_LOOP);
767 break;
768 case 's':
769 matcha ("serial loop", gfc_match_oacc_serial_loop, ST_OACC_SERIAL_LOOP);
770 matcha ("serial", gfc_match_oacc_serial, ST_OACC_SERIAL);
771 break;
772 case 'u':
773 matcha ("update", gfc_match_oacc_update, ST_OACC_UPDATE);
774 break;
775 case 'w':
776 matcha ("wait", gfc_match_oacc_wait, ST_OACC_WAIT);
777 break;
778 }
779
780 /* Directive not found or stored an error message.
781 Check and give up. */
782
783 error_handling:
784 if (gfc_error_check () == 0)
785 gfc_error_now ("Unclassifiable OpenACC directive at %C");
786
787 reject_statement ();
788
789 gfc_error_recovery ();
790
791 return ST_NONE;
792
793 do_spec_only:
794 reject_statement ();
795 gfc_clear_error ();
796 gfc_buffer_error (false);
797 gfc_current_locus = old_locus;
798 return ST_GET_FCN_CHARACTERISTICS;
799 }
800
801 /* Checks for the ST_OMP_ALLOCATE. First, check whether all list items
802 are allocatables/pointers - and if so, assume it is associated with a Fortran
803 ALLOCATE stmt. If not, do some initial parsing-related checks and append
804 namelist to namespace.
805 The check follows OpenMP 5.1 by requiring an executable stmt or OpenMP
806 construct before a directive associated with an allocate statement
807 (-> ST_OMP_ALLOCATE_EXEC); instead of showing an error, conversion of
808 ST_OMP_ALLOCATE -> ST_OMP_ALLOCATE_EXEC would be an alternative. */
809
810 bool
811 check_omp_allocate_stmt (locus *loc)
812 {
813 gfc_omp_namelist *n;
814
815 if (new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym == NULL)
816 {
817 gfc_error ("%qs directive at %L must either have a variable argument or, "
818 "if associated with an ALLOCATE stmt, must be preceded by an "
819 "executable statement or OpenMP construct",
820 gfc_ascii_statement (ST_OMP_ALLOCATE), loc);
821 return false;
822 }
823 bool has_allocatable = false;
824 bool has_non_allocatable = false;
825 for (n = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next)
826 {
827 if (n->expr)
828 {
829 gfc_error ("Structure-component expression at %L in %qs directive not"
830 " permitted in declarative directive; as directive "
831 "associated with an ALLOCATE stmt it must be preceded by "
832 "an executable statement or OpenMP construct",
833 &n->expr->where, gfc_ascii_statement (ST_OMP_ALLOCATE));
834 return false;
835 }
836 /* Procedure pointers are not allocatable; hence, we do not regard them as
837 pointers here - and reject them later in gfc_resolve_omp_allocate. */
838 bool alloc_ptr;
839 if (n->sym->ts.type == BT_CLASS && n->sym->attr.class_ok)
840 alloc_ptr = (CLASS_DATA (n->sym)->attr.allocatable
841 || CLASS_DATA (n->sym)->attr.class_pointer);
842 else
843 alloc_ptr = n->sym->attr.allocatable || n->sym->attr.pointer;
844 if (alloc_ptr
845 || (n->sym->ns && n->sym->ns->proc_name
846 && (n->sym->ns->proc_name->attr.allocatable
847 || n->sym->ns->proc_name->attr.pointer)))
848 has_allocatable = true;
849 else
850 has_non_allocatable = true;
851 }
852 /* All allocatables - assume it is allocated with an ALLOCATE stmt. */
853 if (has_allocatable && !has_non_allocatable)
854 {
855 gfc_error ("%qs directive at %L associated with an ALLOCATE stmt must be "
856 "preceded by an executable statement or OpenMP construct; "
857 "note the variables in the list all have the allocatable or "
858 "pointer attribute", gfc_ascii_statement (ST_OMP_ALLOCATE),
859 loc);
860 return false;
861 }
862 if (!gfc_current_ns->omp_allocate)
863 gfc_current_ns->omp_allocate
864 = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
865 else
866 {
867 for (n = gfc_current_ns->omp_allocate; n->next; n = n->next)
868 ;
869 n->next = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
870 }
871 new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = NULL;
872 gfc_free_omp_clauses (new_st.ext.omp_clauses);
873 return true;
874 }
875
876
877 /* Like match, but set a flag simd_matched if keyword matched
878 and if spec_only, goto do_spec_only without actually matching. */
879 #define matchs(keyword, subr, st) \
880 do { \
881 match m2; \
882 if (spec_only && gfc_match (keyword) == MATCH_YES) \
883 goto do_spec_only; \
884 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
885 &simd_matched)) == MATCH_YES) \
886 { \
887 ret = st; \
888 goto finish; \
889 } \
890 else if (m2 == MATCH_ERROR) \
891 goto error_handling; \
892 else \
893 undo_new_statement (); \
894 } while (0)
895
896 /* Like match, but don't match anything if not -fopenmp
897 and if spec_only, goto do_spec_only without actually matching. */
898 /* If the directive matched but the clauses failed, do not start
899 matching the next directive in the same switch statement. */
900 #define matcho(keyword, subr, st) \
901 do { \
902 match m2; \
903 if (!flag_openmp) \
904 ; \
905 else if (spec_only && gfc_match (keyword) == MATCH_YES) \
906 goto do_spec_only; \
907 else if ((m2 = match_word (keyword, subr, &old_locus)) \
908 == MATCH_YES) \
909 { \
910 ret = st; \
911 goto finish; \
912 } \
913 else if (m2 == MATCH_ERROR) \
914 goto error_handling; \
915 else \
916 undo_new_statement (); \
917 } while (0)
918
919 /* Like match, but set a flag simd_matched if keyword matched. */
920 #define matchds(keyword, subr, st) \
921 do { \
922 match m2; \
923 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
924 &simd_matched)) == MATCH_YES) \
925 { \
926 ret = st; \
927 goto finish; \
928 } \
929 else if (m2 == MATCH_ERROR) \
930 goto error_handling; \
931 else \
932 undo_new_statement (); \
933 } while (0)
934
935 /* Like match, but don't match anything if not -fopenmp. */
936 #define matchdo(keyword, subr, st) \
937 do { \
938 match m2; \
939 if (!flag_openmp) \
940 ; \
941 else if ((m2 = match_word (keyword, subr, &old_locus)) \
942 == MATCH_YES) \
943 { \
944 ret = st; \
945 goto finish; \
946 } \
947 else if (m2 == MATCH_ERROR) \
948 goto error_handling; \
949 else \
950 undo_new_statement (); \
951 } while (0)
952
953 static gfc_statement
954 decode_omp_directive (void)
955 {
956 locus old_locus;
957 char c;
958 bool simd_matched = false;
959 bool spec_only = false;
960 gfc_statement ret = ST_NONE;
961 bool pure_ok = true;
962
963 gfc_enforce_clean_symbol_state ();
964
965 gfc_clear_error (); /* Clear any pending errors. */
966 gfc_clear_warning (); /* Clear any pending warnings. */
967
968 gfc_matching_function = false;
969
970 if (gfc_current_state () == COMP_FUNCTION
971 && gfc_current_block ()->result->ts.kind == -1)
972 spec_only = true;
973
974 old_locus = gfc_current_locus;
975
976 /* General OpenMP directive matching: Instead of testing every possible
977 statement, we eliminate most possibilities by peeking at the
978 first character. */
979
980 c = gfc_peek_ascii_char ();
981
982 /* match is for directives that should be recognized only if
983 -fopenmp, matchs for directives that should be recognized
984 if either -fopenmp or -fopenmp-simd.
985 Handle only the directives allowed in PURE procedures
986 first (those also shall not turn off implicit pure). */
987 switch (c)
988 {
989 case 'a':
990 /* For -fopenmp-simd, ignore 'assumes'; note no clause starts with 's'. */
991 if (!flag_openmp && gfc_match ("assumes") == MATCH_YES)
992 break;
993 matcho ("assumes", gfc_match_omp_assumes, ST_OMP_ASSUMES);
994 matchs ("assume", gfc_match_omp_assume, ST_OMP_ASSUME);
995 break;
996 case 'd':
997 matchds ("declare reduction", gfc_match_omp_declare_reduction,
998 ST_OMP_DECLARE_REDUCTION);
999 matchds ("declare simd", gfc_match_omp_declare_simd,
1000 ST_OMP_DECLARE_SIMD);
1001 matchdo ("declare target", gfc_match_omp_declare_target,
1002 ST_OMP_DECLARE_TARGET);
1003 matchdo ("declare variant", gfc_match_omp_declare_variant,
1004 ST_OMP_DECLARE_VARIANT);
1005 break;
1006 case 'e':
1007 matchs ("end assume", gfc_match_omp_eos_error, ST_OMP_END_ASSUME);
1008 matchs ("end simd", gfc_match_omp_eos_error, ST_OMP_END_SIMD);
1009 matcho ("error", gfc_match_omp_error, ST_OMP_ERROR);
1010 break;
1011 case 's':
1012 matchs ("scan", gfc_match_omp_scan, ST_OMP_SCAN);
1013 matchs ("simd", gfc_match_omp_simd, ST_OMP_SIMD);
1014 break;
1015 case 'n':
1016 matcho ("nothing", gfc_match_omp_nothing, ST_NONE);
1017 break;
1018 }
1019
1020 pure_ok = false;
1021 if (flag_openmp && gfc_pure (NULL))
1022 {
1023 gfc_error_now ("OpenMP directive at %C is not pure and thus may not "
1024 "appear in a PURE procedure");
1025 gfc_error_recovery ();
1026 return ST_NONE;
1027 }
1028
1029 /* match is for directives that should be recognized only if
1030 -fopenmp, matchs for directives that should be recognized
1031 if either -fopenmp or -fopenmp-simd. */
1032 switch (c)
1033 {
1034 case 'a':
1035 if (in_exec_part)
1036 matcho ("allocate", gfc_match_omp_allocate, ST_OMP_ALLOCATE_EXEC);
1037 else
1038 matcho ("allocate", gfc_match_omp_allocate, ST_OMP_ALLOCATE);
1039 matcho ("allocators", gfc_match_omp_allocators, ST_OMP_ALLOCATORS);
1040 matcho ("atomic", gfc_match_omp_atomic, ST_OMP_ATOMIC);
1041 break;
1042 case 'b':
1043 matcho ("barrier", gfc_match_omp_barrier, ST_OMP_BARRIER);
1044 break;
1045 case 'c':
1046 matcho ("cancellation% point", gfc_match_omp_cancellation_point,
1047 ST_OMP_CANCELLATION_POINT);
1048 matcho ("cancel", gfc_match_omp_cancel, ST_OMP_CANCEL);
1049 matcho ("critical", gfc_match_omp_critical, ST_OMP_CRITICAL);
1050 break;
1051 case 'd':
1052 matcho ("depobj", gfc_match_omp_depobj, ST_OMP_DEPOBJ);
1053 matchs ("distribute parallel do simd",
1054 gfc_match_omp_distribute_parallel_do_simd,
1055 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD);
1056 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do,
1057 ST_OMP_DISTRIBUTE_PARALLEL_DO);
1058 matchs ("distribute simd", gfc_match_omp_distribute_simd,
1059 ST_OMP_DISTRIBUTE_SIMD);
1060 matcho ("distribute", gfc_match_omp_distribute, ST_OMP_DISTRIBUTE);
1061 matchs ("do simd", gfc_match_omp_do_simd, ST_OMP_DO_SIMD);
1062 matcho ("do", gfc_match_omp_do, ST_OMP_DO);
1063 break;
1064 case 'e':
1065 matcho ("end allocators", gfc_match_omp_eos_error, ST_OMP_END_ALLOCATORS);
1066 matcho ("end atomic", gfc_match_omp_eos_error, ST_OMP_END_ATOMIC);
1067 matcho ("end critical", gfc_match_omp_end_critical, ST_OMP_END_CRITICAL);
1068 matchs ("end distribute parallel do simd", gfc_match_omp_eos_error,
1069 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD);
1070 matcho ("end distribute parallel do", gfc_match_omp_eos_error,
1071 ST_OMP_END_DISTRIBUTE_PARALLEL_DO);
1072 matchs ("end distribute simd", gfc_match_omp_eos_error,
1073 ST_OMP_END_DISTRIBUTE_SIMD);
1074 matcho ("end distribute", gfc_match_omp_eos_error, ST_OMP_END_DISTRIBUTE);
1075 matchs ("end do simd", gfc_match_omp_end_nowait, ST_OMP_END_DO_SIMD);
1076 matcho ("end do", gfc_match_omp_end_nowait, ST_OMP_END_DO);
1077 matchs ("end loop", gfc_match_omp_eos_error, ST_OMP_END_LOOP);
1078 matcho ("end masked taskloop simd", gfc_match_omp_eos_error,
1079 ST_OMP_END_MASKED_TASKLOOP_SIMD);
1080 matcho ("end masked taskloop", gfc_match_omp_eos_error,
1081 ST_OMP_END_MASKED_TASKLOOP);
1082 matcho ("end masked", gfc_match_omp_eos_error, ST_OMP_END_MASKED);
1083 matcho ("end master taskloop simd", gfc_match_omp_eos_error,
1084 ST_OMP_END_MASTER_TASKLOOP_SIMD);
1085 matcho ("end master taskloop", gfc_match_omp_eos_error,
1086 ST_OMP_END_MASTER_TASKLOOP);
1087 matcho ("end master", gfc_match_omp_eos_error, ST_OMP_END_MASTER);
1088 matchs ("end ordered", gfc_match_omp_eos_error, ST_OMP_END_ORDERED);
1089 matchs ("end parallel do simd", gfc_match_omp_eos_error,
1090 ST_OMP_END_PARALLEL_DO_SIMD);
1091 matcho ("end parallel do", gfc_match_omp_eos_error,
1092 ST_OMP_END_PARALLEL_DO);
1093 matcho ("end parallel loop", gfc_match_omp_eos_error,
1094 ST_OMP_END_PARALLEL_LOOP);
1095 matcho ("end parallel masked taskloop simd", gfc_match_omp_eos_error,
1096 ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD);
1097 matcho ("end parallel masked taskloop", gfc_match_omp_eos_error,
1098 ST_OMP_END_PARALLEL_MASKED_TASKLOOP);
1099 matcho ("end parallel masked", gfc_match_omp_eos_error,
1100 ST_OMP_END_PARALLEL_MASKED);
1101 matcho ("end parallel master taskloop simd", gfc_match_omp_eos_error,
1102 ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD);
1103 matcho ("end parallel master taskloop", gfc_match_omp_eos_error,
1104 ST_OMP_END_PARALLEL_MASTER_TASKLOOP);
1105 matcho ("end parallel master", gfc_match_omp_eos_error,
1106 ST_OMP_END_PARALLEL_MASTER);
1107 matcho ("end parallel sections", gfc_match_omp_eos_error,
1108 ST_OMP_END_PARALLEL_SECTIONS);
1109 matcho ("end parallel workshare", gfc_match_omp_eos_error,
1110 ST_OMP_END_PARALLEL_WORKSHARE);
1111 matcho ("end parallel", gfc_match_omp_eos_error, ST_OMP_END_PARALLEL);
1112 matcho ("end scope", gfc_match_omp_end_nowait, ST_OMP_END_SCOPE);
1113 matcho ("end sections", gfc_match_omp_end_nowait, ST_OMP_END_SECTIONS);
1114 matcho ("end single", gfc_match_omp_end_single, ST_OMP_END_SINGLE);
1115 matcho ("end target data", gfc_match_omp_eos_error, ST_OMP_END_TARGET_DATA);
1116 matchs ("end target parallel do simd", gfc_match_omp_end_nowait,
1117 ST_OMP_END_TARGET_PARALLEL_DO_SIMD);
1118 matcho ("end target parallel do", gfc_match_omp_end_nowait,
1119 ST_OMP_END_TARGET_PARALLEL_DO);
1120 matcho ("end target parallel loop", gfc_match_omp_end_nowait,
1121 ST_OMP_END_TARGET_PARALLEL_LOOP);
1122 matcho ("end target parallel", gfc_match_omp_end_nowait,
1123 ST_OMP_END_TARGET_PARALLEL);
1124 matchs ("end target simd", gfc_match_omp_end_nowait, ST_OMP_END_TARGET_SIMD);
1125 matchs ("end target teams distribute parallel do simd",
1126 gfc_match_omp_end_nowait,
1127 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
1128 matcho ("end target teams distribute parallel do", gfc_match_omp_end_nowait,
1129 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO);
1130 matchs ("end target teams distribute simd", gfc_match_omp_end_nowait,
1131 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD);
1132 matcho ("end target teams distribute", gfc_match_omp_end_nowait,
1133 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE);
1134 matcho ("end target teams loop", gfc_match_omp_end_nowait,
1135 ST_OMP_END_TARGET_TEAMS_LOOP);
1136 matcho ("end target teams", gfc_match_omp_end_nowait,
1137 ST_OMP_END_TARGET_TEAMS);
1138 matcho ("end target", gfc_match_omp_end_nowait, ST_OMP_END_TARGET);
1139 matcho ("end taskgroup", gfc_match_omp_eos_error, ST_OMP_END_TASKGROUP);
1140 matchs ("end taskloop simd", gfc_match_omp_eos_error,
1141 ST_OMP_END_TASKLOOP_SIMD);
1142 matcho ("end taskloop", gfc_match_omp_eos_error, ST_OMP_END_TASKLOOP);
1143 matcho ("end task", gfc_match_omp_eos_error, ST_OMP_END_TASK);
1144 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos_error,
1145 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
1146 matcho ("end teams distribute parallel do", gfc_match_omp_eos_error,
1147 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO);
1148 matchs ("end teams distribute simd", gfc_match_omp_eos_error,
1149 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD);
1150 matcho ("end teams distribute", gfc_match_omp_eos_error,
1151 ST_OMP_END_TEAMS_DISTRIBUTE);
1152 matcho ("end teams loop", gfc_match_omp_eos_error, ST_OMP_END_TEAMS_LOOP);
1153 matcho ("end teams", gfc_match_omp_eos_error, ST_OMP_END_TEAMS);
1154 matcho ("end workshare", gfc_match_omp_end_nowait,
1155 ST_OMP_END_WORKSHARE);
1156 break;
1157 case 'f':
1158 matcho ("flush", gfc_match_omp_flush, ST_OMP_FLUSH);
1159 break;
1160 case 'm':
1161 matcho ("masked taskloop simd", gfc_match_omp_masked_taskloop_simd,
1162 ST_OMP_MASKED_TASKLOOP_SIMD);
1163 matcho ("masked taskloop", gfc_match_omp_masked_taskloop,
1164 ST_OMP_MASKED_TASKLOOP);
1165 matcho ("masked", gfc_match_omp_masked, ST_OMP_MASKED);
1166 matcho ("master taskloop simd", gfc_match_omp_master_taskloop_simd,
1167 ST_OMP_MASTER_TASKLOOP_SIMD);
1168 matcho ("master taskloop", gfc_match_omp_master_taskloop,
1169 ST_OMP_MASTER_TASKLOOP);
1170 matcho ("master", gfc_match_omp_master, ST_OMP_MASTER);
1171 break;
1172 case 'n':
1173 matcho ("nothing", gfc_match_omp_nothing, ST_NONE);
1174 break;
1175 case 'l':
1176 matchs ("loop", gfc_match_omp_loop, ST_OMP_LOOP);
1177 break;
1178 case 'o':
1179 if (gfc_match ("ordered depend (") == MATCH_YES
1180 || gfc_match ("ordered doacross (") == MATCH_YES)
1181 {
1182 gfc_current_locus = old_locus;
1183 if (!flag_openmp)
1184 break;
1185 matcho ("ordered", gfc_match_omp_ordered_depend,
1186 ST_OMP_ORDERED_DEPEND);
1187 }
1188 else
1189 matchs ("ordered", gfc_match_omp_ordered, ST_OMP_ORDERED);
1190 break;
1191 case 'p':
1192 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd,
1193 ST_OMP_PARALLEL_DO_SIMD);
1194 matcho ("parallel do", gfc_match_omp_parallel_do, ST_OMP_PARALLEL_DO);
1195 matcho ("parallel loop", gfc_match_omp_parallel_loop,
1196 ST_OMP_PARALLEL_LOOP);
1197 matcho ("parallel masked taskloop simd",
1198 gfc_match_omp_parallel_masked_taskloop_simd,
1199 ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD);
1200 matcho ("parallel masked taskloop",
1201 gfc_match_omp_parallel_masked_taskloop,
1202 ST_OMP_PARALLEL_MASKED_TASKLOOP);
1203 matcho ("parallel masked", gfc_match_omp_parallel_masked,
1204 ST_OMP_PARALLEL_MASKED);
1205 matcho ("parallel master taskloop simd",
1206 gfc_match_omp_parallel_master_taskloop_simd,
1207 ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD);
1208 matcho ("parallel master taskloop",
1209 gfc_match_omp_parallel_master_taskloop,
1210 ST_OMP_PARALLEL_MASTER_TASKLOOP);
1211 matcho ("parallel master", gfc_match_omp_parallel_master,
1212 ST_OMP_PARALLEL_MASTER);
1213 matcho ("parallel sections", gfc_match_omp_parallel_sections,
1214 ST_OMP_PARALLEL_SECTIONS);
1215 matcho ("parallel workshare", gfc_match_omp_parallel_workshare,
1216 ST_OMP_PARALLEL_WORKSHARE);
1217 matcho ("parallel", gfc_match_omp_parallel, ST_OMP_PARALLEL);
1218 break;
1219 case 'r':
1220 matcho ("requires", gfc_match_omp_requires, ST_OMP_REQUIRES);
1221 break;
1222 case 's':
1223 matcho ("scope", gfc_match_omp_scope, ST_OMP_SCOPE);
1224 matcho ("sections", gfc_match_omp_sections, ST_OMP_SECTIONS);
1225 matcho ("section", gfc_match_omp_eos_error, ST_OMP_SECTION);
1226 matcho ("single", gfc_match_omp_single, ST_OMP_SINGLE);
1227 break;
1228 case 't':
1229 matcho ("target data", gfc_match_omp_target_data, ST_OMP_TARGET_DATA);
1230 matcho ("target enter data", gfc_match_omp_target_enter_data,
1231 ST_OMP_TARGET_ENTER_DATA);
1232 matcho ("target exit data", gfc_match_omp_target_exit_data,
1233 ST_OMP_TARGET_EXIT_DATA);
1234 matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd,
1235 ST_OMP_TARGET_PARALLEL_DO_SIMD);
1236 matcho ("target parallel do", gfc_match_omp_target_parallel_do,
1237 ST_OMP_TARGET_PARALLEL_DO);
1238 matcho ("target parallel loop", gfc_match_omp_target_parallel_loop,
1239 ST_OMP_TARGET_PARALLEL_LOOP);
1240 matcho ("target parallel", gfc_match_omp_target_parallel,
1241 ST_OMP_TARGET_PARALLEL);
1242 matchs ("target simd", gfc_match_omp_target_simd, ST_OMP_TARGET_SIMD);
1243 matchs ("target teams distribute parallel do simd",
1244 gfc_match_omp_target_teams_distribute_parallel_do_simd,
1245 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
1246 matcho ("target teams distribute parallel do",
1247 gfc_match_omp_target_teams_distribute_parallel_do,
1248 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO);
1249 matchs ("target teams distribute simd",
1250 gfc_match_omp_target_teams_distribute_simd,
1251 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD);
1252 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute,
1253 ST_OMP_TARGET_TEAMS_DISTRIBUTE);
1254 matcho ("target teams loop", gfc_match_omp_target_teams_loop,
1255 ST_OMP_TARGET_TEAMS_LOOP);
1256 matcho ("target teams", gfc_match_omp_target_teams, ST_OMP_TARGET_TEAMS);
1257 matcho ("target update", gfc_match_omp_target_update,
1258 ST_OMP_TARGET_UPDATE);
1259 matcho ("target", gfc_match_omp_target, ST_OMP_TARGET);
1260 matcho ("taskgroup", gfc_match_omp_taskgroup, ST_OMP_TASKGROUP);
1261 matchs ("taskloop simd", gfc_match_omp_taskloop_simd,
1262 ST_OMP_TASKLOOP_SIMD);
1263 matcho ("taskloop", gfc_match_omp_taskloop, ST_OMP_TASKLOOP);
1264 matcho ("taskwait", gfc_match_omp_taskwait, ST_OMP_TASKWAIT);
1265 matcho ("taskyield", gfc_match_omp_taskyield, ST_OMP_TASKYIELD);
1266 matcho ("task", gfc_match_omp_task, ST_OMP_TASK);
1267 matchs ("teams distribute parallel do simd",
1268 gfc_match_omp_teams_distribute_parallel_do_simd,
1269 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
1270 matcho ("teams distribute parallel do",
1271 gfc_match_omp_teams_distribute_parallel_do,
1272 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO);
1273 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd,
1274 ST_OMP_TEAMS_DISTRIBUTE_SIMD);
1275 matcho ("teams distribute", gfc_match_omp_teams_distribute,
1276 ST_OMP_TEAMS_DISTRIBUTE);
1277 matcho ("teams loop", gfc_match_omp_teams_loop, ST_OMP_TEAMS_LOOP);
1278 matcho ("teams", gfc_match_omp_teams, ST_OMP_TEAMS);
1279 matchdo ("threadprivate", gfc_match_omp_threadprivate,
1280 ST_OMP_THREADPRIVATE);
1281 break;
1282 case 'w':
1283 matcho ("workshare", gfc_match_omp_workshare, ST_OMP_WORKSHARE);
1284 break;
1285 }
1286
1287 /* All else has failed, so give up. See if any of the matchers has
1288 stored an error message of some sort. Don't error out if
1289 not -fopenmp and simd_matched is false, i.e. if a directive other
1290 than one marked with match has been seen. */
1291
1292 error_handling:
1293 if (flag_openmp || simd_matched)
1294 {
1295 if (!gfc_error_check ())
1296 gfc_error_now ("Unclassifiable OpenMP directive at %C");
1297 }
1298
1299 reject_statement ();
1300
1301 gfc_error_recovery ();
1302
1303 return ST_NONE;
1304
1305 finish:
1306 if (ret == ST_OMP_ERROR && new_st.ext.omp_clauses->at == OMP_AT_EXECUTION)
1307 {
1308 gfc_unset_implicit_pure (NULL);
1309
1310 if (gfc_pure (NULL))
1311 {
1312 gfc_error_now ("OpenMP ERROR directive at %L with %<at(execution)%> "
1313 "clause in a PURE procedure", &old_locus);
1314 reject_statement ();
1315 gfc_error_recovery ();
1316 return ST_NONE;
1317 }
1318 }
1319 if (!pure_ok)
1320 {
1321 gfc_unset_implicit_pure (NULL);
1322
1323 if (!flag_openmp && gfc_pure (NULL))
1324 {
1325 gfc_error_now ("OpenMP directive at %C is not pure and thus may not "
1326 "appear in a PURE procedure");
1327 reject_statement ();
1328 gfc_error_recovery ();
1329 return ST_NONE;
1330 }
1331 }
1332 if (ret == ST_OMP_ALLOCATE && !check_omp_allocate_stmt (&old_locus))
1333 goto error_handling;
1334
1335 switch (ret)
1336 {
1337 /* Set omp_target_seen; exclude ST_OMP_DECLARE_TARGET.
1338 FIXME: Get clarification, cf. OpenMP Spec Issue #3240. */
1339 case ST_OMP_TARGET:
1340 case ST_OMP_TARGET_DATA:
1341 case ST_OMP_TARGET_ENTER_DATA:
1342 case ST_OMP_TARGET_EXIT_DATA:
1343 case ST_OMP_TARGET_TEAMS:
1344 case ST_OMP_TARGET_TEAMS_DISTRIBUTE:
1345 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
1346 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
1347 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
1348 case ST_OMP_TARGET_TEAMS_LOOP:
1349 case ST_OMP_TARGET_PARALLEL:
1350 case ST_OMP_TARGET_PARALLEL_DO:
1351 case ST_OMP_TARGET_PARALLEL_DO_SIMD:
1352 case ST_OMP_TARGET_PARALLEL_LOOP:
1353 case ST_OMP_TARGET_SIMD:
1354 case ST_OMP_TARGET_UPDATE:
1355 {
1356 gfc_namespace *prog_unit = gfc_current_ns;
1357 while (prog_unit->parent)
1358 {
1359 if (gfc_state_stack->previous
1360 && gfc_state_stack->previous->state == COMP_INTERFACE)
1361 break;
1362 prog_unit = prog_unit->parent;
1363 }
1364 prog_unit->omp_target_seen = true;
1365 break;
1366 }
1367 case ST_OMP_ALLOCATE_EXEC:
1368 case ST_OMP_ALLOCATORS:
1369 case ST_OMP_TEAMS:
1370 case ST_OMP_TEAMS_DISTRIBUTE:
1371 case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
1372 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
1373 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
1374 case ST_OMP_TEAMS_LOOP:
1375 for (gfc_state_data *stk = gfc_state_stack->previous; stk;
1376 stk = stk->previous)
1377 if (stk && stk->tail)
1378 switch (stk->tail->op)
1379 {
1380 case EXEC_OMP_TARGET:
1381 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
1382 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
1383 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
1384 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
1385 case EXEC_OMP_TARGET_TEAMS_LOOP:
1386 case EXEC_OMP_TARGET_PARALLEL:
1387 case EXEC_OMP_TARGET_PARALLEL_DO:
1388 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
1389 case EXEC_OMP_TARGET_PARALLEL_LOOP:
1390 case EXEC_OMP_TARGET_SIMD:
1391 if (ret == ST_OMP_ALLOCATE_EXEC || ret == ST_OMP_ALLOCATORS)
1392 new_st.ext.omp_clauses->contained_in_target_construct = 1;
1393 else
1394 stk->tail->ext.omp_clauses->contains_teams_construct = 1;
1395 break;
1396 default:
1397 break;
1398 }
1399 break;
1400 case ST_OMP_ERROR:
1401 if (new_st.ext.omp_clauses->at != OMP_AT_EXECUTION)
1402 return ST_NONE;
1403 default:
1404 break;
1405 }
1406 return ret;
1407
1408 do_spec_only:
1409 reject_statement ();
1410 gfc_clear_error ();
1411 gfc_buffer_error (false);
1412 gfc_current_locus = old_locus;
1413 return ST_GET_FCN_CHARACTERISTICS;
1414 }
1415
1416 static gfc_statement
1417 decode_gcc_attribute (void)
1418 {
1419 locus old_locus;
1420
1421 gfc_enforce_clean_symbol_state ();
1422
1423 gfc_clear_error (); /* Clear any pending errors. */
1424 gfc_clear_warning (); /* Clear any pending warnings. */
1425 old_locus = gfc_current_locus;
1426
1427 match ("attributes", gfc_match_gcc_attributes, ST_ATTR_DECL);
1428 match ("unroll", gfc_match_gcc_unroll, ST_NONE);
1429 match ("builtin", gfc_match_gcc_builtin, ST_NONE);
1430 match ("ivdep", gfc_match_gcc_ivdep, ST_NONE);
1431 match ("vector", gfc_match_gcc_vector, ST_NONE);
1432 match ("novector", gfc_match_gcc_novector, ST_NONE);
1433
1434 /* All else has failed, so give up. See if any of the matchers has
1435 stored an error message of some sort. */
1436
1437 if (!gfc_error_check ())
1438 {
1439 if (pedantic)
1440 gfc_error_now ("Unclassifiable GCC directive at %C");
1441 else
1442 gfc_warning_now (0, "Unclassifiable GCC directive at %C, ignored");
1443 }
1444
1445 reject_statement ();
1446
1447 gfc_error_recovery ();
1448
1449 return ST_NONE;
1450 }
1451
1452 #undef match
1453
1454 /* Assert next length characters to be equal to token in free form. */
1455
1456 static void
1457 verify_token_free (const char* token, int length, bool last_was_use_stmt)
1458 {
1459 int i;
1460 char c;
1461
1462 c = gfc_next_ascii_char ();
1463 for (i = 0; i < length; i++, c = gfc_next_ascii_char ())
1464 gcc_assert (c == token[i]);
1465
1466 gcc_assert (gfc_is_whitespace(c));
1467 gfc_gobble_whitespace ();
1468 if (last_was_use_stmt)
1469 use_modules ();
1470 }
1471
1472 /* Get the next statement in free form source. */
1473
1474 static gfc_statement
1475 next_free (void)
1476 {
1477 match m;
1478 int i, cnt, at_bol;
1479 char c;
1480
1481 at_bol = gfc_at_bol ();
1482 gfc_gobble_whitespace ();
1483
1484 c = gfc_peek_ascii_char ();
1485
1486 if (ISDIGIT (c))
1487 {
1488 char d;
1489
1490 /* Found a statement label? */
1491 m = gfc_match_st_label (&gfc_statement_label);
1492
1493 d = gfc_peek_ascii_char ();
1494 if (m != MATCH_YES || !gfc_is_whitespace (d))
1495 {
1496 gfc_match_small_literal_int (&i, &cnt);
1497
1498 if (cnt > 5)
1499 gfc_error_now ("Too many digits in statement label at %C");
1500
1501 if (i == 0)
1502 gfc_error_now ("Zero is not a valid statement label at %C");
1503
1504 do
1505 c = gfc_next_ascii_char ();
1506 while (ISDIGIT(c));
1507
1508 if (!gfc_is_whitespace (c))
1509 gfc_error_now ("Non-numeric character in statement label at %C");
1510
1511 return ST_NONE;
1512 }
1513 else
1514 {
1515 label_locus = gfc_current_locus;
1516
1517 gfc_gobble_whitespace ();
1518
1519 if (at_bol && gfc_peek_ascii_char () == ';')
1520 {
1521 gfc_error_now ("Semicolon at %C needs to be preceded by "
1522 "statement");
1523 gfc_next_ascii_char (); /* Eat up the semicolon. */
1524 return ST_NONE;
1525 }
1526
1527 if (gfc_match_eos () == MATCH_YES)
1528 gfc_error_now ("Statement label without statement at %L",
1529 &label_locus);
1530 }
1531 }
1532 else if (c == '!')
1533 {
1534 /* Comments have already been skipped by the time we get here,
1535 except for GCC attributes and OpenMP/OpenACC directives. */
1536
1537 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1538 c = gfc_peek_ascii_char ();
1539
1540 if (c == 'g')
1541 {
1542 int i;
1543
1544 c = gfc_next_ascii_char ();
1545 for (i = 0; i < 4; i++, c = gfc_next_ascii_char ())
1546 gcc_assert (c == "gcc$"[i]);
1547
1548 gfc_gobble_whitespace ();
1549 return decode_gcc_attribute ();
1550
1551 }
1552 else if (c == '$')
1553 {
1554 /* Since both OpenMP and OpenACC directives starts with
1555 !$ character sequence, we must check all flags combinations */
1556 if ((flag_openmp || flag_openmp_simd)
1557 && !flag_openacc)
1558 {
1559 verify_token_free ("$omp", 4, last_was_use_stmt);
1560 return decode_omp_directive ();
1561 }
1562 else if ((flag_openmp || flag_openmp_simd)
1563 && flag_openacc)
1564 {
1565 gfc_next_ascii_char (); /* Eat up dollar character */
1566 c = gfc_peek_ascii_char ();
1567
1568 if (c == 'o')
1569 {
1570 verify_token_free ("omp", 3, last_was_use_stmt);
1571 return decode_omp_directive ();
1572 }
1573 else if (c == 'a')
1574 {
1575 verify_token_free ("acc", 3, last_was_use_stmt);
1576 return decode_oacc_directive ();
1577 }
1578 }
1579 else if (flag_openacc)
1580 {
1581 verify_token_free ("$acc", 4, last_was_use_stmt);
1582 return decode_oacc_directive ();
1583 }
1584 }
1585 gcc_unreachable ();
1586 }
1587
1588 if (at_bol && c == ';')
1589 {
1590 if (!(gfc_option.allow_std & GFC_STD_F2008))
1591 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1592 "statement");
1593 gfc_next_ascii_char (); /* Eat up the semicolon. */
1594 return ST_NONE;
1595 }
1596
1597 return decode_statement ();
1598 }
1599
1600 /* Assert next length characters to be equal to token in fixed form. */
1601
1602 static bool
1603 verify_token_fixed (const char *token, int length, bool last_was_use_stmt)
1604 {
1605 int i;
1606 char c = gfc_next_char_literal (NONSTRING);
1607
1608 for (i = 0; i < length; i++, c = gfc_next_char_literal (NONSTRING))
1609 gcc_assert ((char) gfc_wide_tolower (c) == token[i]);
1610
1611 if (c != ' ' && c != '0')
1612 {
1613 gfc_buffer_error (false);
1614 gfc_error ("Bad continuation line at %C");
1615 return false;
1616 }
1617 if (last_was_use_stmt)
1618 use_modules ();
1619
1620 return true;
1621 }
1622
1623 /* Get the next statement in fixed-form source. */
1624
1625 static gfc_statement
1626 next_fixed (void)
1627 {
1628 int label, digit_flag, i;
1629 locus loc;
1630 gfc_char_t c;
1631
1632 if (!gfc_at_bol ())
1633 return decode_statement ();
1634
1635 /* Skip past the current label field, parsing a statement label if
1636 one is there. This is a weird number parser, since the number is
1637 contained within five columns and can have any kind of embedded
1638 spaces. We also check for characters that make the rest of the
1639 line a comment. */
1640
1641 label = 0;
1642 digit_flag = 0;
1643
1644 for (i = 0; i < 5; i++)
1645 {
1646 c = gfc_next_char_literal (NONSTRING);
1647
1648 switch (c)
1649 {
1650 case ' ':
1651 break;
1652
1653 case '0':
1654 case '1':
1655 case '2':
1656 case '3':
1657 case '4':
1658 case '5':
1659 case '6':
1660 case '7':
1661 case '8':
1662 case '9':
1663 label = label * 10 + ((unsigned char) c - '0');
1664 label_locus = gfc_current_locus;
1665 digit_flag = 1;
1666 break;
1667
1668 /* Comments have already been skipped by the time we get
1669 here, except for GCC attributes and OpenMP directives. */
1670
1671 case '*':
1672 c = gfc_next_char_literal (NONSTRING);
1673
1674 if (TOLOWER (c) == 'g')
1675 {
1676 for (i = 0; i < 4; i++, c = gfc_next_char_literal (NONSTRING))
1677 gcc_assert (TOLOWER (c) == "gcc$"[i]);
1678
1679 return decode_gcc_attribute ();
1680 }
1681 else if (c == '$')
1682 {
1683 if ((flag_openmp || flag_openmp_simd)
1684 && !flag_openacc)
1685 {
1686 if (!verify_token_fixed ("omp", 3, last_was_use_stmt))
1687 return ST_NONE;
1688 return decode_omp_directive ();
1689 }
1690 else if ((flag_openmp || flag_openmp_simd)
1691 && flag_openacc)
1692 {
1693 c = gfc_next_char_literal(NONSTRING);
1694 if (c == 'o' || c == 'O')
1695 {
1696 if (!verify_token_fixed ("mp", 2, last_was_use_stmt))
1697 return ST_NONE;
1698 return decode_omp_directive ();
1699 }
1700 else if (c == 'a' || c == 'A')
1701 {
1702 if (!verify_token_fixed ("cc", 2, last_was_use_stmt))
1703 return ST_NONE;
1704 return decode_oacc_directive ();
1705 }
1706 }
1707 else if (flag_openacc)
1708 {
1709 if (!verify_token_fixed ("acc", 3, last_was_use_stmt))
1710 return ST_NONE;
1711 return decode_oacc_directive ();
1712 }
1713 }
1714 gcc_fallthrough ();
1715
1716 /* Comments have already been skipped by the time we get
1717 here so don't bother checking for them. */
1718
1719 default:
1720 gfc_buffer_error (false);
1721 gfc_error ("Non-numeric character in statement label at %C");
1722 return ST_NONE;
1723 }
1724 }
1725
1726 if (digit_flag)
1727 {
1728 if (label == 0)
1729 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1730 else
1731 {
1732 /* We've found a valid statement label. */
1733 gfc_statement_label = gfc_get_st_label (label);
1734 }
1735 }
1736
1737 /* Since this line starts a statement, it cannot be a continuation
1738 of a previous statement. If we see something here besides a
1739 space or zero, it must be a bad continuation line. */
1740
1741 c = gfc_next_char_literal (NONSTRING);
1742 if (c == '\n')
1743 goto blank_line;
1744
1745 if (c != ' ' && c != '0')
1746 {
1747 gfc_buffer_error (false);
1748 gfc_error ("Bad continuation line at %C");
1749 return ST_NONE;
1750 }
1751
1752 /* Now that we've taken care of the statement label columns, we have
1753 to make sure that the first nonblank character is not a '!'. If
1754 it is, the rest of the line is a comment. */
1755
1756 do
1757 {
1758 loc = gfc_current_locus;
1759 c = gfc_next_char_literal (NONSTRING);
1760 }
1761 while (gfc_is_whitespace (c));
1762
1763 if (c == '!')
1764 goto blank_line;
1765 gfc_current_locus = loc;
1766
1767 if (c == ';')
1768 {
1769 if (digit_flag)
1770 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1771 else if (!(gfc_option.allow_std & GFC_STD_F2008))
1772 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1773 "statement");
1774 return ST_NONE;
1775 }
1776
1777 if (gfc_match_eos () == MATCH_YES)
1778 goto blank_line;
1779
1780 /* At this point, we've got a nonblank statement to parse. */
1781 return decode_statement ();
1782
1783 blank_line:
1784 if (digit_flag)
1785 gfc_error_now ("Statement label without statement at %L", &label_locus);
1786
1787 gfc_current_locus.lb->truncated = 0;
1788 gfc_advance_line ();
1789 return ST_NONE;
1790 }
1791
1792
1793 /* Return the next non-ST_NONE statement to the caller. We also worry
1794 about including files and the ends of include files at this stage. */
1795
1796 static gfc_statement
1797 next_statement (void)
1798 {
1799 gfc_statement st;
1800 locus old_locus;
1801
1802 gfc_enforce_clean_symbol_state ();
1803
1804 gfc_new_block = NULL;
1805
1806 gfc_current_ns->old_equiv = gfc_current_ns->equiv;
1807 gfc_current_ns->old_data = gfc_current_ns->data;
1808 for (;;)
1809 {
1810 gfc_statement_label = NULL;
1811 gfc_buffer_error (true);
1812
1813 if (gfc_at_eol ())
1814 gfc_advance_line ();
1815
1816 gfc_skip_comments ();
1817
1818 if (gfc_at_end ())
1819 {
1820 st = ST_NONE;
1821 break;
1822 }
1823
1824 if (gfc_define_undef_line ())
1825 continue;
1826
1827 old_locus = gfc_current_locus;
1828
1829 st = (gfc_current_form == FORM_FIXED) ? next_fixed () : next_free ();
1830
1831 if (st != ST_NONE)
1832 break;
1833 }
1834
1835 gfc_buffer_error (false);
1836
1837 if (st == ST_GET_FCN_CHARACTERISTICS)
1838 {
1839 if (gfc_statement_label != NULL)
1840 {
1841 gfc_free_st_label (gfc_statement_label);
1842 gfc_statement_label = NULL;
1843 }
1844 gfc_current_locus = old_locus;
1845 }
1846
1847 if (st != ST_NONE)
1848 check_statement_label (st);
1849
1850 return st;
1851 }
1852
1853
1854 /****************************** Parser ***********************************/
1855
1856 /* The parser subroutines are of type 'try' that fail if the file ends
1857 unexpectedly. */
1858
1859 /* Macros that expand to case-labels for various classes of
1860 statements. Start with executable statements that directly do
1861 things. */
1862
1863 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1864 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1865 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1866 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1867 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1868 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1869 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1870 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1871 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1872 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: case ST_OMP_DEPOBJ: \
1873 case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
1874 case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: case ST_OMP_ERROR: \
1875 case ST_ERROR_STOP: case ST_OMP_SCAN: case ST_SYNC_ALL: \
1876 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1877 case ST_FORM_TEAM: case ST_CHANGE_TEAM: \
1878 case ST_END_TEAM: case ST_SYNC_TEAM: \
1879 case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \
1880 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1881 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1882
1883 /* Statements that mark other executable statements. */
1884
1885 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1886 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1887 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1888 case ST_SELECT_RANK: case ST_OMP_PARALLEL: case ST_OMP_PARALLEL_MASKED: \
1889 case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
1890 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case ST_OMP_PARALLEL_MASTER: \
1891 case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
1892 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
1893 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1894 case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASKED_TASKLOOP: \
1895 case ST_OMP_MASKED_TASKLOOP_SIMD: \
1896 case ST_OMP_MASTER: case ST_OMP_MASTER_TASKLOOP: \
1897 case ST_OMP_MASTER_TASKLOOP_SIMD: case ST_OMP_SCOPE: case ST_OMP_SINGLE: \
1898 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1899 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1900 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1901 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1902 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1903 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1904 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1905 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1906 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1907 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1908 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1909 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1910 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1911 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1912 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
1913 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
1914 case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
1915 case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \
1916 case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \
1917 case ST_OMP_ALLOCATE_EXEC: case ST_OMP_ALLOCATORS: case ST_OMP_ASSUME: \
1918 case ST_CRITICAL: \
1919 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1920 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1921 case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \
1922 case ST_OACC_ATOMIC
1923
1924 /* Declaration statements */
1925
1926 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1927 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1928 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE
1929
1930 /* OpenMP and OpenACC declaration statements, which may appear anywhere in
1931 the specification part. */
1932
1933 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1934 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \
1935 case ST_OMP_DECLARE_VARIANT: case ST_OMP_ALLOCATE: case ST_OMP_ASSUMES: \
1936 case ST_OMP_REQUIRES: case ST_OACC_ROUTINE: case ST_OACC_DECLARE
1937
1938 /* Block end statements. Errors associated with interchanging these
1939 are detected in gfc_match_end(). */
1940
1941 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1942 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1943 case ST_END_BLOCK: case ST_END_ASSOCIATE
1944
1945
1946 /* Push a new state onto the stack. */
1947
1948 static void
1949 push_state (gfc_state_data *p, gfc_compile_state new_state, gfc_symbol *sym)
1950 {
1951 p->state = new_state;
1952 p->previous = gfc_state_stack;
1953 p->sym = sym;
1954 p->head = p->tail = NULL;
1955 p->do_variable = NULL;
1956 if (p->state != COMP_DO && p->state != COMP_DO_CONCURRENT)
1957 p->ext.oacc_declare_clauses = NULL;
1958
1959 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1960 construct statement was accepted right before pushing the state. Thus,
1961 the construct's gfc_code is available as tail of the parent state. */
1962 gcc_assert (gfc_state_stack);
1963 p->construct = gfc_state_stack->tail;
1964
1965 gfc_state_stack = p;
1966 }
1967
1968
1969 /* Pop the current state. */
1970 static void
1971 pop_state (void)
1972 {
1973 gfc_state_stack = gfc_state_stack->previous;
1974 }
1975
1976
1977 /* Try to find the given state in the state stack. */
1978
1979 bool
1980 gfc_find_state (gfc_compile_state state)
1981 {
1982 gfc_state_data *p;
1983
1984 for (p = gfc_state_stack; p; p = p->previous)
1985 if (p->state == state)
1986 break;
1987
1988 return (p == NULL) ? false : true;
1989 }
1990
1991
1992 /* Starts a new level in the statement list. */
1993
1994 static gfc_code *
1995 new_level (gfc_code *q)
1996 {
1997 gfc_code *p;
1998
1999 p = q->block = gfc_get_code (EXEC_NOP);
2000
2001 gfc_state_stack->head = gfc_state_stack->tail = p;
2002
2003 return p;
2004 }
2005
2006
2007 /* Add the current new_st code structure and adds it to the current
2008 program unit. As a side-effect, it zeroes the new_st. */
2009
2010 static gfc_code *
2011 add_statement (void)
2012 {
2013 gfc_code *p;
2014
2015 p = XCNEW (gfc_code);
2016 *p = new_st;
2017
2018 p->loc = gfc_current_locus;
2019
2020 if (gfc_state_stack->head == NULL)
2021 gfc_state_stack->head = p;
2022 else
2023 gfc_state_stack->tail->next = p;
2024
2025 while (p->next != NULL)
2026 p = p->next;
2027
2028 gfc_state_stack->tail = p;
2029
2030 gfc_clear_new_st ();
2031
2032 return p;
2033 }
2034
2035
2036 /* Frees everything associated with the current statement. */
2037
2038 static void
2039 undo_new_statement (void)
2040 {
2041 gfc_free_statements (new_st.block);
2042 gfc_free_statements (new_st.next);
2043 gfc_free_statement (&new_st);
2044 gfc_clear_new_st ();
2045 }
2046
2047
2048 /* If the current statement has a statement label, make sure that it
2049 is allowed to, or should have one. */
2050
2051 static void
2052 check_statement_label (gfc_statement st)
2053 {
2054 gfc_sl_type type;
2055
2056 if (gfc_statement_label == NULL)
2057 {
2058 if (st == ST_FORMAT)
2059 gfc_error ("FORMAT statement at %L does not have a statement label",
2060 &new_st.loc);
2061 return;
2062 }
2063
2064 switch (st)
2065 {
2066 case ST_END_PROGRAM:
2067 case ST_END_FUNCTION:
2068 case ST_END_SUBROUTINE:
2069 case ST_ENDDO:
2070 case ST_ENDIF:
2071 case ST_END_SELECT:
2072 case ST_END_CRITICAL:
2073 case ST_END_BLOCK:
2074 case ST_END_ASSOCIATE:
2075 case_executable:
2076 case_exec_markers:
2077 if (st == ST_ENDDO || st == ST_CONTINUE)
2078 type = ST_LABEL_DO_TARGET;
2079 else
2080 type = ST_LABEL_TARGET;
2081 break;
2082
2083 case ST_FORMAT:
2084 type = ST_LABEL_FORMAT;
2085 break;
2086
2087 /* Statement labels are not restricted from appearing on a
2088 particular line. However, there are plenty of situations
2089 where the resulting label can't be referenced. */
2090
2091 default:
2092 type = ST_LABEL_BAD_TARGET;
2093 break;
2094 }
2095
2096 gfc_define_st_label (gfc_statement_label, type, &label_locus);
2097
2098 new_st.here = gfc_statement_label;
2099 }
2100
2101
2102 /* Figures out what the enclosing program unit is. This will be a
2103 function, subroutine, program, block data or module. */
2104
2105 gfc_state_data *
2106 gfc_enclosing_unit (gfc_compile_state * result)
2107 {
2108 gfc_state_data *p;
2109
2110 for (p = gfc_state_stack; p; p = p->previous)
2111 if (p->state == COMP_FUNCTION || p->state == COMP_SUBROUTINE
2112 || p->state == COMP_MODULE || p->state == COMP_SUBMODULE
2113 || p->state == COMP_BLOCK_DATA || p->state == COMP_PROGRAM)
2114 {
2115
2116 if (result != NULL)
2117 *result = p->state;
2118 return p;
2119 }
2120
2121 if (result != NULL)
2122 *result = COMP_PROGRAM;
2123 return NULL;
2124 }
2125
2126
2127 /* Translate a statement enum to a string. If strip_sentinel is true,
2128 the !$OMP/!$ACC sentinel is excluded. */
2129
2130 const char *
2131 gfc_ascii_statement (gfc_statement st, bool strip_sentinel)
2132 {
2133 const char *p;
2134
2135 switch (st)
2136 {
2137 case ST_ARITHMETIC_IF:
2138 p = _("arithmetic IF");
2139 break;
2140 case ST_ALLOCATE:
2141 p = "ALLOCATE";
2142 break;
2143 case ST_ASSOCIATE:
2144 p = "ASSOCIATE";
2145 break;
2146 case ST_ATTR_DECL:
2147 p = _("attribute declaration");
2148 break;
2149 case ST_BACKSPACE:
2150 p = "BACKSPACE";
2151 break;
2152 case ST_BLOCK:
2153 p = "BLOCK";
2154 break;
2155 case ST_BLOCK_DATA:
2156 p = "BLOCK DATA";
2157 break;
2158 case ST_CALL:
2159 p = "CALL";
2160 break;
2161 case ST_CASE:
2162 p = "CASE";
2163 break;
2164 case ST_CLOSE:
2165 p = "CLOSE";
2166 break;
2167 case ST_COMMON:
2168 p = "COMMON";
2169 break;
2170 case ST_CONTINUE:
2171 p = "CONTINUE";
2172 break;
2173 case ST_CONTAINS:
2174 p = "CONTAINS";
2175 break;
2176 case ST_CRITICAL:
2177 p = "CRITICAL";
2178 break;
2179 case ST_CYCLE:
2180 p = "CYCLE";
2181 break;
2182 case ST_DATA_DECL:
2183 p = _("data declaration");
2184 break;
2185 case ST_DATA:
2186 p = "DATA";
2187 break;
2188 case ST_DEALLOCATE:
2189 p = "DEALLOCATE";
2190 break;
2191 case ST_MAP:
2192 p = "MAP";
2193 break;
2194 case ST_UNION:
2195 p = "UNION";
2196 break;
2197 case ST_STRUCTURE_DECL:
2198 p = "STRUCTURE";
2199 break;
2200 case ST_DERIVED_DECL:
2201 p = _("derived type declaration");
2202 break;
2203 case ST_DO:
2204 p = "DO";
2205 break;
2206 case ST_ELSE:
2207 p = "ELSE";
2208 break;
2209 case ST_ELSEIF:
2210 p = "ELSE IF";
2211 break;
2212 case ST_ELSEWHERE:
2213 p = "ELSEWHERE";
2214 break;
2215 case ST_EVENT_POST:
2216 p = "EVENT POST";
2217 break;
2218 case ST_EVENT_WAIT:
2219 p = "EVENT WAIT";
2220 break;
2221 case ST_FAIL_IMAGE:
2222 p = "FAIL IMAGE";
2223 break;
2224 case ST_CHANGE_TEAM:
2225 p = "CHANGE TEAM";
2226 break;
2227 case ST_END_TEAM:
2228 p = "END TEAM";
2229 break;
2230 case ST_FORM_TEAM:
2231 p = "FORM TEAM";
2232 break;
2233 case ST_SYNC_TEAM:
2234 p = "SYNC TEAM";
2235 break;
2236 case ST_END_ASSOCIATE:
2237 p = "END ASSOCIATE";
2238 break;
2239 case ST_END_BLOCK:
2240 p = "END BLOCK";
2241 break;
2242 case ST_END_BLOCK_DATA:
2243 p = "END BLOCK DATA";
2244 break;
2245 case ST_END_CRITICAL:
2246 p = "END CRITICAL";
2247 break;
2248 case ST_ENDDO:
2249 p = "END DO";
2250 break;
2251 case ST_END_FILE:
2252 p = "END FILE";
2253 break;
2254 case ST_END_FORALL:
2255 p = "END FORALL";
2256 break;
2257 case ST_END_FUNCTION:
2258 p = "END FUNCTION";
2259 break;
2260 case ST_ENDIF:
2261 p = "END IF";
2262 break;
2263 case ST_END_INTERFACE:
2264 p = "END INTERFACE";
2265 break;
2266 case ST_END_MODULE:
2267 p = "END MODULE";
2268 break;
2269 case ST_END_SUBMODULE:
2270 p = "END SUBMODULE";
2271 break;
2272 case ST_END_PROGRAM:
2273 p = "END PROGRAM";
2274 break;
2275 case ST_END_SELECT:
2276 p = "END SELECT";
2277 break;
2278 case ST_END_SUBROUTINE:
2279 p = "END SUBROUTINE";
2280 break;
2281 case ST_END_WHERE:
2282 p = "END WHERE";
2283 break;
2284 case ST_END_STRUCTURE:
2285 p = "END STRUCTURE";
2286 break;
2287 case ST_END_UNION:
2288 p = "END UNION";
2289 break;
2290 case ST_END_MAP:
2291 p = "END MAP";
2292 break;
2293 case ST_END_TYPE:
2294 p = "END TYPE";
2295 break;
2296 case ST_ENTRY:
2297 p = "ENTRY";
2298 break;
2299 case ST_EQUIVALENCE:
2300 p = "EQUIVALENCE";
2301 break;
2302 case ST_ERROR_STOP:
2303 p = "ERROR STOP";
2304 break;
2305 case ST_EXIT:
2306 p = "EXIT";
2307 break;
2308 case ST_FLUSH:
2309 p = "FLUSH";
2310 break;
2311 case ST_FORALL_BLOCK: /* Fall through */
2312 case ST_FORALL:
2313 p = "FORALL";
2314 break;
2315 case ST_FORMAT:
2316 p = "FORMAT";
2317 break;
2318 case ST_FUNCTION:
2319 p = "FUNCTION";
2320 break;
2321 case ST_GENERIC:
2322 p = "GENERIC";
2323 break;
2324 case ST_GOTO:
2325 p = "GOTO";
2326 break;
2327 case ST_IF_BLOCK:
2328 p = _("block IF");
2329 break;
2330 case ST_IMPLICIT:
2331 p = "IMPLICIT";
2332 break;
2333 case ST_IMPLICIT_NONE:
2334 p = "IMPLICIT NONE";
2335 break;
2336 case ST_IMPLIED_ENDDO:
2337 p = _("implied END DO");
2338 break;
2339 case ST_IMPORT:
2340 p = "IMPORT";
2341 break;
2342 case ST_INQUIRE:
2343 p = "INQUIRE";
2344 break;
2345 case ST_INTERFACE:
2346 p = "INTERFACE";
2347 break;
2348 case ST_LOCK:
2349 p = "LOCK";
2350 break;
2351 case ST_PARAMETER:
2352 p = "PARAMETER";
2353 break;
2354 case ST_PRIVATE:
2355 p = "PRIVATE";
2356 break;
2357 case ST_PUBLIC:
2358 p = "PUBLIC";
2359 break;
2360 case ST_MODULE:
2361 p = "MODULE";
2362 break;
2363 case ST_SUBMODULE:
2364 p = "SUBMODULE";
2365 break;
2366 case ST_PAUSE:
2367 p = "PAUSE";
2368 break;
2369 case ST_MODULE_PROC:
2370 p = "MODULE PROCEDURE";
2371 break;
2372 case ST_NAMELIST:
2373 p = "NAMELIST";
2374 break;
2375 case ST_NULLIFY:
2376 p = "NULLIFY";
2377 break;
2378 case ST_OPEN:
2379 p = "OPEN";
2380 break;
2381 case ST_PROGRAM:
2382 p = "PROGRAM";
2383 break;
2384 case ST_PROCEDURE:
2385 p = "PROCEDURE";
2386 break;
2387 case ST_READ:
2388 p = "READ";
2389 break;
2390 case ST_RETURN:
2391 p = "RETURN";
2392 break;
2393 case ST_REWIND:
2394 p = "REWIND";
2395 break;
2396 case ST_STOP:
2397 p = "STOP";
2398 break;
2399 case ST_SYNC_ALL:
2400 p = "SYNC ALL";
2401 break;
2402 case ST_SYNC_IMAGES:
2403 p = "SYNC IMAGES";
2404 break;
2405 case ST_SYNC_MEMORY:
2406 p = "SYNC MEMORY";
2407 break;
2408 case ST_SUBROUTINE:
2409 p = "SUBROUTINE";
2410 break;
2411 case ST_TYPE:
2412 p = "TYPE";
2413 break;
2414 case ST_UNLOCK:
2415 p = "UNLOCK";
2416 break;
2417 case ST_USE:
2418 p = "USE";
2419 break;
2420 case ST_WHERE_BLOCK: /* Fall through */
2421 case ST_WHERE:
2422 p = "WHERE";
2423 break;
2424 case ST_WAIT:
2425 p = "WAIT";
2426 break;
2427 case ST_WRITE:
2428 p = "WRITE";
2429 break;
2430 case ST_ASSIGNMENT:
2431 p = _("assignment");
2432 break;
2433 case ST_POINTER_ASSIGNMENT:
2434 p = _("pointer assignment");
2435 break;
2436 case ST_SELECT_CASE:
2437 p = "SELECT CASE";
2438 break;
2439 case ST_SELECT_TYPE:
2440 p = "SELECT TYPE";
2441 break;
2442 case ST_SELECT_RANK:
2443 p = "SELECT RANK";
2444 break;
2445 case ST_TYPE_IS:
2446 p = "TYPE IS";
2447 break;
2448 case ST_CLASS_IS:
2449 p = "CLASS IS";
2450 break;
2451 case ST_RANK:
2452 p = "RANK";
2453 break;
2454 case ST_SEQUENCE:
2455 p = "SEQUENCE";
2456 break;
2457 case ST_SIMPLE_IF:
2458 p = _("simple IF");
2459 break;
2460 case ST_STATEMENT_FUNCTION:
2461 p = "STATEMENT FUNCTION";
2462 break;
2463 case ST_LABEL_ASSIGNMENT:
2464 p = "LABEL ASSIGNMENT";
2465 break;
2466 case ST_ENUM:
2467 p = "ENUM DEFINITION";
2468 break;
2469 case ST_ENUMERATOR:
2470 p = "ENUMERATOR DEFINITION";
2471 break;
2472 case ST_END_ENUM:
2473 p = "END ENUM";
2474 break;
2475 case ST_OACC_PARALLEL_LOOP:
2476 p = "!$ACC PARALLEL LOOP";
2477 break;
2478 case ST_OACC_END_PARALLEL_LOOP:
2479 p = "!$ACC END PARALLEL LOOP";
2480 break;
2481 case ST_OACC_PARALLEL:
2482 p = "!$ACC PARALLEL";
2483 break;
2484 case ST_OACC_END_PARALLEL:
2485 p = "!$ACC END PARALLEL";
2486 break;
2487 case ST_OACC_KERNELS:
2488 p = "!$ACC KERNELS";
2489 break;
2490 case ST_OACC_END_KERNELS:
2491 p = "!$ACC END KERNELS";
2492 break;
2493 case ST_OACC_KERNELS_LOOP:
2494 p = "!$ACC KERNELS LOOP";
2495 break;
2496 case ST_OACC_END_KERNELS_LOOP:
2497 p = "!$ACC END KERNELS LOOP";
2498 break;
2499 case ST_OACC_SERIAL_LOOP:
2500 p = "!$ACC SERIAL LOOP";
2501 break;
2502 case ST_OACC_END_SERIAL_LOOP:
2503 p = "!$ACC END SERIAL LOOP";
2504 break;
2505 case ST_OACC_SERIAL:
2506 p = "!$ACC SERIAL";
2507 break;
2508 case ST_OACC_END_SERIAL:
2509 p = "!$ACC END SERIAL";
2510 break;
2511 case ST_OACC_DATA:
2512 p = "!$ACC DATA";
2513 break;
2514 case ST_OACC_END_DATA:
2515 p = "!$ACC END DATA";
2516 break;
2517 case ST_OACC_HOST_DATA:
2518 p = "!$ACC HOST_DATA";
2519 break;
2520 case ST_OACC_END_HOST_DATA:
2521 p = "!$ACC END HOST_DATA";
2522 break;
2523 case ST_OACC_LOOP:
2524 p = "!$ACC LOOP";
2525 break;
2526 case ST_OACC_END_LOOP:
2527 p = "!$ACC END LOOP";
2528 break;
2529 case ST_OACC_DECLARE:
2530 p = "!$ACC DECLARE";
2531 break;
2532 case ST_OACC_UPDATE:
2533 p = "!$ACC UPDATE";
2534 break;
2535 case ST_OACC_WAIT:
2536 p = "!$ACC WAIT";
2537 break;
2538 case ST_OACC_CACHE:
2539 p = "!$ACC CACHE";
2540 break;
2541 case ST_OACC_ENTER_DATA:
2542 p = "!$ACC ENTER DATA";
2543 break;
2544 case ST_OACC_EXIT_DATA:
2545 p = "!$ACC EXIT DATA";
2546 break;
2547 case ST_OACC_ROUTINE:
2548 p = "!$ACC ROUTINE";
2549 break;
2550 case ST_OACC_ATOMIC:
2551 p = "!$ACC ATOMIC";
2552 break;
2553 case ST_OACC_END_ATOMIC:
2554 p = "!$ACC END ATOMIC";
2555 break;
2556 case ST_OMP_ALLOCATE:
2557 case ST_OMP_ALLOCATE_EXEC:
2558 p = "!$OMP ALLOCATE";
2559 break;
2560 case ST_OMP_ALLOCATORS:
2561 p = "!$OMP ALLOCATORS";
2562 break;
2563 case ST_OMP_ASSUME:
2564 p = "!$OMP ASSUME";
2565 break;
2566 case ST_OMP_ASSUMES:
2567 p = "!$OMP ASSUMES";
2568 break;
2569 case ST_OMP_ATOMIC:
2570 p = "!$OMP ATOMIC";
2571 break;
2572 case ST_OMP_BARRIER:
2573 p = "!$OMP BARRIER";
2574 break;
2575 case ST_OMP_CANCEL:
2576 p = "!$OMP CANCEL";
2577 break;
2578 case ST_OMP_CANCELLATION_POINT:
2579 p = "!$OMP CANCELLATION POINT";
2580 break;
2581 case ST_OMP_CRITICAL:
2582 p = "!$OMP CRITICAL";
2583 break;
2584 case ST_OMP_DECLARE_REDUCTION:
2585 p = "!$OMP DECLARE REDUCTION";
2586 break;
2587 case ST_OMP_DECLARE_SIMD:
2588 p = "!$OMP DECLARE SIMD";
2589 break;
2590 case ST_OMP_DECLARE_TARGET:
2591 p = "!$OMP DECLARE TARGET";
2592 break;
2593 case ST_OMP_DECLARE_VARIANT:
2594 p = "!$OMP DECLARE VARIANT";
2595 break;
2596 case ST_OMP_DEPOBJ:
2597 p = "!$OMP DEPOBJ";
2598 break;
2599 case ST_OMP_DISTRIBUTE:
2600 p = "!$OMP DISTRIBUTE";
2601 break;
2602 case ST_OMP_DISTRIBUTE_PARALLEL_DO:
2603 p = "!$OMP DISTRIBUTE PARALLEL DO";
2604 break;
2605 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
2606 p = "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2607 break;
2608 case ST_OMP_DISTRIBUTE_SIMD:
2609 p = "!$OMP DISTRIBUTE SIMD";
2610 break;
2611 case ST_OMP_DO:
2612 p = "!$OMP DO";
2613 break;
2614 case ST_OMP_DO_SIMD:
2615 p = "!$OMP DO SIMD";
2616 break;
2617 case ST_OMP_END_ALLOCATORS:
2618 p = "!$OMP END ALLOCATORS";
2619 break;
2620 case ST_OMP_END_ASSUME:
2621 p = "!$OMP END ASSUME";
2622 break;
2623 case ST_OMP_END_ATOMIC:
2624 p = "!$OMP END ATOMIC";
2625 break;
2626 case ST_OMP_END_CRITICAL:
2627 p = "!$OMP END CRITICAL";
2628 break;
2629 case ST_OMP_END_DISTRIBUTE:
2630 p = "!$OMP END DISTRIBUTE";
2631 break;
2632 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO:
2633 p = "!$OMP END DISTRIBUTE PARALLEL DO";
2634 break;
2635 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD:
2636 p = "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2637 break;
2638 case ST_OMP_END_DISTRIBUTE_SIMD:
2639 p = "!$OMP END DISTRIBUTE SIMD";
2640 break;
2641 case ST_OMP_END_DO:
2642 p = "!$OMP END DO";
2643 break;
2644 case ST_OMP_END_DO_SIMD:
2645 p = "!$OMP END DO SIMD";
2646 break;
2647 case ST_OMP_END_SCOPE:
2648 p = "!$OMP END SCOPE";
2649 break;
2650 case ST_OMP_END_SIMD:
2651 p = "!$OMP END SIMD";
2652 break;
2653 case ST_OMP_END_LOOP:
2654 p = "!$OMP END LOOP";
2655 break;
2656 case ST_OMP_END_MASKED:
2657 p = "!$OMP END MASKED";
2658 break;
2659 case ST_OMP_END_MASKED_TASKLOOP:
2660 p = "!$OMP END MASKED TASKLOOP";
2661 break;
2662 case ST_OMP_END_MASKED_TASKLOOP_SIMD:
2663 p = "!$OMP END MASKED TASKLOOP SIMD";
2664 break;
2665 case ST_OMP_END_MASTER:
2666 p = "!$OMP END MASTER";
2667 break;
2668 case ST_OMP_END_MASTER_TASKLOOP:
2669 p = "!$OMP END MASTER TASKLOOP";
2670 break;
2671 case ST_OMP_END_MASTER_TASKLOOP_SIMD:
2672 p = "!$OMP END MASTER TASKLOOP SIMD";
2673 break;
2674 case ST_OMP_END_ORDERED:
2675 p = "!$OMP END ORDERED";
2676 break;
2677 case ST_OMP_END_PARALLEL:
2678 p = "!$OMP END PARALLEL";
2679 break;
2680 case ST_OMP_END_PARALLEL_DO:
2681 p = "!$OMP END PARALLEL DO";
2682 break;
2683 case ST_OMP_END_PARALLEL_DO_SIMD:
2684 p = "!$OMP END PARALLEL DO SIMD";
2685 break;
2686 case ST_OMP_END_PARALLEL_LOOP:
2687 p = "!$OMP END PARALLEL LOOP";
2688 break;
2689 case ST_OMP_END_PARALLEL_MASKED:
2690 p = "!$OMP END PARALLEL MASKED";
2691 break;
2692 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP:
2693 p = "!$OMP END PARALLEL MASKED TASKLOOP";
2694 break;
2695 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD:
2696 p = "!$OMP END PARALLEL MASKED TASKLOOP SIMD";
2697 break;
2698 case ST_OMP_END_PARALLEL_MASTER:
2699 p = "!$OMP END PARALLEL MASTER";
2700 break;
2701 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP:
2702 p = "!$OMP END PARALLEL MASTER TASKLOOP";
2703 break;
2704 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD:
2705 p = "!$OMP END PARALLEL MASTER TASKLOOP SIMD";
2706 break;
2707 case ST_OMP_END_PARALLEL_SECTIONS:
2708 p = "!$OMP END PARALLEL SECTIONS";
2709 break;
2710 case ST_OMP_END_PARALLEL_WORKSHARE:
2711 p = "!$OMP END PARALLEL WORKSHARE";
2712 break;
2713 case ST_OMP_END_SECTIONS:
2714 p = "!$OMP END SECTIONS";
2715 break;
2716 case ST_OMP_END_SINGLE:
2717 p = "!$OMP END SINGLE";
2718 break;
2719 case ST_OMP_END_TASK:
2720 p = "!$OMP END TASK";
2721 break;
2722 case ST_OMP_END_TARGET:
2723 p = "!$OMP END TARGET";
2724 break;
2725 case ST_OMP_END_TARGET_DATA:
2726 p = "!$OMP END TARGET DATA";
2727 break;
2728 case ST_OMP_END_TARGET_PARALLEL:
2729 p = "!$OMP END TARGET PARALLEL";
2730 break;
2731 case ST_OMP_END_TARGET_PARALLEL_DO:
2732 p = "!$OMP END TARGET PARALLEL DO";
2733 break;
2734 case ST_OMP_END_TARGET_PARALLEL_DO_SIMD:
2735 p = "!$OMP END TARGET PARALLEL DO SIMD";
2736 break;
2737 case ST_OMP_END_TARGET_PARALLEL_LOOP:
2738 p = "!$OMP END TARGET PARALLEL LOOP";
2739 break;
2740 case ST_OMP_END_TARGET_SIMD:
2741 p = "!$OMP END TARGET SIMD";
2742 break;
2743 case ST_OMP_END_TARGET_TEAMS:
2744 p = "!$OMP END TARGET TEAMS";
2745 break;
2746 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE:
2747 p = "!$OMP END TARGET TEAMS DISTRIBUTE";
2748 break;
2749 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
2750 p = "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2751 break;
2752 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
2753 p = "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2754 break;
2755 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD:
2756 p = "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2757 break;
2758 case ST_OMP_END_TARGET_TEAMS_LOOP:
2759 p = "!$OMP END TARGET TEAMS LOOP";
2760 break;
2761 case ST_OMP_END_TASKGROUP:
2762 p = "!$OMP END TASKGROUP";
2763 break;
2764 case ST_OMP_END_TASKLOOP:
2765 p = "!$OMP END TASKLOOP";
2766 break;
2767 case ST_OMP_END_TASKLOOP_SIMD:
2768 p = "!$OMP END TASKLOOP SIMD";
2769 break;
2770 case ST_OMP_END_TEAMS:
2771 p = "!$OMP END TEAMS";
2772 break;
2773 case ST_OMP_END_TEAMS_DISTRIBUTE:
2774 p = "!$OMP END TEAMS DISTRIBUTE";
2775 break;
2776 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO:
2777 p = "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2778 break;
2779 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
2780 p = "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2781 break;
2782 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD:
2783 p = "!$OMP END TEAMS DISTRIBUTE SIMD";
2784 break;
2785 case ST_OMP_END_TEAMS_LOOP:
2786 p = "!$OMP END TEAMS LOOP";
2787 break;
2788 case ST_OMP_END_WORKSHARE:
2789 p = "!$OMP END WORKSHARE";
2790 break;
2791 case ST_OMP_ERROR:
2792 p = "!$OMP ERROR";
2793 break;
2794 case ST_OMP_FLUSH:
2795 p = "!$OMP FLUSH";
2796 break;
2797 case ST_OMP_LOOP:
2798 p = "!$OMP LOOP";
2799 break;
2800 case ST_OMP_MASKED:
2801 p = "!$OMP MASKED";
2802 break;
2803 case ST_OMP_MASKED_TASKLOOP:
2804 p = "!$OMP MASKED TASKLOOP";
2805 break;
2806 case ST_OMP_MASKED_TASKLOOP_SIMD:
2807 p = "!$OMP MASKED TASKLOOP SIMD";
2808 break;
2809 case ST_OMP_MASTER:
2810 p = "!$OMP MASTER";
2811 break;
2812 case ST_OMP_MASTER_TASKLOOP:
2813 p = "!$OMP MASTER TASKLOOP";
2814 break;
2815 case ST_OMP_MASTER_TASKLOOP_SIMD:
2816 p = "!$OMP MASTER TASKLOOP SIMD";
2817 break;
2818 case ST_OMP_ORDERED:
2819 case ST_OMP_ORDERED_DEPEND:
2820 p = "!$OMP ORDERED";
2821 break;
2822 case ST_OMP_NOTHING:
2823 /* Note: gfc_match_omp_nothing returns ST_NONE. */
2824 p = "!$OMP NOTHING";
2825 break;
2826 case ST_OMP_PARALLEL:
2827 p = "!$OMP PARALLEL";
2828 break;
2829 case ST_OMP_PARALLEL_DO:
2830 p = "!$OMP PARALLEL DO";
2831 break;
2832 case ST_OMP_PARALLEL_LOOP:
2833 p = "!$OMP PARALLEL LOOP";
2834 break;
2835 case ST_OMP_PARALLEL_DO_SIMD:
2836 p = "!$OMP PARALLEL DO SIMD";
2837 break;
2838 case ST_OMP_PARALLEL_MASKED:
2839 p = "!$OMP PARALLEL MASKED";
2840 break;
2841 case ST_OMP_PARALLEL_MASKED_TASKLOOP:
2842 p = "!$OMP PARALLEL MASKED TASKLOOP";
2843 break;
2844 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
2845 p = "!$OMP PARALLEL MASKED TASKLOOP SIMD";
2846 break;
2847 case ST_OMP_PARALLEL_MASTER:
2848 p = "!$OMP PARALLEL MASTER";
2849 break;
2850 case ST_OMP_PARALLEL_MASTER_TASKLOOP:
2851 p = "!$OMP PARALLEL MASTER TASKLOOP";
2852 break;
2853 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
2854 p = "!$OMP PARALLEL MASTER TASKLOOP SIMD";
2855 break;
2856 case ST_OMP_PARALLEL_SECTIONS:
2857 p = "!$OMP PARALLEL SECTIONS";
2858 break;
2859 case ST_OMP_PARALLEL_WORKSHARE:
2860 p = "!$OMP PARALLEL WORKSHARE";
2861 break;
2862 case ST_OMP_REQUIRES:
2863 p = "!$OMP REQUIRES";
2864 break;
2865 case ST_OMP_SCAN:
2866 p = "!$OMP SCAN";
2867 break;
2868 case ST_OMP_SCOPE:
2869 p = "!$OMP SCOPE";
2870 break;
2871 case ST_OMP_SECTIONS:
2872 p = "!$OMP SECTIONS";
2873 break;
2874 case ST_OMP_SECTION:
2875 p = "!$OMP SECTION";
2876 break;
2877 case ST_OMP_SIMD:
2878 p = "!$OMP SIMD";
2879 break;
2880 case ST_OMP_SINGLE:
2881 p = "!$OMP SINGLE";
2882 break;
2883 case ST_OMP_TARGET:
2884 p = "!$OMP TARGET";
2885 break;
2886 case ST_OMP_TARGET_DATA:
2887 p = "!$OMP TARGET DATA";
2888 break;
2889 case ST_OMP_TARGET_ENTER_DATA:
2890 p = "!$OMP TARGET ENTER DATA";
2891 break;
2892 case ST_OMP_TARGET_EXIT_DATA:
2893 p = "!$OMP TARGET EXIT DATA";
2894 break;
2895 case ST_OMP_TARGET_PARALLEL:
2896 p = "!$OMP TARGET PARALLEL";
2897 break;
2898 case ST_OMP_TARGET_PARALLEL_DO:
2899 p = "!$OMP TARGET PARALLEL DO";
2900 break;
2901 case ST_OMP_TARGET_PARALLEL_DO_SIMD:
2902 p = "!$OMP TARGET PARALLEL DO SIMD";
2903 break;
2904 case ST_OMP_TARGET_PARALLEL_LOOP:
2905 p = "!$OMP TARGET PARALLEL LOOP";
2906 break;
2907 case ST_OMP_TARGET_SIMD:
2908 p = "!$OMP TARGET SIMD";
2909 break;
2910 case ST_OMP_TARGET_TEAMS:
2911 p = "!$OMP TARGET TEAMS";
2912 break;
2913 case ST_OMP_TARGET_TEAMS_DISTRIBUTE:
2914 p = "!$OMP TARGET TEAMS DISTRIBUTE";
2915 break;
2916 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
2917 p = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2918 break;
2919 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
2920 p = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2921 break;
2922 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
2923 p = "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2924 break;
2925 case ST_OMP_TARGET_TEAMS_LOOP:
2926 p = "!$OMP TARGET TEAMS LOOP";
2927 break;
2928 case ST_OMP_TARGET_UPDATE:
2929 p = "!$OMP TARGET UPDATE";
2930 break;
2931 case ST_OMP_TASK:
2932 p = "!$OMP TASK";
2933 break;
2934 case ST_OMP_TASKGROUP:
2935 p = "!$OMP TASKGROUP";
2936 break;
2937 case ST_OMP_TASKLOOP:
2938 p = "!$OMP TASKLOOP";
2939 break;
2940 case ST_OMP_TASKLOOP_SIMD:
2941 p = "!$OMP TASKLOOP SIMD";
2942 break;
2943 case ST_OMP_TASKWAIT:
2944 p = "!$OMP TASKWAIT";
2945 break;
2946 case ST_OMP_TASKYIELD:
2947 p = "!$OMP TASKYIELD";
2948 break;
2949 case ST_OMP_TEAMS:
2950 p = "!$OMP TEAMS";
2951 break;
2952 case ST_OMP_TEAMS_DISTRIBUTE:
2953 p = "!$OMP TEAMS DISTRIBUTE";
2954 break;
2955 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
2956 p = "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2957 break;
2958 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
2959 p = "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2960 break;
2961 case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
2962 p = "!$OMP TEAMS DISTRIBUTE SIMD";
2963 break;
2964 case ST_OMP_TEAMS_LOOP:
2965 p = "!$OMP TEAMS LOOP";
2966 break;
2967 case ST_OMP_THREADPRIVATE:
2968 p = "!$OMP THREADPRIVATE";
2969 break;
2970 case ST_OMP_WORKSHARE:
2971 p = "!$OMP WORKSHARE";
2972 break;
2973 default:
2974 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2975 }
2976
2977 if (strip_sentinel && p[0] == '!')
2978 return p + strlen ("!$OMP ");
2979 return p;
2980 }
2981
2982
2983 /* Create a symbol for the main program and assign it to ns->proc_name. */
2984
2985 static void
2986 main_program_symbol (gfc_namespace *ns, const char *name)
2987 {
2988 gfc_symbol *main_program;
2989 symbol_attribute attr;
2990
2991 gfc_get_symbol (name, ns, &main_program);
2992 gfc_clear_attr (&attr);
2993 attr.flavor = FL_PROGRAM;
2994 attr.proc = PROC_UNKNOWN;
2995 attr.subroutine = 1;
2996 attr.access = ACCESS_PUBLIC;
2997 attr.is_main_program = 1;
2998 main_program->attr = attr;
2999 main_program->declared_at = gfc_current_locus;
3000 ns->proc_name = main_program;
3001 gfc_commit_symbols ();
3002 }
3003
3004
3005 /* Do whatever is necessary to accept the last statement. */
3006
3007 static void
3008 accept_statement (gfc_statement st)
3009 {
3010 switch (st)
3011 {
3012 case ST_IMPLICIT_NONE:
3013 case ST_IMPLICIT:
3014 break;
3015
3016 case ST_FUNCTION:
3017 case ST_SUBROUTINE:
3018 case ST_MODULE:
3019 case ST_SUBMODULE:
3020 gfc_current_ns->proc_name = gfc_new_block;
3021 break;
3022
3023 /* If the statement is the end of a block, lay down a special code
3024 that allows a branch to the end of the block from within the
3025 construct. IF and SELECT are treated differently from DO
3026 (where EXEC_NOP is added inside the loop) for two
3027 reasons:
3028 1. END DO has a meaning in the sense that after a GOTO to
3029 it, the loop counter must be increased.
3030 2. IF blocks and SELECT blocks can consist of multiple
3031 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
3032 Putting the label before the END IF would make the jump
3033 from, say, the ELSE IF block to the END IF illegal. */
3034
3035 case ST_ENDIF:
3036 case ST_END_SELECT:
3037 case ST_END_CRITICAL:
3038 if (gfc_statement_label != NULL)
3039 {
3040 new_st.op = EXEC_END_NESTED_BLOCK;
3041 add_statement ();
3042 }
3043 break;
3044
3045 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
3046 one parallel block. Thus, we add the special code to the nested block
3047 itself, instead of the parent one. */
3048 case ST_END_BLOCK:
3049 case ST_END_ASSOCIATE:
3050 if (gfc_statement_label != NULL)
3051 {
3052 new_st.op = EXEC_END_BLOCK;
3053 add_statement ();
3054 }
3055 break;
3056
3057 /* The end-of-program unit statements do not get the special
3058 marker and require a statement of some sort if they are a
3059 branch target. */
3060
3061 case ST_END_PROGRAM:
3062 case ST_END_FUNCTION:
3063 case ST_END_SUBROUTINE:
3064 if (gfc_statement_label != NULL)
3065 {
3066 new_st.op = EXEC_RETURN;
3067 add_statement ();
3068 }
3069 else
3070 {
3071 new_st.op = EXEC_END_PROCEDURE;
3072 add_statement ();
3073 }
3074
3075 break;
3076
3077 case ST_ENTRY:
3078 case_executable:
3079 case_exec_markers:
3080 add_statement ();
3081 break;
3082
3083 default:
3084 break;
3085 }
3086
3087 gfc_commit_symbols ();
3088 gfc_warning_check ();
3089 gfc_clear_new_st ();
3090 }
3091
3092
3093 /* Undo anything tentative that has been built for the current statement,
3094 except if a gfc_charlen structure has been added to current namespace's
3095 list of gfc_charlen structure. */
3096
3097 static void
3098 reject_statement (void)
3099 {
3100 gfc_free_equiv_until (gfc_current_ns->equiv, gfc_current_ns->old_equiv);
3101 gfc_current_ns->equiv = gfc_current_ns->old_equiv;
3102 gfc_drop_interface_elements_before (current_interface_ptr,
3103 previous_interface_head);
3104
3105 gfc_reject_data (gfc_current_ns);
3106
3107 gfc_new_block = NULL;
3108 gfc_undo_symbols ();
3109 gfc_clear_warning ();
3110 undo_new_statement ();
3111 }
3112
3113
3114 /* Generic complaint about an out of order statement. We also do
3115 whatever is necessary to clean up. */
3116
3117 static void
3118 unexpected_statement (gfc_statement st)
3119 {
3120 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st));
3121
3122 reject_statement ();
3123 }
3124
3125
3126 /* Given the next statement seen by the matcher, make sure that it is
3127 in proper order with the last. This subroutine is initialized by
3128 calling it with an argument of ST_NONE. If there is a problem, we
3129 issue an error and return false. Otherwise we return true.
3130
3131 Individual parsers need to verify that the statements seen are
3132 valid before calling here, i.e., ENTRY statements are not allowed in
3133 INTERFACE blocks. The following diagram is taken from the standard:
3134
3135 +---------------------------------------+
3136 | program subroutine function module |
3137 +---------------------------------------+
3138 | use |
3139 +---------------------------------------+
3140 | import |
3141 +---------------------------------------+
3142 | | implicit none |
3143 | +-----------+------------------+
3144 | | parameter | implicit |
3145 | +-----------+------------------+
3146 | format | | derived type |
3147 | entry | parameter | interface |
3148 | | data | specification |
3149 | | | statement func |
3150 | +-----------+------------------+
3151 | | data | executable |
3152 +--------+-----------+------------------+
3153 | contains |
3154 +---------------------------------------+
3155 | internal module/subprogram |
3156 +---------------------------------------+
3157 | end |
3158 +---------------------------------------+
3159
3160 */
3161
3162 enum state_order
3163 {
3164 ORDER_START,
3165 ORDER_USE,
3166 ORDER_IMPORT,
3167 ORDER_IMPLICIT_NONE,
3168 ORDER_IMPLICIT,
3169 ORDER_SPEC,
3170 ORDER_EXEC
3171 };
3172
3173 typedef struct
3174 {
3175 enum state_order state;
3176 gfc_statement last_statement;
3177 locus where;
3178 }
3179 st_state;
3180
3181 static bool
3182 verify_st_order (st_state *p, gfc_statement st, bool silent)
3183 {
3184
3185 switch (st)
3186 {
3187 case ST_NONE:
3188 p->state = ORDER_START;
3189 in_exec_part = false;
3190 break;
3191
3192 case ST_USE:
3193 if (p->state > ORDER_USE)
3194 goto order;
3195 p->state = ORDER_USE;
3196 break;
3197
3198 case ST_IMPORT:
3199 if (p->state > ORDER_IMPORT)
3200 goto order;
3201 p->state = ORDER_IMPORT;
3202 break;
3203
3204 case ST_IMPLICIT_NONE:
3205 if (p->state > ORDER_IMPLICIT)
3206 goto order;
3207
3208 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
3209 statement disqualifies a USE but not an IMPLICIT NONE.
3210 Duplicate IMPLICIT NONEs are caught when the implicit types
3211 are set. */
3212
3213 p->state = ORDER_IMPLICIT_NONE;
3214 break;
3215
3216 case ST_IMPLICIT:
3217 if (p->state > ORDER_IMPLICIT)
3218 goto order;
3219 p->state = ORDER_IMPLICIT;
3220 break;
3221
3222 case ST_FORMAT:
3223 case ST_ENTRY:
3224 if (p->state < ORDER_IMPLICIT_NONE)
3225 p->state = ORDER_IMPLICIT_NONE;
3226 break;
3227
3228 case ST_PARAMETER:
3229 if (p->state >= ORDER_EXEC)
3230 goto order;
3231 if (p->state < ORDER_IMPLICIT)
3232 p->state = ORDER_IMPLICIT;
3233 break;
3234
3235 case ST_DATA:
3236 if (p->state < ORDER_SPEC)
3237 p->state = ORDER_SPEC;
3238 break;
3239
3240 case ST_PUBLIC:
3241 case ST_PRIVATE:
3242 case ST_STRUCTURE_DECL:
3243 case ST_DERIVED_DECL:
3244 case_decl:
3245 if (p->state >= ORDER_EXEC)
3246 goto order;
3247 if (p->state < ORDER_SPEC)
3248 p->state = ORDER_SPEC;
3249 break;
3250
3251 case_omp_decl:
3252 /* The OpenMP/OpenACC directives have to be somewhere in the specification
3253 part, but there are no further requirements on their ordering.
3254 Thus don't adjust p->state, just ignore them. */
3255 if (p->state >= ORDER_EXEC)
3256 goto order;
3257 break;
3258
3259 case_executable:
3260 case_exec_markers:
3261 if (p->state < ORDER_EXEC)
3262 p->state = ORDER_EXEC;
3263 in_exec_part = true;
3264 break;
3265
3266 default:
3267 return false;
3268 }
3269
3270 /* All is well, record the statement in case we need it next time. */
3271 p->where = gfc_current_locus;
3272 p->last_statement = st;
3273 return true;
3274
3275 order:
3276 if (!silent)
3277 gfc_error ("%s statement at %C cannot follow %s statement at %L",
3278 gfc_ascii_statement (st),
3279 gfc_ascii_statement (p->last_statement), &p->where);
3280
3281 return false;
3282 }
3283
3284
3285 /* Handle an unexpected end of file. This is a show-stopper... */
3286
3287 static void unexpected_eof (void) ATTRIBUTE_NORETURN;
3288
3289 static void
3290 unexpected_eof (void)
3291 {
3292 gfc_state_data *p;
3293
3294 gfc_error ("Unexpected end of file in %qs", gfc_source_file);
3295
3296 /* Memory cleanup. Move to "second to last". */
3297 for (p = gfc_state_stack; p && p->previous && p->previous->previous;
3298 p = p->previous);
3299
3300 gfc_current_ns->code = (p && p->previous) ? p->head : NULL;
3301 gfc_done_2 ();
3302
3303 longjmp (eof_buf, 1);
3304
3305 /* Avoids build error on systems where longjmp is not declared noreturn. */
3306 gcc_unreachable ();
3307 }
3308
3309
3310 /* Parse the CONTAINS section of a derived type definition. */
3311
3312 gfc_access gfc_typebound_default_access;
3313
3314 static bool
3315 parse_derived_contains (void)
3316 {
3317 gfc_state_data s;
3318 bool seen_private = false;
3319 bool seen_comps = false;
3320 bool error_flag = false;
3321 bool to_finish;
3322
3323 gcc_assert (gfc_current_state () == COMP_DERIVED);
3324 gcc_assert (gfc_current_block ());
3325
3326 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
3327 section. */
3328 if (gfc_current_block ()->attr.sequence)
3329 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
3330 " section at %C", gfc_current_block ()->name);
3331 if (gfc_current_block ()->attr.is_bind_c)
3332 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
3333 " section at %C", gfc_current_block ()->name);
3334
3335 accept_statement (ST_CONTAINS);
3336 push_state (&s, COMP_DERIVED_CONTAINS, NULL);
3337
3338 gfc_typebound_default_access = ACCESS_PUBLIC;
3339
3340 to_finish = false;
3341 while (!to_finish)
3342 {
3343 gfc_statement st;
3344 st = next_statement ();
3345 switch (st)
3346 {
3347 case ST_NONE:
3348 unexpected_eof ();
3349 break;
3350
3351 case ST_DATA_DECL:
3352 gfc_error ("Components in TYPE at %C must precede CONTAINS");
3353 goto error;
3354
3355 case ST_PROCEDURE:
3356 if (!gfc_notify_std (GFC_STD_F2003, "Type-bound procedure at %C"))
3357 goto error;
3358
3359 accept_statement (ST_PROCEDURE);
3360 seen_comps = true;
3361 break;
3362
3363 case ST_GENERIC:
3364 if (!gfc_notify_std (GFC_STD_F2003, "GENERIC binding at %C"))
3365 goto error;
3366
3367 accept_statement (ST_GENERIC);
3368 seen_comps = true;
3369 break;
3370
3371 case ST_FINAL:
3372 if (!gfc_notify_std (GFC_STD_F2003, "FINAL procedure declaration"
3373 " at %C"))
3374 goto error;
3375
3376 accept_statement (ST_FINAL);
3377 seen_comps = true;
3378 break;
3379
3380 case ST_END_TYPE:
3381 to_finish = true;
3382
3383 if (!seen_comps
3384 && (!gfc_notify_std(GFC_STD_F2008, "Derived type definition "
3385 "at %C with empty CONTAINS section")))
3386 goto error;
3387
3388 /* ST_END_TYPE is accepted by parse_derived after return. */
3389 break;
3390
3391 case ST_PRIVATE:
3392 if (!gfc_find_state (COMP_MODULE))
3393 {
3394 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3395 "a MODULE");
3396 goto error;
3397 }
3398
3399 if (seen_comps)
3400 {
3401 gfc_error ("PRIVATE statement at %C must precede procedure"
3402 " bindings");
3403 goto error;
3404 }
3405
3406 if (seen_private)
3407 {
3408 gfc_error ("Duplicate PRIVATE statement at %C");
3409 goto error;
3410 }
3411
3412 accept_statement (ST_PRIVATE);
3413 gfc_typebound_default_access = ACCESS_PRIVATE;
3414 seen_private = true;
3415 break;
3416
3417 case ST_SEQUENCE:
3418 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
3419 goto error;
3420
3421 case ST_CONTAINS:
3422 gfc_error ("Already inside a CONTAINS block at %C");
3423 goto error;
3424
3425 default:
3426 unexpected_statement (st);
3427 break;
3428 }
3429
3430 continue;
3431
3432 error:
3433 error_flag = true;
3434 reject_statement ();
3435 }
3436
3437 pop_state ();
3438 gcc_assert (gfc_current_state () == COMP_DERIVED);
3439
3440 return error_flag;
3441 }
3442
3443
3444 /* Set attributes for the parent symbol based on the attributes of a component
3445 and raise errors if conflicting attributes are found for the component. */
3446
3447 static void
3448 check_component (gfc_symbol *sym, gfc_component *c, gfc_component **lockp,
3449 gfc_component **eventp)
3450 {
3451 bool coarray, lock_type, event_type, allocatable, pointer;
3452 coarray = lock_type = event_type = allocatable = pointer = false;
3453 gfc_component *lock_comp = NULL, *event_comp = NULL;
3454
3455 if (lockp) lock_comp = *lockp;
3456 if (eventp) event_comp = *eventp;
3457
3458 /* Look for allocatable components. */
3459 if (c->attr.allocatable
3460 || (c->ts.type == BT_CLASS && c->attr.class_ok
3461 && CLASS_DATA (c)->attr.allocatable)
3462 || (c->ts.type == BT_DERIVED && !c->attr.pointer
3463 && c->ts.u.derived->attr.alloc_comp))
3464 {
3465 allocatable = true;
3466 sym->attr.alloc_comp = 1;
3467 }
3468
3469 /* Look for pointer components. */
3470 if (c->attr.pointer
3471 || (c->ts.type == BT_CLASS && c->attr.class_ok
3472 && CLASS_DATA (c)->attr.class_pointer)
3473 || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.pointer_comp))
3474 {
3475 pointer = true;
3476 sym->attr.pointer_comp = 1;
3477 }
3478
3479 /* Look for procedure pointer components. */
3480 if (c->attr.proc_pointer
3481 || (c->ts.type == BT_DERIVED
3482 && c->ts.u.derived->attr.proc_pointer_comp))
3483 sym->attr.proc_pointer_comp = 1;
3484
3485 /* Looking for coarray components. */
3486 if (c->attr.codimension
3487 || (c->ts.type == BT_CLASS && c->attr.class_ok
3488 && CLASS_DATA (c)->attr.codimension))
3489 {
3490 coarray = true;
3491 sym->attr.coarray_comp = 1;
3492 }
3493
3494 if (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.coarray_comp
3495 && !c->attr.pointer)
3496 {
3497 coarray = true;
3498 sym->attr.coarray_comp = 1;
3499 }
3500
3501 /* Looking for lock_type components. */
3502 if ((c->ts.type == BT_DERIVED
3503 && c->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
3504 && c->ts.u.derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE)
3505 || (c->ts.type == BT_CLASS && c->attr.class_ok
3506 && CLASS_DATA (c)->ts.u.derived->from_intmod
3507 == INTMOD_ISO_FORTRAN_ENV
3508 && CLASS_DATA (c)->ts.u.derived->intmod_sym_id
3509 == ISOFORTRAN_LOCK_TYPE)
3510 || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.lock_comp
3511 && !allocatable && !pointer))
3512 {
3513 lock_type = 1;
3514 lock_comp = c;
3515 sym->attr.lock_comp = 1;
3516 }
3517
3518 /* Looking for event_type components. */
3519 if ((c->ts.type == BT_DERIVED
3520 && c->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
3521 && c->ts.u.derived->intmod_sym_id == ISOFORTRAN_EVENT_TYPE)
3522 || (c->ts.type == BT_CLASS && c->attr.class_ok
3523 && CLASS_DATA (c)->ts.u.derived->from_intmod
3524 == INTMOD_ISO_FORTRAN_ENV
3525 && CLASS_DATA (c)->ts.u.derived->intmod_sym_id
3526 == ISOFORTRAN_EVENT_TYPE)
3527 || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.event_comp
3528 && !allocatable && !pointer))
3529 {
3530 event_type = 1;
3531 event_comp = c;
3532 sym->attr.event_comp = 1;
3533 }
3534
3535 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
3536 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
3537 unless there are nondirect [allocatable or pointer] components
3538 involved (cf. 1.3.33.1 and 1.3.33.3). */
3539
3540 if (pointer && !coarray && lock_type)
3541 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
3542 "codimension or be a subcomponent of a coarray, "
3543 "which is not possible as the component has the "
3544 "pointer attribute", c->name, &c->loc);
3545 else if (pointer && !coarray && c->ts.type == BT_DERIVED
3546 && c->ts.u.derived->attr.lock_comp)
3547 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3548 "of type LOCK_TYPE, which must have a codimension or be a "
3549 "subcomponent of a coarray", c->name, &c->loc);
3550
3551 if (lock_type && allocatable && !coarray)
3552 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
3553 "a codimension", c->name, &c->loc);
3554 else if (lock_type && allocatable && c->ts.type == BT_DERIVED
3555 && c->ts.u.derived->attr.lock_comp)
3556 gfc_error ("Allocatable component %s at %L must have a codimension as "
3557 "it has a noncoarray subcomponent of type LOCK_TYPE",
3558 c->name, &c->loc);
3559
3560 if (sym->attr.coarray_comp && !coarray && lock_type)
3561 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3562 "subcomponent of type LOCK_TYPE must have a codimension or "
3563 "be a subcomponent of a coarray. (Variables of type %s may "
3564 "not have a codimension as already a coarray "
3565 "subcomponent exists)", c->name, &c->loc, sym->name);
3566
3567 if (sym->attr.lock_comp && coarray && !lock_type)
3568 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3569 "subcomponent of type LOCK_TYPE must have a codimension or "
3570 "be a subcomponent of a coarray. (Variables of type %s may "
3571 "not have a codimension as %s at %L has a codimension or a "
3572 "coarray subcomponent)", lock_comp->name, &lock_comp->loc,
3573 sym->name, c->name, &c->loc);
3574
3575 /* Similarly for EVENT TYPE. */
3576
3577 if (pointer && !coarray && event_type)
3578 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
3579 "codimension or be a subcomponent of a coarray, "
3580 "which is not possible as the component has the "
3581 "pointer attribute", c->name, &c->loc);
3582 else if (pointer && !coarray && c->ts.type == BT_DERIVED
3583 && c->ts.u.derived->attr.event_comp)
3584 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3585 "of type EVENT_TYPE, which must have a codimension or be a "
3586 "subcomponent of a coarray", c->name, &c->loc);
3587
3588 if (event_type && allocatable && !coarray)
3589 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
3590 "a codimension", c->name, &c->loc);
3591 else if (event_type && allocatable && c->ts.type == BT_DERIVED
3592 && c->ts.u.derived->attr.event_comp)
3593 gfc_error ("Allocatable component %s at %L must have a codimension as "
3594 "it has a noncoarray subcomponent of type EVENT_TYPE",
3595 c->name, &c->loc);
3596
3597 if (sym->attr.coarray_comp && !coarray && event_type)
3598 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3599 "subcomponent of type EVENT_TYPE must have a codimension or "
3600 "be a subcomponent of a coarray. (Variables of type %s may "
3601 "not have a codimension as already a coarray "
3602 "subcomponent exists)", c->name, &c->loc, sym->name);
3603
3604 if (sym->attr.event_comp && coarray && !event_type)
3605 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3606 "subcomponent of type EVENT_TYPE must have a codimension or "
3607 "be a subcomponent of a coarray. (Variables of type %s may "
3608 "not have a codimension as %s at %L has a codimension or a "
3609 "coarray subcomponent)", event_comp->name, &event_comp->loc,
3610 sym->name, c->name, &c->loc);
3611
3612 /* Look for private components. */
3613 if (sym->component_access == ACCESS_PRIVATE
3614 || c->attr.access == ACCESS_PRIVATE
3615 || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.private_comp))
3616 sym->attr.private_comp = 1;
3617
3618 if (lockp) *lockp = lock_comp;
3619 if (eventp) *eventp = event_comp;
3620 }
3621
3622
3623 static void parse_struct_map (gfc_statement);
3624
3625 /* Parse a union component definition within a structure definition. */
3626
3627 static void
3628 parse_union (void)
3629 {
3630 int compiling;
3631 gfc_statement st;
3632 gfc_state_data s;
3633 gfc_component *c, *lock_comp = NULL, *event_comp = NULL;
3634 gfc_symbol *un;
3635
3636 accept_statement(ST_UNION);
3637 push_state (&s, COMP_UNION, gfc_new_block);
3638 un = gfc_new_block;
3639
3640 compiling = 1;
3641
3642 while (compiling)
3643 {
3644 st = next_statement ();
3645 /* Only MAP declarations valid within a union. */
3646 switch (st)
3647 {
3648 case ST_NONE:
3649 unexpected_eof ();
3650
3651 case ST_MAP:
3652 accept_statement (ST_MAP);
3653 parse_struct_map (ST_MAP);
3654 /* Add a component to the union for each map. */
3655 if (!gfc_add_component (un, gfc_new_block->name, &c))
3656 {
3657 gfc_internal_error ("failed to create map component '%s'",
3658 gfc_new_block->name);
3659 reject_statement ();
3660 return;
3661 }
3662 c->ts.type = BT_DERIVED;
3663 c->ts.u.derived = gfc_new_block;
3664 /* Normally components get their initialization expressions when they
3665 are created in decl.cc (build_struct) so we can look through the
3666 flat component list for initializers during resolution. Unions and
3667 maps create components along with their type definitions so we
3668 have to generate initializers here. */
3669 c->initializer = gfc_default_initializer (&c->ts);
3670 break;
3671
3672 case ST_END_UNION:
3673 compiling = 0;
3674 accept_statement (ST_END_UNION);
3675 break;
3676
3677 default:
3678 unexpected_statement (st);
3679 break;
3680 }
3681 }
3682
3683 for (c = un->components; c; c = c->next)
3684 check_component (un, c, &lock_comp, &event_comp);
3685
3686 /* Add the union as a component in its parent structure. */
3687 pop_state ();
3688 if (!gfc_add_component (gfc_current_block (), un->name, &c))
3689 {
3690 gfc_internal_error ("failed to create union component '%s'", un->name);
3691 reject_statement ();
3692 return;
3693 }
3694 c->ts.type = BT_UNION;
3695 c->ts.u.derived = un;
3696 c->initializer = gfc_default_initializer (&c->ts);
3697
3698 un->attr.zero_comp = un->components == NULL;
3699 }
3700
3701
3702 /* Parse a STRUCTURE or MAP. */
3703
3704 static void
3705 parse_struct_map (gfc_statement block)
3706 {
3707 int compiling_type;
3708 gfc_statement st;
3709 gfc_state_data s;
3710 gfc_symbol *sym;
3711 gfc_component *c, *lock_comp = NULL, *event_comp = NULL;
3712 gfc_compile_state comp;
3713 gfc_statement ends;
3714
3715 if (block == ST_STRUCTURE_DECL)
3716 {
3717 comp = COMP_STRUCTURE;
3718 ends = ST_END_STRUCTURE;
3719 }
3720 else
3721 {
3722 gcc_assert (block == ST_MAP);
3723 comp = COMP_MAP;
3724 ends = ST_END_MAP;
3725 }
3726
3727 accept_statement(block);
3728 push_state (&s, comp, gfc_new_block);
3729
3730 gfc_new_block->component_access = ACCESS_PUBLIC;
3731 compiling_type = 1;
3732
3733 while (compiling_type)
3734 {
3735 st = next_statement ();
3736 switch (st)
3737 {
3738 case ST_NONE:
3739 unexpected_eof ();
3740
3741 /* Nested structure declarations will be captured as ST_DATA_DECL. */
3742 case ST_STRUCTURE_DECL:
3743 /* Let a more specific error make it to decode_statement(). */
3744 if (gfc_error_check () == 0)
3745 gfc_error ("Syntax error in nested structure declaration at %C");
3746 reject_statement ();
3747 /* Skip the rest of this statement. */
3748 gfc_error_recovery ();
3749 break;
3750
3751 case ST_UNION:
3752 accept_statement (ST_UNION);
3753 parse_union ();
3754 break;
3755
3756 case ST_DATA_DECL:
3757 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
3758 accept_statement (ST_DATA_DECL);
3759 if (gfc_new_block && gfc_new_block != gfc_current_block ()
3760 && gfc_new_block->attr.flavor == FL_STRUCT)
3761 parse_struct_map (ST_STRUCTURE_DECL);
3762 break;
3763
3764 case ST_END_STRUCTURE:
3765 case ST_END_MAP:
3766 if (st == ends)
3767 {
3768 accept_statement (st);
3769 compiling_type = 0;
3770 }
3771 else
3772 unexpected_statement (st);
3773 break;
3774
3775 default:
3776 unexpected_statement (st);
3777 break;
3778 }
3779 }
3780
3781 /* Validate each component. */
3782 sym = gfc_current_block ();
3783 for (c = sym->components; c; c = c->next)
3784 check_component (sym, c, &lock_comp, &event_comp);
3785
3786 sym->attr.zero_comp = (sym->components == NULL);
3787
3788 /* Allow parse_union to find this structure to add to its list of maps. */
3789 if (block == ST_MAP)
3790 gfc_new_block = gfc_current_block ();
3791
3792 pop_state ();
3793 }
3794
3795
3796 /* Parse a derived type. */
3797
3798 static void
3799 parse_derived (void)
3800 {
3801 int compiling_type, seen_private, seen_sequence, seen_component;
3802 gfc_statement st;
3803 gfc_state_data s;
3804 gfc_symbol *sym;
3805 gfc_component *c, *lock_comp = NULL, *event_comp = NULL;
3806
3807 accept_statement (ST_DERIVED_DECL);
3808 push_state (&s, COMP_DERIVED, gfc_new_block);
3809
3810 gfc_new_block->component_access = ACCESS_PUBLIC;
3811 seen_private = 0;
3812 seen_sequence = 0;
3813 seen_component = 0;
3814
3815 compiling_type = 1;
3816
3817 while (compiling_type)
3818 {
3819 st = next_statement ();
3820 switch (st)
3821 {
3822 case ST_NONE:
3823 unexpected_eof ();
3824
3825 case ST_DATA_DECL:
3826 case ST_PROCEDURE:
3827 accept_statement (st);
3828 seen_component = 1;
3829 break;
3830
3831 case ST_FINAL:
3832 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3833 break;
3834
3835 case ST_END_TYPE:
3836 endType:
3837 compiling_type = 0;
3838
3839 if (!seen_component)
3840 gfc_notify_std (GFC_STD_F2003, "Derived type "
3841 "definition at %C without components");
3842
3843 accept_statement (ST_END_TYPE);
3844 break;
3845
3846 case ST_PRIVATE:
3847 if (!gfc_find_state (COMP_MODULE))
3848 {
3849 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3850 "a MODULE");
3851 break;
3852 }
3853
3854 if (seen_component)
3855 {
3856 gfc_error ("PRIVATE statement at %C must precede "
3857 "structure components");
3858 break;
3859 }
3860
3861 if (seen_private)
3862 gfc_error ("Duplicate PRIVATE statement at %C");
3863
3864 s.sym->component_access = ACCESS_PRIVATE;
3865
3866 accept_statement (ST_PRIVATE);
3867 seen_private = 1;
3868 break;
3869
3870 case ST_SEQUENCE:
3871 if (seen_component)
3872 {
3873 gfc_error ("SEQUENCE statement at %C must precede "
3874 "structure components");
3875 break;
3876 }
3877
3878 if (gfc_current_block ()->attr.sequence)
3879 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
3880 "TYPE statement");
3881
3882 if (seen_sequence)
3883 {
3884 gfc_error ("Duplicate SEQUENCE statement at %C");
3885 }
3886
3887 seen_sequence = 1;
3888 gfc_add_sequence (&gfc_current_block ()->attr,
3889 gfc_current_block ()->name, NULL);
3890 break;
3891
3892 case ST_CONTAINS:
3893 gfc_notify_std (GFC_STD_F2003,
3894 "CONTAINS block in derived type"
3895 " definition at %C");
3896
3897 accept_statement (ST_CONTAINS);
3898 parse_derived_contains ();
3899 goto endType;
3900
3901 default:
3902 unexpected_statement (st);
3903 break;
3904 }
3905 }
3906
3907 /* need to verify that all fields of the derived type are
3908 * interoperable with C if the type is declared to be bind(c)
3909 */
3910 sym = gfc_current_block ();
3911 for (c = sym->components; c; c = c->next)
3912 check_component (sym, c, &lock_comp, &event_comp);
3913
3914 if (!seen_component)
3915 sym->attr.zero_comp = 1;
3916
3917 pop_state ();
3918 }
3919
3920
3921 /* Parse an ENUM. */
3922
3923 static void
3924 parse_enum (void)
3925 {
3926 gfc_statement st;
3927 int compiling_enum;
3928 gfc_state_data s;
3929 int seen_enumerator = 0;
3930
3931 push_state (&s, COMP_ENUM, gfc_new_block);
3932
3933 compiling_enum = 1;
3934
3935 while (compiling_enum)
3936 {
3937 st = next_statement ();
3938 switch (st)
3939 {
3940 case ST_NONE:
3941 unexpected_eof ();
3942 break;
3943
3944 case ST_ENUMERATOR:
3945 seen_enumerator = 1;
3946 accept_statement (st);
3947 break;
3948
3949 case ST_END_ENUM:
3950 compiling_enum = 0;
3951 if (!seen_enumerator)
3952 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
3953 accept_statement (st);
3954 break;
3955
3956 default:
3957 gfc_free_enum_history ();
3958 unexpected_statement (st);
3959 break;
3960 }
3961 }
3962 pop_state ();
3963 }
3964
3965
3966 /* Parse an interface. We must be able to deal with the possibility
3967 of recursive interfaces. The parse_spec() subroutine is mutually
3968 recursive with parse_interface(). */
3969
3970 static gfc_statement parse_spec (gfc_statement);
3971
3972 static void
3973 parse_interface (void)
3974 {
3975 gfc_compile_state new_state = COMP_NONE, current_state;
3976 gfc_symbol *prog_unit, *sym;
3977 gfc_interface_info save;
3978 gfc_state_data s1, s2;
3979 gfc_statement st;
3980
3981 accept_statement (ST_INTERFACE);
3982
3983 current_interface.ns = gfc_current_ns;
3984 save = current_interface;
3985
3986 sym = (current_interface.type == INTERFACE_GENERIC
3987 || current_interface.type == INTERFACE_USER_OP)
3988 ? gfc_new_block : NULL;
3989
3990 push_state (&s1, COMP_INTERFACE, sym);
3991 current_state = COMP_NONE;
3992
3993 loop:
3994 gfc_current_ns = gfc_get_namespace (current_interface.ns, 0);
3995
3996 st = next_statement ();
3997 switch (st)
3998 {
3999 case ST_NONE:
4000 unexpected_eof ();
4001
4002 case ST_SUBROUTINE:
4003 case ST_FUNCTION:
4004 if (st == ST_SUBROUTINE)
4005 new_state = COMP_SUBROUTINE;
4006 else if (st == ST_FUNCTION)
4007 new_state = COMP_FUNCTION;
4008 if (gfc_new_block->attr.pointer)
4009 {
4010 gfc_new_block->attr.pointer = 0;
4011 gfc_new_block->attr.proc_pointer = 1;
4012 }
4013 if (!gfc_add_explicit_interface (gfc_new_block, IFSRC_IFBODY,
4014 gfc_new_block->formal, NULL))
4015 {
4016 reject_statement ();
4017 gfc_free_namespace (gfc_current_ns);
4018 goto loop;
4019 }
4020 /* F2008 C1210 forbids the IMPORT statement in module procedure
4021 interface bodies and the flag is set to import symbols. */
4022 if (gfc_new_block->attr.module_procedure)
4023 gfc_current_ns->has_import_set = 1;
4024 break;
4025
4026 case ST_PROCEDURE:
4027 case ST_MODULE_PROC: /* The module procedure matcher makes
4028 sure the context is correct. */
4029 accept_statement (st);
4030 gfc_free_namespace (gfc_current_ns);
4031 goto loop;
4032
4033 case ST_END_INTERFACE:
4034 gfc_free_namespace (gfc_current_ns);
4035 gfc_current_ns = current_interface.ns;
4036 goto done;
4037
4038 default:
4039 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
4040 gfc_ascii_statement (st));
4041 reject_statement ();
4042 gfc_free_namespace (gfc_current_ns);
4043 goto loop;
4044 }
4045
4046
4047 /* Make sure that the generic name has the right attribute. */
4048 if (current_interface.type == INTERFACE_GENERIC
4049 && current_state == COMP_NONE)
4050 {
4051 if (new_state == COMP_FUNCTION && sym)
4052 gfc_add_function (&sym->attr, sym->name, NULL);
4053 else if (new_state == COMP_SUBROUTINE && sym)
4054 gfc_add_subroutine (&sym->attr, sym->name, NULL);
4055
4056 current_state = new_state;
4057 }
4058
4059 if (current_interface.type == INTERFACE_ABSTRACT)
4060 {
4061 gfc_add_abstract (&gfc_new_block->attr, &gfc_current_locus);
4062 if (gfc_is_intrinsic_typename (gfc_new_block->name))
4063 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
4064 "cannot be the same as an intrinsic type",
4065 gfc_new_block->name);
4066 }
4067
4068 push_state (&s2, new_state, gfc_new_block);
4069 accept_statement (st);
4070 prog_unit = gfc_new_block;
4071 prog_unit->formal_ns = gfc_current_ns;
4072
4073 decl:
4074 /* Read data declaration statements. */
4075 st = parse_spec (ST_NONE);
4076 in_specification_block = true;
4077
4078 /* Since the interface block does not permit an IMPLICIT statement,
4079 the default type for the function or the result must be taken
4080 from the formal namespace. */
4081 if (new_state == COMP_FUNCTION)
4082 {
4083 if (prog_unit->result == prog_unit
4084 && prog_unit->ts.type == BT_UNKNOWN)
4085 gfc_set_default_type (prog_unit, 1, prog_unit->formal_ns);
4086 else if (prog_unit->result != prog_unit
4087 && prog_unit->result->ts.type == BT_UNKNOWN)
4088 gfc_set_default_type (prog_unit->result, 1,
4089 prog_unit->formal_ns);
4090 }
4091
4092 if (st != ST_END_SUBROUTINE && st != ST_END_FUNCTION)
4093 {
4094 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
4095 gfc_ascii_statement (st));
4096 reject_statement ();
4097 goto decl;
4098 }
4099
4100 /* Add EXTERNAL attribute to function or subroutine. */
4101 if (current_interface.type != INTERFACE_ABSTRACT && !prog_unit->attr.dummy)
4102 gfc_add_external (&prog_unit->attr, &gfc_current_locus);
4103
4104 current_interface = save;
4105 gfc_add_interface (prog_unit);
4106 pop_state ();
4107
4108 if (current_interface.ns
4109 && current_interface.ns->proc_name
4110 && strcmp (current_interface.ns->proc_name->name,
4111 prog_unit->name) == 0)
4112 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
4113 "enclosing procedure", prog_unit->name,
4114 &current_interface.ns->proc_name->declared_at);
4115
4116 goto loop;
4117
4118 done:
4119 pop_state ();
4120 }
4121
4122
4123 /* Associate function characteristics by going back to the function
4124 declaration and rematching the prefix. */
4125
4126 static match
4127 match_deferred_characteristics (gfc_typespec * ts)
4128 {
4129 locus loc;
4130 match m = MATCH_ERROR;
4131 char name[GFC_MAX_SYMBOL_LEN + 1];
4132
4133 loc = gfc_current_locus;
4134
4135 gfc_current_locus = gfc_current_block ()->declared_at;
4136
4137 gfc_clear_error ();
4138 gfc_buffer_error (true);
4139 m = gfc_match_prefix (ts);
4140 gfc_buffer_error (false);
4141
4142 if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
4143 {
4144 ts->kind = 0;
4145
4146 if (!ts->u.derived)
4147 m = MATCH_ERROR;
4148 }
4149
4150 /* Only permit one go at the characteristic association. */
4151 if (ts->kind == -1)
4152 ts->kind = 0;
4153
4154 /* Set the function locus correctly. If we have not found the
4155 function name, there is an error. */
4156 if (m == MATCH_YES
4157 && gfc_match ("function% %n", name) == MATCH_YES
4158 && strcmp (name, gfc_current_block ()->name) == 0)
4159 {
4160 gfc_current_block ()->declared_at = gfc_current_locus;
4161 gfc_commit_symbols ();
4162 }
4163 else
4164 {
4165 gfc_error_check ();
4166 gfc_undo_symbols ();
4167 }
4168
4169 gfc_current_locus =loc;
4170 return m;
4171 }
4172
4173
4174 /* Check specification-expressions in the function result of the currently
4175 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
4176 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
4177 scope are not yet parsed so this has to be delayed up to parse_spec. */
4178
4179 static bool
4180 check_function_result_typed (void)
4181 {
4182 gfc_typespec ts;
4183
4184 gcc_assert (gfc_current_state () == COMP_FUNCTION);
4185
4186 if (!gfc_current_ns->proc_name->result)
4187 return true;
4188
4189 ts = gfc_current_ns->proc_name->result->ts;
4190
4191 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
4192 /* TODO: Extend when KIND type parameters are implemented. */
4193 if (ts.type == BT_CHARACTER && ts.u.cl && ts.u.cl->length)
4194 {
4195 /* Reject invalid type of specification expression for length. */
4196 if (ts.u.cl->length->ts.type != BT_INTEGER)
4197 return false;
4198
4199 gfc_expr_check_typed (ts.u.cl->length, gfc_current_ns, true);
4200 }
4201
4202 return true;
4203 }
4204
4205
4206 /* Parse a set of specification statements. Returns the statement
4207 that doesn't fit. */
4208
4209 static gfc_statement
4210 parse_spec (gfc_statement st)
4211 {
4212 st_state ss;
4213 bool function_result_typed = false;
4214 bool bad_characteristic = false;
4215 gfc_typespec *ts;
4216
4217 in_specification_block = true;
4218
4219 verify_st_order (&ss, ST_NONE, false);
4220 if (st == ST_NONE)
4221 st = next_statement ();
4222
4223 /* If we are not inside a function or don't have a result specified so far,
4224 do nothing special about it. */
4225 if (gfc_current_state () != COMP_FUNCTION)
4226 function_result_typed = true;
4227 else
4228 {
4229 gfc_symbol* proc = gfc_current_ns->proc_name;
4230 gcc_assert (proc);
4231
4232 if (proc->result && proc->result->ts.type == BT_UNKNOWN)
4233 function_result_typed = true;
4234 }
4235
4236 loop:
4237
4238 /* If we're inside a BLOCK construct, some statements are disallowed.
4239 Check this here. Attribute declaration statements like INTENT, OPTIONAL
4240 or VALUE are also disallowed, but they don't have a particular ST_*
4241 key so we have to check for them individually in their matcher routine. */
4242 if (gfc_current_state () == COMP_BLOCK)
4243 switch (st)
4244 {
4245 case ST_IMPLICIT:
4246 case ST_IMPLICIT_NONE:
4247 case ST_NAMELIST:
4248 case ST_COMMON:
4249 case ST_EQUIVALENCE:
4250 case ST_STATEMENT_FUNCTION:
4251 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
4252 gfc_ascii_statement (st));
4253 reject_statement ();
4254 break;
4255
4256 default:
4257 break;
4258 }
4259 else if (gfc_current_state () == COMP_BLOCK_DATA)
4260 /* Fortran 2008, C1116. */
4261 switch (st)
4262 {
4263 case ST_ATTR_DECL:
4264 case ST_COMMON:
4265 case ST_DATA:
4266 case ST_DATA_DECL:
4267 case ST_DERIVED_DECL:
4268 case ST_END_BLOCK_DATA:
4269 case ST_EQUIVALENCE:
4270 case ST_IMPLICIT:
4271 case ST_IMPLICIT_NONE:
4272 case ST_OMP_THREADPRIVATE:
4273 case ST_PARAMETER:
4274 case ST_STRUCTURE_DECL:
4275 case ST_TYPE:
4276 case ST_USE:
4277 break;
4278
4279 case ST_NONE:
4280 break;
4281
4282 default:
4283 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
4284 gfc_ascii_statement (st));
4285 reject_statement ();
4286 break;
4287 }
4288
4289 /* If we find a statement that cannot be followed by an IMPLICIT statement
4290 (and thus we can expect to see none any further), type the function result
4291 if it has not yet been typed. Be careful not to give the END statement
4292 to verify_st_order! */
4293 if (!function_result_typed && st != ST_GET_FCN_CHARACTERISTICS)
4294 {
4295 bool verify_now = false;
4296
4297 if (st == ST_END_FUNCTION || st == ST_CONTAINS)
4298 verify_now = true;
4299 else
4300 {
4301 st_state dummyss;
4302 verify_st_order (&dummyss, ST_NONE, false);
4303 verify_st_order (&dummyss, st, false);
4304
4305 if (!verify_st_order (&dummyss, ST_IMPLICIT, true))
4306 verify_now = true;
4307 }
4308
4309 if (verify_now)
4310 function_result_typed = check_function_result_typed ();
4311 }
4312
4313 switch (st)
4314 {
4315 case ST_NONE:
4316 unexpected_eof ();
4317
4318 case ST_IMPLICIT_NONE:
4319 case ST_IMPLICIT:
4320 if (!function_result_typed)
4321 function_result_typed = check_function_result_typed ();
4322 goto declSt;
4323
4324 case ST_FORMAT:
4325 case ST_ENTRY:
4326 case ST_DATA: /* Not allowed in interfaces */
4327 if (gfc_current_state () == COMP_INTERFACE)
4328 break;
4329
4330 /* Fall through */
4331
4332 case ST_USE:
4333 case ST_IMPORT:
4334 case ST_PARAMETER:
4335 case ST_PUBLIC:
4336 case ST_PRIVATE:
4337 case ST_STRUCTURE_DECL:
4338 case ST_DERIVED_DECL:
4339 case_decl:
4340 case_omp_decl:
4341 declSt:
4342 if (!verify_st_order (&ss, st, false))
4343 {
4344 reject_statement ();
4345 st = next_statement ();
4346 goto loop;
4347 }
4348
4349 switch (st)
4350 {
4351 case ST_INTERFACE:
4352 parse_interface ();
4353 break;
4354
4355 case ST_STRUCTURE_DECL:
4356 parse_struct_map (ST_STRUCTURE_DECL);
4357 break;
4358
4359 case ST_DERIVED_DECL:
4360 parse_derived ();
4361 break;
4362
4363 case ST_PUBLIC:
4364 case ST_PRIVATE:
4365 if (gfc_current_state () != COMP_MODULE)
4366 {
4367 gfc_error ("%s statement must appear in a MODULE",
4368 gfc_ascii_statement (st));
4369 reject_statement ();
4370 break;
4371 }
4372
4373 if (gfc_current_ns->default_access != ACCESS_UNKNOWN)
4374 {
4375 gfc_error ("%s statement at %C follows another accessibility "
4376 "specification", gfc_ascii_statement (st));
4377 reject_statement ();
4378 break;
4379 }
4380
4381 gfc_current_ns->default_access = (st == ST_PUBLIC)
4382 ? ACCESS_PUBLIC : ACCESS_PRIVATE;
4383
4384 break;
4385
4386 case ST_STATEMENT_FUNCTION:
4387 if (gfc_current_state () == COMP_MODULE
4388 || gfc_current_state () == COMP_SUBMODULE)
4389 {
4390 unexpected_statement (st);
4391 break;
4392 }
4393
4394 default:
4395 break;
4396 }
4397
4398 accept_statement (st);
4399 st = next_statement ();
4400 goto loop;
4401
4402 case ST_ENUM:
4403 accept_statement (st);
4404 parse_enum();
4405 st = next_statement ();
4406 goto loop;
4407
4408 case ST_GET_FCN_CHARACTERISTICS:
4409 /* This statement triggers the association of a function's result
4410 characteristics. */
4411 ts = &gfc_current_block ()->result->ts;
4412 if (match_deferred_characteristics (ts) != MATCH_YES)
4413 bad_characteristic = true;
4414
4415 st = next_statement ();
4416 goto loop;
4417
4418 default:
4419 break;
4420 }
4421
4422 /* If match_deferred_characteristics failed, then there is an error. */
4423 if (bad_characteristic)
4424 {
4425 ts = &gfc_current_block ()->result->ts;
4426 if (ts->type != BT_DERIVED && ts->type != BT_CLASS)
4427 gfc_error ("Bad kind expression for function %qs at %L",
4428 gfc_current_block ()->name,
4429 &gfc_current_block ()->declared_at);
4430 else
4431 gfc_error ("The type for function %qs at %L is not accessible",
4432 gfc_current_block ()->name,
4433 &gfc_current_block ()->declared_at);
4434
4435 gfc_current_block ()->ts.kind = 0;
4436 /* Keep the derived type; if it's bad, it will be discovered later. */
4437 if (!(ts->type == BT_DERIVED && ts->u.derived))
4438 ts->type = BT_UNKNOWN;
4439 }
4440
4441 in_specification_block = false;
4442
4443 return st;
4444 }
4445
4446
4447 /* Parse a WHERE block, (not a simple WHERE statement). */
4448
4449 static void
4450 parse_where_block (void)
4451 {
4452 int seen_empty_else;
4453 gfc_code *top, *d;
4454 gfc_state_data s;
4455 gfc_statement st;
4456
4457 accept_statement (ST_WHERE_BLOCK);
4458 top = gfc_state_stack->tail;
4459
4460 push_state (&s, COMP_WHERE, gfc_new_block);
4461
4462 d = add_statement ();
4463 d->expr1 = top->expr1;
4464 d->op = EXEC_WHERE;
4465
4466 top->expr1 = NULL;
4467 top->block = d;
4468
4469 seen_empty_else = 0;
4470
4471 do
4472 {
4473 st = next_statement ();
4474 switch (st)
4475 {
4476 case ST_NONE:
4477 unexpected_eof ();
4478
4479 case ST_WHERE_BLOCK:
4480 parse_where_block ();
4481 break;
4482
4483 case ST_ASSIGNMENT:
4484 case ST_WHERE:
4485 accept_statement (st);
4486 break;
4487
4488 case ST_ELSEWHERE:
4489 if (seen_empty_else)
4490 {
4491 gfc_error ("ELSEWHERE statement at %C follows previous "
4492 "unmasked ELSEWHERE");
4493 reject_statement ();
4494 break;
4495 }
4496
4497 if (new_st.expr1 == NULL)
4498 seen_empty_else = 1;
4499
4500 d = new_level (gfc_state_stack->head);
4501 d->op = EXEC_WHERE;
4502 d->expr1 = new_st.expr1;
4503
4504 accept_statement (st);
4505
4506 break;
4507
4508 case ST_END_WHERE:
4509 accept_statement (st);
4510 break;
4511
4512 default:
4513 gfc_error ("Unexpected %s statement in WHERE block at %C",
4514 gfc_ascii_statement (st));
4515 reject_statement ();
4516 break;
4517 }
4518 }
4519 while (st != ST_END_WHERE);
4520
4521 pop_state ();
4522 }
4523
4524
4525 /* Parse a FORALL block (not a simple FORALL statement). */
4526
4527 static void
4528 parse_forall_block (void)
4529 {
4530 gfc_code *top, *d;
4531 gfc_state_data s;
4532 gfc_statement st;
4533
4534 accept_statement (ST_FORALL_BLOCK);
4535 top = gfc_state_stack->tail;
4536
4537 push_state (&s, COMP_FORALL, gfc_new_block);
4538
4539 d = add_statement ();
4540 d->op = EXEC_FORALL;
4541 top->block = d;
4542
4543 do
4544 {
4545 st = next_statement ();
4546 switch (st)
4547 {
4548
4549 case ST_ASSIGNMENT:
4550 case ST_POINTER_ASSIGNMENT:
4551 case ST_WHERE:
4552 case ST_FORALL:
4553 accept_statement (st);
4554 break;
4555
4556 case ST_WHERE_BLOCK:
4557 parse_where_block ();
4558 break;
4559
4560 case ST_FORALL_BLOCK:
4561 parse_forall_block ();
4562 break;
4563
4564 case ST_END_FORALL:
4565 accept_statement (st);
4566 break;
4567
4568 case ST_NONE:
4569 unexpected_eof ();
4570
4571 default:
4572 gfc_error ("Unexpected %s statement in FORALL block at %C",
4573 gfc_ascii_statement (st));
4574
4575 reject_statement ();
4576 break;
4577 }
4578 }
4579 while (st != ST_END_FORALL);
4580
4581 pop_state ();
4582 }
4583
4584
4585 static gfc_statement parse_executable (gfc_statement);
4586
4587 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
4588
4589 static void
4590 parse_if_block (void)
4591 {
4592 gfc_code *top, *d;
4593 gfc_statement st;
4594 locus else_locus;
4595 gfc_state_data s;
4596 int seen_else;
4597
4598 seen_else = 0;
4599 accept_statement (ST_IF_BLOCK);
4600
4601 top = gfc_state_stack->tail;
4602 push_state (&s, COMP_IF, gfc_new_block);
4603
4604 new_st.op = EXEC_IF;
4605 d = add_statement ();
4606
4607 d->expr1 = top->expr1;
4608 top->expr1 = NULL;
4609 top->block = d;
4610
4611 do
4612 {
4613 st = parse_executable (ST_NONE);
4614
4615 switch (st)
4616 {
4617 case ST_NONE:
4618 unexpected_eof ();
4619
4620 case ST_ELSEIF:
4621 if (seen_else)
4622 {
4623 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
4624 "statement at %L", &else_locus);
4625
4626 reject_statement ();
4627 break;
4628 }
4629
4630 d = new_level (gfc_state_stack->head);
4631 d->op = EXEC_IF;
4632 d->expr1 = new_st.expr1;
4633
4634 accept_statement (st);
4635
4636 break;
4637
4638 case ST_ELSE:
4639 if (seen_else)
4640 {
4641 gfc_error ("Duplicate ELSE statements at %L and %C",
4642 &else_locus);
4643 reject_statement ();
4644 break;
4645 }
4646
4647 seen_else = 1;
4648 else_locus = gfc_current_locus;
4649
4650 d = new_level (gfc_state_stack->head);
4651 d->op = EXEC_IF;
4652
4653 accept_statement (st);
4654
4655 break;
4656
4657 case ST_ENDIF:
4658 break;
4659
4660 default:
4661 unexpected_statement (st);
4662 break;
4663 }
4664 }
4665 while (st != ST_ENDIF);
4666
4667 pop_state ();
4668 accept_statement (st);
4669 }
4670
4671
4672 /* Parse a SELECT block. */
4673
4674 static void
4675 parse_select_block (void)
4676 {
4677 gfc_statement st;
4678 gfc_code *cp;
4679 gfc_state_data s;
4680
4681 accept_statement (ST_SELECT_CASE);
4682
4683 cp = gfc_state_stack->tail;
4684 push_state (&s, COMP_SELECT, gfc_new_block);
4685
4686 /* Make sure that the next statement is a CASE or END SELECT. */
4687 for (;;)
4688 {
4689 st = next_statement ();
4690 if (st == ST_NONE)
4691 unexpected_eof ();
4692 if (st == ST_END_SELECT)
4693 {
4694 /* Empty SELECT CASE is OK. */
4695 accept_statement (st);
4696 pop_state ();
4697 return;
4698 }
4699 if (st == ST_CASE)
4700 break;
4701
4702 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
4703 "CASE at %C");
4704
4705 reject_statement ();
4706 }
4707
4708 /* At this point, we've got a nonempty select block. */
4709 cp = new_level (cp);
4710 *cp = new_st;
4711
4712 accept_statement (st);
4713
4714 do
4715 {
4716 st = parse_executable (ST_NONE);
4717 switch (st)
4718 {
4719 case ST_NONE:
4720 unexpected_eof ();
4721
4722 case ST_CASE:
4723 cp = new_level (gfc_state_stack->head);
4724 *cp = new_st;
4725 gfc_clear_new_st ();
4726
4727 accept_statement (st);
4728 /* Fall through */
4729
4730 case ST_END_SELECT:
4731 break;
4732
4733 /* Can't have an executable statement because of
4734 parse_executable(). */
4735 default:
4736 unexpected_statement (st);
4737 break;
4738 }
4739 }
4740 while (st != ST_END_SELECT);
4741
4742 pop_state ();
4743 accept_statement (st);
4744 }
4745
4746
4747 /* Pop the current selector from the SELECT TYPE stack. */
4748
4749 static void
4750 select_type_pop (void)
4751 {
4752 gfc_select_type_stack *old = select_type_stack;
4753 select_type_stack = old->prev;
4754 free (old);
4755 }
4756
4757
4758 /* Parse a SELECT TYPE construct (F03:R821). */
4759
4760 static void
4761 parse_select_type_block (void)
4762 {
4763 gfc_statement st;
4764 gfc_code *cp;
4765 gfc_state_data s;
4766
4767 gfc_current_ns = new_st.ext.block.ns;
4768 accept_statement (ST_SELECT_TYPE);
4769
4770 cp = gfc_state_stack->tail;
4771 push_state (&s, COMP_SELECT_TYPE, gfc_new_block);
4772
4773 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4774 or END SELECT. */
4775 for (;;)
4776 {
4777 st = next_statement ();
4778 if (st == ST_NONE)
4779 unexpected_eof ();
4780 if (st == ST_END_SELECT)
4781 /* Empty SELECT CASE is OK. */
4782 goto done;
4783 if (st == ST_TYPE_IS || st == ST_CLASS_IS)
4784 break;
4785
4786 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4787 "following SELECT TYPE at %C");
4788
4789 reject_statement ();
4790 }
4791
4792 /* At this point, we've got a nonempty select block. */
4793 cp = new_level (cp);
4794 *cp = new_st;
4795
4796 accept_statement (st);
4797
4798 do
4799 {
4800 st = parse_executable (ST_NONE);
4801 switch (st)
4802 {
4803 case ST_NONE:
4804 unexpected_eof ();
4805
4806 case ST_TYPE_IS:
4807 case ST_CLASS_IS:
4808 cp = new_level (gfc_state_stack->head);
4809 *cp = new_st;
4810 gfc_clear_new_st ();
4811
4812 accept_statement (st);
4813 /* Fall through */
4814
4815 case ST_END_SELECT:
4816 break;
4817
4818 /* Can't have an executable statement because of
4819 parse_executable(). */
4820 default:
4821 unexpected_statement (st);
4822 break;
4823 }
4824 }
4825 while (st != ST_END_SELECT);
4826
4827 done:
4828 pop_state ();
4829 accept_statement (st);
4830 gfc_current_ns = gfc_current_ns->parent;
4831 select_type_pop ();
4832 }
4833
4834
4835 /* Parse a SELECT RANK construct. */
4836
4837 static void
4838 parse_select_rank_block (void)
4839 {
4840 gfc_statement st;
4841 gfc_code *cp;
4842 gfc_state_data s;
4843
4844 gfc_current_ns = new_st.ext.block.ns;
4845 accept_statement (ST_SELECT_RANK);
4846
4847 cp = gfc_state_stack->tail;
4848 push_state (&s, COMP_SELECT_RANK, gfc_new_block);
4849
4850 /* Make sure that the next statement is a RANK IS or RANK DEFAULT. */
4851 for (;;)
4852 {
4853 st = next_statement ();
4854 if (st == ST_NONE)
4855 unexpected_eof ();
4856 if (st == ST_END_SELECT)
4857 /* Empty SELECT CASE is OK. */
4858 goto done;
4859 if (st == ST_RANK)
4860 break;
4861
4862 gfc_error ("Expected RANK or RANK DEFAULT "
4863 "following SELECT RANK at %C");
4864
4865 reject_statement ();
4866 }
4867
4868 /* At this point, we've got a nonempty select block. */
4869 cp = new_level (cp);
4870 *cp = new_st;
4871
4872 accept_statement (st);
4873
4874 do
4875 {
4876 st = parse_executable (ST_NONE);
4877 switch (st)
4878 {
4879 case ST_NONE:
4880 unexpected_eof ();
4881
4882 case ST_RANK:
4883 cp = new_level (gfc_state_stack->head);
4884 *cp = new_st;
4885 gfc_clear_new_st ();
4886
4887 accept_statement (st);
4888 /* Fall through */
4889
4890 case ST_END_SELECT:
4891 break;
4892
4893 /* Can't have an executable statement because of
4894 parse_executable(). */
4895 default:
4896 unexpected_statement (st);
4897 break;
4898 }
4899 }
4900 while (st != ST_END_SELECT);
4901
4902 done:
4903 pop_state ();
4904 accept_statement (st);
4905 gfc_current_ns = gfc_current_ns->parent;
4906 select_type_pop ();
4907 }
4908
4909
4910 /* Given a symbol, make sure it is not an iteration variable for a DO
4911 statement. This subroutine is called when the symbol is seen in a
4912 context that causes it to become redefined. If the symbol is an
4913 iterator, we generate an error message and return nonzero. */
4914
4915 bool
4916 gfc_check_do_variable (gfc_symtree *st)
4917 {
4918 gfc_state_data *s;
4919
4920 if (!st)
4921 return 0;
4922
4923 for (s=gfc_state_stack; s; s = s->previous)
4924 if (s->do_variable == st)
4925 {
4926 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
4927 "loop beginning at %L", st->name, &s->head->loc);
4928 return 1;
4929 }
4930
4931 return 0;
4932 }
4933
4934
4935 /* Checks to see if the current statement label closes an enddo.
4936 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
4937 an error) if it incorrectly closes an ENDDO. */
4938
4939 static int
4940 check_do_closure (void)
4941 {
4942 gfc_state_data *p;
4943
4944 if (gfc_statement_label == NULL)
4945 return 0;
4946
4947 for (p = gfc_state_stack; p; p = p->previous)
4948 if (p->state == COMP_DO || p->state == COMP_DO_CONCURRENT)
4949 break;
4950
4951 if (p == NULL)
4952 return 0; /* No loops to close */
4953
4954 if (p->ext.end_do_label == gfc_statement_label)
4955 {
4956 if (p == gfc_state_stack)
4957 return 1;
4958
4959 gfc_error ("End of nonblock DO statement at %C is within another block");
4960 return 2;
4961 }
4962
4963 /* At this point, the label doesn't terminate the innermost loop.
4964 Make sure it doesn't terminate another one. */
4965 for (; p; p = p->previous)
4966 if ((p->state == COMP_DO || p->state == COMP_DO_CONCURRENT)
4967 && p->ext.end_do_label == gfc_statement_label)
4968 {
4969 gfc_error ("End of nonblock DO statement at %C is interwoven "
4970 "with another DO loop");
4971 return 2;
4972 }
4973
4974 return 0;
4975 }
4976
4977
4978 /* Parse a series of contained program units. */
4979
4980 static void parse_progunit (gfc_statement);
4981
4982
4983 /* Parse a CRITICAL block. */
4984
4985 static void
4986 parse_critical_block (void)
4987 {
4988 gfc_code *top, *d;
4989 gfc_state_data s, *sd;
4990 gfc_statement st;
4991
4992 for (sd = gfc_state_stack; sd; sd = sd->previous)
4993 if (sd->state == COMP_OMP_STRUCTURED_BLOCK)
4994 gfc_error_now (is_oacc (sd)
4995 ? G_("CRITICAL block inside of OpenACC region at %C")
4996 : G_("CRITICAL block inside of OpenMP region at %C"));
4997
4998 s.ext.end_do_label = new_st.label1;
4999
5000 accept_statement (ST_CRITICAL);
5001 top = gfc_state_stack->tail;
5002
5003 push_state (&s, COMP_CRITICAL, gfc_new_block);
5004
5005 d = add_statement ();
5006 d->op = EXEC_CRITICAL;
5007 top->block = d;
5008
5009 do
5010 {
5011 st = parse_executable (ST_NONE);
5012
5013 switch (st)
5014 {
5015 case ST_NONE:
5016 unexpected_eof ();
5017 break;
5018
5019 case ST_END_CRITICAL:
5020 if (s.ext.end_do_label != NULL
5021 && s.ext.end_do_label != gfc_statement_label)
5022 gfc_error_now ("Statement label in END CRITICAL at %C does not "
5023 "match CRITICAL label");
5024
5025 if (gfc_statement_label != NULL)
5026 {
5027 new_st.op = EXEC_NOP;
5028 add_statement ();
5029 }
5030 break;
5031
5032 default:
5033 unexpected_statement (st);
5034 break;
5035 }
5036 }
5037 while (st != ST_END_CRITICAL);
5038
5039 pop_state ();
5040 accept_statement (st);
5041 }
5042
5043
5044 /* Set up the local namespace for a BLOCK construct. */
5045
5046 gfc_namespace*
5047 gfc_build_block_ns (gfc_namespace *parent_ns)
5048 {
5049 gfc_namespace* my_ns;
5050 static int numblock = 1;
5051
5052 my_ns = gfc_get_namespace (parent_ns, 1);
5053 my_ns->construct_entities = 1;
5054
5055 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
5056 code generation (so it must not be NULL).
5057 We set its recursive argument if our container procedure is recursive, so
5058 that local variables are accordingly placed on the stack when it
5059 will be necessary. */
5060 if (gfc_new_block)
5061 my_ns->proc_name = gfc_new_block;
5062 else
5063 {
5064 bool t;
5065 char buffer[20]; /* Enough to hold "block@2147483648\n". */
5066
5067 snprintf(buffer, sizeof(buffer), "block@%d", numblock++);
5068 gfc_get_symbol (buffer, my_ns, &my_ns->proc_name);
5069 t = gfc_add_flavor (&my_ns->proc_name->attr, FL_LABEL,
5070 my_ns->proc_name->name, NULL);
5071 gcc_assert (t);
5072 gfc_commit_symbol (my_ns->proc_name);
5073 }
5074
5075 if (parent_ns->proc_name)
5076 my_ns->proc_name->attr.recursive = parent_ns->proc_name->attr.recursive;
5077
5078 return my_ns;
5079 }
5080
5081
5082 /* Parse a BLOCK construct. */
5083
5084 static void
5085 parse_block_construct (void)
5086 {
5087 gfc_namespace* my_ns;
5088 gfc_namespace* my_parent;
5089 gfc_state_data s;
5090
5091 gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C");
5092
5093 my_ns = gfc_build_block_ns (gfc_current_ns);
5094
5095 new_st.op = EXEC_BLOCK;
5096 new_st.ext.block.ns = my_ns;
5097 new_st.ext.block.assoc = NULL;
5098 accept_statement (ST_BLOCK);
5099
5100 push_state (&s, COMP_BLOCK, my_ns->proc_name);
5101 gfc_current_ns = my_ns;
5102 my_parent = my_ns->parent;
5103
5104 parse_progunit (ST_NONE);
5105
5106 /* Don't depend on the value of gfc_current_ns; it might have been
5107 reset if the block had errors and was cleaned up. */
5108 gfc_current_ns = my_parent;
5109
5110 pop_state ();
5111 }
5112
5113
5114 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
5115 behind the scenes with compiler-generated variables. */
5116
5117 static void
5118 parse_associate (void)
5119 {
5120 gfc_namespace* my_ns;
5121 gfc_state_data s;
5122 gfc_statement st;
5123 gfc_association_list* a;
5124 gfc_array_spec *as;
5125
5126 gfc_notify_std (GFC_STD_F2003, "ASSOCIATE construct at %C");
5127
5128 my_ns = gfc_build_block_ns (gfc_current_ns);
5129
5130 new_st.op = EXEC_BLOCK;
5131 new_st.ext.block.ns = my_ns;
5132 gcc_assert (new_st.ext.block.assoc);
5133
5134 /* Add all associate-names as BLOCK variables. Creating them is enough
5135 for now, they'll get their values during trans-* phase. */
5136 gfc_current_ns = my_ns;
5137 for (a = new_st.ext.block.assoc; a; a = a->next)
5138 {
5139 gfc_symbol *sym, *tsym;
5140 gfc_expr *target;
5141 int rank;
5142
5143 if (gfc_get_sym_tree (a->name, NULL, &a->st, false))
5144 gcc_unreachable ();
5145
5146 sym = a->st->n.sym;
5147 sym->attr.flavor = FL_VARIABLE;
5148 sym->assoc = a;
5149 sym->declared_at = a->where;
5150 gfc_set_sym_referenced (sym);
5151
5152 /* Initialize the typespec. It is not available in all cases,
5153 however, as it may only be set on the target during resolution.
5154 Still, sometimes it helps to have it right now -- especially
5155 for parsing component references on the associate-name
5156 in case of association to a derived-type. */
5157 sym->ts = a->target->ts;
5158 target = a->target;
5159
5160 /* Don’t share the character length information between associate
5161 variable and target if the length is not a compile-time constant,
5162 as we don’t want to touch some other character length variable when
5163 we try to initialize the associate variable’s character length
5164 variable.
5165 We do it here rather than later so that expressions referencing the
5166 associate variable will automatically have the correctly setup length
5167 information. If we did it at resolution stage the expressions would
5168 use the original length information, and the variable a new different
5169 one, but only the latter one would be correctly initialized at
5170 translation stage, and the former one would need some additional setup
5171 there. */
5172 if (sym->ts.type == BT_CHARACTER
5173 && sym->ts.u.cl
5174 && !(sym->ts.u.cl->length
5175 && sym->ts.u.cl->length->expr_type == EXPR_CONSTANT))
5176 sym->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
5177
5178 /* Check if the target expression is array valued. This cannot be done
5179 by calling gfc_resolve_expr because the context is unavailable.
5180 However, the references can be resolved and the rank of the target
5181 expression set. */
5182 if (target->ref && gfc_resolve_ref (target)
5183 && target->expr_type != EXPR_ARRAY
5184 && target->expr_type != EXPR_COMPCALL)
5185 gfc_expression_rank (target);
5186
5187 /* Determine whether or not function expressions with unknown type are
5188 structure constructors. If so, the function result can be converted
5189 to be a derived type.
5190 TODO: Deal with references to sibling functions that have not yet been
5191 parsed (PRs 89645 and 99065). */
5192 if (target->expr_type == EXPR_FUNCTION && target->ts.type == BT_UNKNOWN)
5193 {
5194 gfc_symbol *derived;
5195 /* The derived type has a leading uppercase character. */
5196 gfc_find_symbol (gfc_dt_upper_string (target->symtree->name),
5197 my_ns->parent, 1, &derived);
5198 if (derived && derived->attr.flavor == FL_DERIVED)
5199 {
5200 sym->ts.type = BT_DERIVED;
5201 sym->ts.u.derived = derived;
5202 }
5203 else if (target->symtree && (tsym = target->symtree->n.sym))
5204 {
5205 sym->ts = tsym->result ? tsym->result->ts : tsym->ts;
5206 if (sym->ts.type == BT_CLASS)
5207 {
5208 if (CLASS_DATA (sym)->as)
5209 target->rank = CLASS_DATA (sym)->as->rank;
5210 sym->attr.class_ok = 1;
5211 }
5212 }
5213 }
5214
5215 rank = target->rank;
5216 /* Fixup cases where the ranks are mismatched. */
5217 if (sym->ts.type == BT_CLASS && CLASS_DATA (sym))
5218 {
5219 if ((!CLASS_DATA (sym)->as && rank != 0)
5220 || (CLASS_DATA (sym)->as
5221 && CLASS_DATA (sym)->as->rank != rank))
5222 {
5223 /* Don't just (re-)set the attr and as in the sym.ts,
5224 because this modifies the target's attr and as. Copy the
5225 data and do a build_class_symbol. */
5226 symbol_attribute attr = CLASS_DATA (target)->attr;
5227 int corank = gfc_get_corank (target);
5228 gfc_typespec type;
5229
5230 if (rank || corank)
5231 {
5232 as = gfc_get_array_spec ();
5233 as->type = AS_DEFERRED;
5234 as->rank = rank;
5235 as->corank = corank;
5236 attr.dimension = rank ? 1 : 0;
5237 attr.codimension = corank ? 1 : 0;
5238 }
5239 else
5240 {
5241 as = NULL;
5242 attr.dimension = attr.codimension = 0;
5243 }
5244 attr.class_ok = 0;
5245 type = CLASS_DATA (sym)->ts;
5246 if (!gfc_build_class_symbol (&type, &attr, &as))
5247 gcc_unreachable ();
5248 sym->ts = type;
5249 sym->ts.type = BT_CLASS;
5250 sym->attr.class_ok = 1;
5251 }
5252 else
5253 sym->attr.class_ok = 1;
5254 }
5255 else if ((!sym->as && rank != 0)
5256 || (sym->as && sym->as->rank != rank))
5257 {
5258 as = gfc_get_array_spec ();
5259 as->type = AS_DEFERRED;
5260 as->rank = rank;
5261 as->corank = gfc_get_corank (target);
5262 sym->as = as;
5263 sym->attr.dimension = 1;
5264 if (as->corank)
5265 sym->attr.codimension = 1;
5266 }
5267 }
5268
5269 accept_statement (ST_ASSOCIATE);
5270 push_state (&s, COMP_ASSOCIATE, my_ns->proc_name);
5271
5272 loop:
5273 st = parse_executable (ST_NONE);
5274 switch (st)
5275 {
5276 case ST_NONE:
5277 unexpected_eof ();
5278
5279 case_end:
5280 accept_statement (st);
5281 my_ns->code = gfc_state_stack->head;
5282 break;
5283
5284 default:
5285 unexpected_statement (st);
5286 goto loop;
5287 }
5288
5289 gfc_current_ns = gfc_current_ns->parent;
5290 pop_state ();
5291 }
5292
5293
5294 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
5295 handled inside of parse_executable(), because they aren't really
5296 loop statements. */
5297
5298 static void
5299 parse_do_block (void)
5300 {
5301 gfc_statement st;
5302 gfc_code *top;
5303 gfc_state_data s;
5304 gfc_symtree *stree;
5305 gfc_exec_op do_op;
5306
5307 do_op = new_st.op;
5308 s.ext.end_do_label = new_st.label1;
5309
5310 if (new_st.ext.iterator != NULL)
5311 {
5312 stree = new_st.ext.iterator->var->symtree;
5313 if (directive_unroll != -1)
5314 {
5315 new_st.ext.iterator->unroll = directive_unroll;
5316 directive_unroll = -1;
5317 }
5318 if (directive_ivdep)
5319 {
5320 new_st.ext.iterator->ivdep = directive_ivdep;
5321 directive_ivdep = false;
5322 }
5323 if (directive_vector)
5324 {
5325 new_st.ext.iterator->vector = directive_vector;
5326 directive_vector = false;
5327 }
5328 if (directive_novector)
5329 {
5330 new_st.ext.iterator->novector = directive_novector;
5331 directive_novector = false;
5332 }
5333 }
5334 else
5335 stree = NULL;
5336
5337 accept_statement (ST_DO);
5338
5339 top = gfc_state_stack->tail;
5340 push_state (&s, do_op == EXEC_DO_CONCURRENT ? COMP_DO_CONCURRENT : COMP_DO,
5341 gfc_new_block);
5342
5343 s.do_variable = stree;
5344
5345 top->block = new_level (top);
5346 top->block->op = EXEC_DO;
5347
5348 loop:
5349 st = parse_executable (ST_NONE);
5350
5351 switch (st)
5352 {
5353 case ST_NONE:
5354 unexpected_eof ();
5355
5356 case ST_ENDDO:
5357 if (s.ext.end_do_label != NULL
5358 && s.ext.end_do_label != gfc_statement_label)
5359 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
5360 "DO label");
5361
5362 if (gfc_statement_label != NULL)
5363 {
5364 new_st.op = EXEC_NOP;
5365 add_statement ();
5366 }
5367 break;
5368
5369 case ST_IMPLIED_ENDDO:
5370 /* If the do-stmt of this DO construct has a do-construct-name,
5371 the corresponding end-do must be an end-do-stmt (with a matching
5372 name, but in that case we must have seen ST_ENDDO first).
5373 We only complain about this in pedantic mode. */
5374 if (gfc_current_block () != NULL)
5375 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
5376 &gfc_current_block()->declared_at);
5377
5378 break;
5379
5380 default:
5381 unexpected_statement (st);
5382 goto loop;
5383 }
5384
5385 pop_state ();
5386 accept_statement (st);
5387 }
5388
5389
5390 /* Parse the statements of OpenMP do/parallel do. */
5391
5392 static gfc_statement
5393 parse_omp_do (gfc_statement omp_st)
5394 {
5395 gfc_statement st;
5396 gfc_code *cp, *np;
5397 gfc_state_data s;
5398
5399 accept_statement (omp_st);
5400
5401 cp = gfc_state_stack->tail;
5402 push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
5403 np = new_level (cp);
5404 np->op = cp->op;
5405 np->block = NULL;
5406
5407 for (;;)
5408 {
5409 st = next_statement ();
5410 if (st == ST_NONE)
5411 unexpected_eof ();
5412 else if (st == ST_DO)
5413 break;
5414 else
5415 unexpected_statement (st);
5416 }
5417
5418 parse_do_block ();
5419 if (gfc_statement_label != NULL
5420 && gfc_state_stack->previous != NULL
5421 && gfc_state_stack->previous->state == COMP_DO
5422 && gfc_state_stack->previous->ext.end_do_label == gfc_statement_label)
5423 {
5424 /* In
5425 DO 100 I=1,10
5426 !$OMP DO
5427 DO J=1,10
5428 ...
5429 100 CONTINUE
5430 there should be no !$OMP END DO. */
5431 pop_state ();
5432 return ST_IMPLIED_ENDDO;
5433 }
5434
5435 check_do_closure ();
5436 pop_state ();
5437
5438 st = next_statement ();
5439 gfc_statement omp_end_st = ST_OMP_END_DO;
5440 switch (omp_st)
5441 {
5442 case ST_OMP_DISTRIBUTE: omp_end_st = ST_OMP_END_DISTRIBUTE; break;
5443 case ST_OMP_DISTRIBUTE_PARALLEL_DO:
5444 omp_end_st = ST_OMP_END_DISTRIBUTE_PARALLEL_DO;
5445 break;
5446 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
5447 omp_end_st = ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD;
5448 break;
5449 case ST_OMP_DISTRIBUTE_SIMD:
5450 omp_end_st = ST_OMP_END_DISTRIBUTE_SIMD;
5451 break;
5452 case ST_OMP_DO: omp_end_st = ST_OMP_END_DO; break;
5453 case ST_OMP_DO_SIMD: omp_end_st = ST_OMP_END_DO_SIMD; break;
5454 case ST_OMP_LOOP: omp_end_st = ST_OMP_END_LOOP; break;
5455 case ST_OMP_PARALLEL_DO: omp_end_st = ST_OMP_END_PARALLEL_DO; break;
5456 case ST_OMP_PARALLEL_DO_SIMD:
5457 omp_end_st = ST_OMP_END_PARALLEL_DO_SIMD;
5458 break;
5459 case ST_OMP_PARALLEL_LOOP:
5460 omp_end_st = ST_OMP_END_PARALLEL_LOOP;
5461 break;
5462 case ST_OMP_SIMD: omp_end_st = ST_OMP_END_SIMD; break;
5463 case ST_OMP_TARGET_PARALLEL_DO:
5464 omp_end_st = ST_OMP_END_TARGET_PARALLEL_DO;
5465 break;
5466 case ST_OMP_TARGET_PARALLEL_DO_SIMD:
5467 omp_end_st = ST_OMP_END_TARGET_PARALLEL_DO_SIMD;
5468 break;
5469 case ST_OMP_TARGET_PARALLEL_LOOP:
5470 omp_end_st = ST_OMP_END_TARGET_PARALLEL_LOOP;
5471 break;
5472 case ST_OMP_TARGET_SIMD: omp_end_st = ST_OMP_END_TARGET_SIMD; break;
5473 case ST_OMP_TARGET_TEAMS_DISTRIBUTE:
5474 omp_end_st = ST_OMP_END_TARGET_TEAMS_DISTRIBUTE;
5475 break;
5476 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
5477 omp_end_st = ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO;
5478 break;
5479 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
5480 omp_end_st = ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
5481 break;
5482 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
5483 omp_end_st = ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD;
5484 break;
5485 case ST_OMP_TARGET_TEAMS_LOOP:
5486 omp_end_st = ST_OMP_END_TARGET_TEAMS_LOOP;
5487 break;
5488 case ST_OMP_TASKLOOP: omp_end_st = ST_OMP_END_TASKLOOP; break;
5489 case ST_OMP_TASKLOOP_SIMD: omp_end_st = ST_OMP_END_TASKLOOP_SIMD; break;
5490 case ST_OMP_MASKED_TASKLOOP: omp_end_st = ST_OMP_END_MASKED_TASKLOOP; break;
5491 case ST_OMP_MASKED_TASKLOOP_SIMD:
5492 omp_end_st = ST_OMP_END_MASKED_TASKLOOP_SIMD;
5493 break;
5494 case ST_OMP_MASTER_TASKLOOP: omp_end_st = ST_OMP_END_MASTER_TASKLOOP; break;
5495 case ST_OMP_MASTER_TASKLOOP_SIMD:
5496 omp_end_st = ST_OMP_END_MASTER_TASKLOOP_SIMD;
5497 break;
5498 case ST_OMP_PARALLEL_MASKED_TASKLOOP:
5499 omp_end_st = ST_OMP_END_PARALLEL_MASKED_TASKLOOP;
5500 break;
5501 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
5502 omp_end_st = ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD;
5503 break;
5504 case ST_OMP_PARALLEL_MASTER_TASKLOOP:
5505 omp_end_st = ST_OMP_END_PARALLEL_MASTER_TASKLOOP;
5506 break;
5507 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
5508 omp_end_st = ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD;
5509 break;
5510 case ST_OMP_TEAMS_DISTRIBUTE:
5511 omp_end_st = ST_OMP_END_TEAMS_DISTRIBUTE;
5512 break;
5513 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
5514 omp_end_st = ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO;
5515 break;
5516 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
5517 omp_end_st = ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
5518 break;
5519 case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
5520 omp_end_st = ST_OMP_END_TEAMS_DISTRIBUTE_SIMD;
5521 break;
5522 case ST_OMP_TEAMS_LOOP:
5523 omp_end_st = ST_OMP_END_TEAMS_LOOP;
5524 break;
5525 default: gcc_unreachable ();
5526 }
5527 if (st == omp_end_st)
5528 {
5529 if (new_st.op == EXEC_OMP_END_NOWAIT)
5530 {
5531 if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool)
5532 gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
5533 gfc_ascii_statement (omp_st),
5534 gfc_ascii_statement (omp_end_st));
5535 cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool;
5536 }
5537 else
5538 gcc_assert (new_st.op == EXEC_NOP);
5539 gfc_clear_new_st ();
5540 gfc_commit_symbols ();
5541 gfc_warning_check ();
5542 st = next_statement ();
5543 }
5544 return st;
5545 }
5546
5547
5548 /* Parse the statements of OpenMP atomic directive. */
5549
5550 static gfc_statement
5551 parse_omp_oacc_atomic (bool omp_p)
5552 {
5553 gfc_statement st, st_atomic, st_end_atomic;
5554 gfc_code *cp, *np;
5555 gfc_state_data s;
5556 int count;
5557
5558 if (omp_p)
5559 {
5560 st_atomic = ST_OMP_ATOMIC;
5561 st_end_atomic = ST_OMP_END_ATOMIC;
5562 }
5563 else
5564 {
5565 st_atomic = ST_OACC_ATOMIC;
5566 st_end_atomic = ST_OACC_END_ATOMIC;
5567 }
5568 accept_statement (st_atomic);
5569
5570 cp = gfc_state_stack->tail;
5571 push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
5572 np = new_level (cp);
5573 np->op = cp->op;
5574 np->block = NULL;
5575 np->ext.omp_clauses = cp->ext.omp_clauses;
5576 cp->ext.omp_clauses = NULL;
5577 count = 1 + np->ext.omp_clauses->capture;
5578
5579 while (count)
5580 {
5581 st = next_statement ();
5582 if (st == ST_NONE)
5583 unexpected_eof ();
5584 else if (np->ext.omp_clauses->compare
5585 && (st == ST_SIMPLE_IF || st == ST_IF_BLOCK))
5586 {
5587 count--;
5588 if (st == ST_IF_BLOCK)
5589 {
5590 parse_if_block ();
5591 /* With else (or elseif). */
5592 if (gfc_state_stack->tail->block->block)
5593 count--;
5594 }
5595 accept_statement (st);
5596 }
5597 else if (st == ST_ASSIGNMENT
5598 && (!np->ext.omp_clauses->compare
5599 || np->ext.omp_clauses->capture))
5600 {
5601 accept_statement (st);
5602 count--;
5603 }
5604 else
5605 unexpected_statement (st);
5606 }
5607
5608 pop_state ();
5609
5610 st = next_statement ();
5611 if (st == st_end_atomic)
5612 {
5613 gfc_clear_new_st ();
5614 gfc_commit_symbols ();
5615 gfc_warning_check ();
5616 st = next_statement ();
5617 }
5618 return st;
5619 }
5620
5621
5622 /* Parse the statements of an OpenACC structured block. */
5623
5624 static void
5625 parse_oacc_structured_block (gfc_statement acc_st)
5626 {
5627 gfc_statement st, acc_end_st;
5628 gfc_code *cp, *np;
5629 gfc_state_data s, *sd;
5630
5631 for (sd = gfc_state_stack; sd; sd = sd->previous)
5632 if (sd->state == COMP_CRITICAL)
5633 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5634
5635 accept_statement (acc_st);
5636
5637 cp = gfc_state_stack->tail;
5638 push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
5639 np = new_level (cp);
5640 np->op = cp->op;
5641 np->block = NULL;
5642 switch (acc_st)
5643 {
5644 case ST_OACC_PARALLEL:
5645 acc_end_st = ST_OACC_END_PARALLEL;
5646 break;
5647 case ST_OACC_KERNELS:
5648 acc_end_st = ST_OACC_END_KERNELS;
5649 break;
5650 case ST_OACC_SERIAL:
5651 acc_end_st = ST_OACC_END_SERIAL;
5652 break;
5653 case ST_OACC_DATA:
5654 acc_end_st = ST_OACC_END_DATA;
5655 break;
5656 case ST_OACC_HOST_DATA:
5657 acc_end_st = ST_OACC_END_HOST_DATA;
5658 break;
5659 default:
5660 gcc_unreachable ();
5661 }
5662
5663 do
5664 {
5665 st = parse_executable (ST_NONE);
5666 if (st == ST_NONE)
5667 unexpected_eof ();
5668 else if (st != acc_end_st)
5669 {
5670 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st));
5671 reject_statement ();
5672 }
5673 }
5674 while (st != acc_end_st);
5675
5676 gcc_assert (new_st.op == EXEC_NOP);
5677
5678 gfc_clear_new_st ();
5679 gfc_commit_symbols ();
5680 gfc_warning_check ();
5681 pop_state ();
5682 }
5683
5684 /* Parse the statements of OpenACC 'loop', or combined compute 'loop'. */
5685
5686 static gfc_statement
5687 parse_oacc_loop (gfc_statement acc_st)
5688 {
5689 gfc_statement st;
5690 gfc_code *cp, *np;
5691 gfc_state_data s, *sd;
5692
5693 for (sd = gfc_state_stack; sd; sd = sd->previous)
5694 if (sd->state == COMP_CRITICAL)
5695 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5696
5697 accept_statement (acc_st);
5698
5699 cp = gfc_state_stack->tail;
5700 push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
5701 np = new_level (cp);
5702 np->op = cp->op;
5703 np->block = NULL;
5704
5705 for (;;)
5706 {
5707 st = next_statement ();
5708 if (st == ST_NONE)
5709 unexpected_eof ();
5710 else if (st == ST_DO)
5711 break;
5712 else
5713 {
5714 gfc_error ("Expected DO loop at %C");
5715 reject_statement ();
5716 }
5717 }
5718
5719 parse_do_block ();
5720 if (gfc_statement_label != NULL
5721 && gfc_state_stack->previous != NULL
5722 && gfc_state_stack->previous->state == COMP_DO
5723 && gfc_state_stack->previous->ext.end_do_label == gfc_statement_label)
5724 {
5725 pop_state ();
5726 return ST_IMPLIED_ENDDO;
5727 }
5728
5729 check_do_closure ();
5730 pop_state ();
5731
5732 st = next_statement ();
5733 if (st == ST_OACC_END_LOOP)
5734 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
5735 if ((acc_st == ST_OACC_PARALLEL_LOOP && st == ST_OACC_END_PARALLEL_LOOP) ||
5736 (acc_st == ST_OACC_KERNELS_LOOP && st == ST_OACC_END_KERNELS_LOOP) ||
5737 (acc_st == ST_OACC_SERIAL_LOOP && st == ST_OACC_END_SERIAL_LOOP) ||
5738 (acc_st == ST_OACC_LOOP && st == ST_OACC_END_LOOP))
5739 {
5740 gcc_assert (new_st.op == EXEC_NOP);
5741 gfc_clear_new_st ();
5742 gfc_commit_symbols ();
5743 gfc_warning_check ();
5744 st = next_statement ();
5745 }
5746 return st;
5747 }
5748
5749
5750 /* Parse an OpenMP allocate block, including optional ALLOCATORS
5751 end directive. */
5752
5753 static gfc_statement
5754 parse_openmp_allocate_block (gfc_statement omp_st)
5755 {
5756 gfc_statement st;
5757 gfc_code *cp, *np;
5758 gfc_state_data s;
5759 bool empty_list = false;
5760 locus empty_list_loc;
5761 gfc_omp_namelist *n_first = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
5762
5763 if (omp_st == ST_OMP_ALLOCATE_EXEC
5764 && new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym == NULL)
5765 {
5766 empty_list = true;
5767 empty_list_loc = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where;
5768 }
5769
5770 accept_statement (omp_st);
5771
5772 cp = gfc_state_stack->tail;
5773 push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
5774 np = new_level (cp);
5775 np->op = cp->op;
5776 np->block = NULL;
5777
5778 st = next_statement ();
5779 while (omp_st == ST_OMP_ALLOCATE_EXEC && st == ST_OMP_ALLOCATE_EXEC)
5780 {
5781 if (empty_list && !new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym)
5782 {
5783 locus *loc = &new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where;
5784 gfc_error_now ("%s statements at %L and %L have both no list item but"
5785 " only one may", gfc_ascii_statement (st),
5786 &empty_list_loc, loc);
5787 empty_list = false;
5788 }
5789 if (!new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym)
5790 {
5791 empty_list = true;
5792 empty_list_loc = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where;
5793 }
5794 for ( ; n_first->next; n_first = n_first->next)
5795 ;
5796 n_first->next = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
5797 new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = NULL;
5798 gfc_free_omp_clauses (new_st.ext.omp_clauses);
5799
5800 accept_statement (ST_NONE);
5801 st = next_statement ();
5802 }
5803 if (st != ST_ALLOCATE && omp_st == ST_OMP_ALLOCATE_EXEC)
5804 gfc_error_now ("Unexpected %s at %C; expected ALLOCATE or %s statement",
5805 gfc_ascii_statement (st), gfc_ascii_statement (omp_st));
5806 else if (st != ST_ALLOCATE)
5807 gfc_error_now ("Unexpected %s at %C; expected ALLOCATE statement after %s",
5808 gfc_ascii_statement (st), gfc_ascii_statement (omp_st));
5809 accept_statement (st);
5810 pop_state ();
5811 st = next_statement ();
5812 if (omp_st == ST_OMP_ALLOCATORS && st == ST_OMP_END_ALLOCATORS)
5813 {
5814 accept_statement (st);
5815 st = next_statement ();
5816 }
5817 return st;
5818 }
5819
5820
5821 /* Parse the statements of an OpenMP structured block. */
5822
5823 static gfc_statement
5824 parse_omp_structured_block (gfc_statement omp_st, bool workshare_stmts_only)
5825 {
5826 gfc_statement st, omp_end_st, first_st;
5827 gfc_code *cp, *np;
5828 gfc_state_data s, s2;
5829
5830 accept_statement (omp_st);
5831
5832 cp = gfc_state_stack->tail;
5833 push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
5834 np = new_level (cp);
5835 np->op = cp->op;
5836 np->block = NULL;
5837
5838 switch (omp_st)
5839 {
5840 case ST_OMP_ASSUME:
5841 omp_end_st = ST_OMP_END_ASSUME;
5842 break;
5843 case ST_OMP_PARALLEL:
5844 omp_end_st = ST_OMP_END_PARALLEL;
5845 break;
5846 case ST_OMP_PARALLEL_MASKED:
5847 omp_end_st = ST_OMP_END_PARALLEL_MASKED;
5848 break;
5849 case ST_OMP_PARALLEL_MASTER:
5850 omp_end_st = ST_OMP_END_PARALLEL_MASTER;
5851 break;
5852 case ST_OMP_PARALLEL_SECTIONS:
5853 omp_end_st = ST_OMP_END_PARALLEL_SECTIONS;
5854 break;
5855 case ST_OMP_SCOPE:
5856 omp_end_st = ST_OMP_END_SCOPE;
5857 break;
5858 case ST_OMP_SECTIONS:
5859 omp_end_st = ST_OMP_END_SECTIONS;
5860 break;
5861 case ST_OMP_ORDERED:
5862 omp_end_st = ST_OMP_END_ORDERED;
5863 break;
5864 case ST_OMP_CRITICAL:
5865 omp_end_st = ST_OMP_END_CRITICAL;
5866 break;
5867 case ST_OMP_MASKED:
5868 omp_end_st = ST_OMP_END_MASKED;
5869 break;
5870 case ST_OMP_MASTER:
5871 omp_end_st = ST_OMP_END_MASTER;
5872 break;
5873 case ST_OMP_SINGLE:
5874 omp_end_st = ST_OMP_END_SINGLE;
5875 break;
5876 case ST_OMP_TARGET:
5877 omp_end_st = ST_OMP_END_TARGET;
5878 break;
5879 case ST_OMP_TARGET_DATA:
5880 omp_end_st = ST_OMP_END_TARGET_DATA;
5881 break;
5882 case ST_OMP_TARGET_PARALLEL:
5883 omp_end_st = ST_OMP_END_TARGET_PARALLEL;
5884 break;
5885 case ST_OMP_TARGET_TEAMS:
5886 omp_end_st = ST_OMP_END_TARGET_TEAMS;
5887 break;
5888 case ST_OMP_TASK:
5889 omp_end_st = ST_OMP_END_TASK;
5890 break;
5891 case ST_OMP_TASKGROUP:
5892 omp_end_st = ST_OMP_END_TASKGROUP;
5893 break;
5894 case ST_OMP_TEAMS:
5895 omp_end_st = ST_OMP_END_TEAMS;
5896 break;
5897 case ST_OMP_TEAMS_DISTRIBUTE:
5898 omp_end_st = ST_OMP_END_TEAMS_DISTRIBUTE;
5899 break;
5900 case ST_OMP_DISTRIBUTE:
5901 omp_end_st = ST_OMP_END_DISTRIBUTE;
5902 break;
5903 case ST_OMP_WORKSHARE:
5904 omp_end_st = ST_OMP_END_WORKSHARE;
5905 break;
5906 case ST_OMP_PARALLEL_WORKSHARE:
5907 omp_end_st = ST_OMP_END_PARALLEL_WORKSHARE;
5908 break;
5909 default:
5910 gcc_unreachable ();
5911 }
5912
5913 bool block_construct = false;
5914 gfc_namespace *my_ns = NULL;
5915 gfc_namespace *my_parent = NULL;
5916
5917 first_st = st = next_statement ();
5918
5919 if (st == ST_BLOCK)
5920 {
5921 /* Adjust state to a strictly-structured block, now that we found that
5922 the body starts with a BLOCK construct. */
5923 s.state = COMP_OMP_STRICTLY_STRUCTURED_BLOCK;
5924
5925 block_construct = true;
5926 gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C");
5927
5928 my_ns = gfc_build_block_ns (gfc_current_ns);
5929 new_st.op = EXEC_BLOCK;
5930 new_st.ext.block.ns = my_ns;
5931 new_st.ext.block.assoc = NULL;
5932 accept_statement (ST_BLOCK);
5933
5934 push_state (&s2, COMP_BLOCK, my_ns->proc_name);
5935 gfc_current_ns = my_ns;
5936 my_parent = my_ns->parent;
5937 if (omp_st == ST_OMP_SECTIONS
5938 || omp_st == ST_OMP_PARALLEL_SECTIONS)
5939 {
5940 np = new_level (cp);
5941 np->op = cp->op;
5942 }
5943
5944 first_st = next_statement ();
5945 st = parse_spec (first_st);
5946 }
5947
5948 if (omp_end_st == ST_OMP_END_TARGET)
5949 switch (first_st)
5950 {
5951 case ST_OMP_TEAMS:
5952 case ST_OMP_TEAMS_DISTRIBUTE:
5953 case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
5954 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
5955 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
5956 case ST_OMP_TEAMS_LOOP:
5957 {
5958 gfc_state_data *stk = gfc_state_stack->previous;
5959 if (stk->state == COMP_OMP_STRICTLY_STRUCTURED_BLOCK)
5960 stk = stk->previous;
5961 stk->tail->ext.omp_clauses->target_first_st_is_teams = true;
5962 break;
5963 }
5964 default:
5965 break;
5966 }
5967
5968 do
5969 {
5970 if (workshare_stmts_only)
5971 {
5972 /* Inside of !$omp workshare, only
5973 scalar assignments
5974 array assignments
5975 where statements and constructs
5976 forall statements and constructs
5977 !$omp atomic
5978 !$omp critical
5979 !$omp parallel
5980 are allowed. For !$omp critical these
5981 restrictions apply recursively. */
5982 bool cycle = true;
5983
5984 for (;;)
5985 {
5986 switch (st)
5987 {
5988 case ST_NONE:
5989 unexpected_eof ();
5990
5991 case ST_ASSIGNMENT:
5992 case ST_WHERE:
5993 case ST_FORALL:
5994 accept_statement (st);
5995 break;
5996
5997 case ST_WHERE_BLOCK:
5998 parse_where_block ();
5999 break;
6000
6001 case ST_FORALL_BLOCK:
6002 parse_forall_block ();
6003 break;
6004
6005 case ST_OMP_ALLOCATE_EXEC:
6006 case ST_OMP_ALLOCATORS:
6007 st = parse_openmp_allocate_block (st);
6008 continue;
6009
6010 case ST_OMP_ASSUME:
6011 case ST_OMP_PARALLEL:
6012 case ST_OMP_PARALLEL_MASKED:
6013 case ST_OMP_PARALLEL_MASTER:
6014 case ST_OMP_PARALLEL_SECTIONS:
6015 st = parse_omp_structured_block (st, false);
6016 continue;
6017
6018 case ST_OMP_PARALLEL_WORKSHARE:
6019 case ST_OMP_CRITICAL:
6020 st = parse_omp_structured_block (st, true);
6021 continue;
6022
6023 case ST_OMP_PARALLEL_DO:
6024 case ST_OMP_PARALLEL_DO_SIMD:
6025 st = parse_omp_do (st);
6026 continue;
6027
6028 case ST_OMP_ATOMIC:
6029 st = parse_omp_oacc_atomic (true);
6030 continue;
6031
6032 default:
6033 cycle = false;
6034 break;
6035 }
6036
6037 if (!cycle)
6038 break;
6039
6040 st = next_statement ();
6041 }
6042 }
6043 else
6044 st = parse_executable (st);
6045 if (st == ST_NONE)
6046 unexpected_eof ();
6047 else if (st == ST_OMP_SECTION
6048 && (omp_st == ST_OMP_SECTIONS
6049 || omp_st == ST_OMP_PARALLEL_SECTIONS))
6050 {
6051 np = new_level (np);
6052 np->op = cp->op;
6053 np->block = NULL;
6054 st = next_statement ();
6055 }
6056 else if (block_construct && st == ST_END_BLOCK)
6057 {
6058 accept_statement (st);
6059 gfc_current_ns->code = gfc_state_stack->head;
6060 gfc_current_ns = my_parent;
6061 pop_state (); /* Inner BLOCK */
6062 pop_state (); /* Outer COMP_OMP_STRICTLY_STRUCTURED_BLOCK */
6063
6064 st = next_statement ();
6065 if (st == omp_end_st)
6066 {
6067 accept_statement (st);
6068 st = next_statement ();
6069 }
6070 return st;
6071 }
6072 else if (st != omp_end_st || block_construct)
6073 {
6074 unexpected_statement (st);
6075 st = next_statement ();
6076 }
6077 }
6078 while (st != omp_end_st);
6079
6080 switch (new_st.op)
6081 {
6082 case EXEC_OMP_END_NOWAIT:
6083 if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool)
6084 gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
6085 gfc_ascii_statement (omp_st),
6086 gfc_ascii_statement (omp_end_st));
6087 cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool;
6088 break;
6089 case EXEC_OMP_END_CRITICAL:
6090 if (((cp->ext.omp_clauses->critical_name == NULL)
6091 ^ (new_st.ext.omp_name == NULL))
6092 || (new_st.ext.omp_name != NULL
6093 && strcmp (cp->ext.omp_clauses->critical_name,
6094 new_st.ext.omp_name) != 0))
6095 gfc_error ("Name after !$omp critical and !$omp end critical does "
6096 "not match at %C");
6097 free (CONST_CAST (char *, new_st.ext.omp_name));
6098 new_st.ext.omp_name = NULL;
6099 break;
6100 case EXEC_OMP_END_SINGLE:
6101 if (cp->ext.omp_clauses->nowait && new_st.ext.omp_clauses->nowait)
6102 gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
6103 gfc_ascii_statement (omp_st),
6104 gfc_ascii_statement (omp_end_st));
6105 cp->ext.omp_clauses->nowait |= new_st.ext.omp_clauses->nowait;
6106 if (cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE])
6107 {
6108 gfc_omp_namelist *nl;
6109 for (nl = cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE];
6110 nl->next; nl = nl->next)
6111 ;
6112 nl->next = new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE];
6113 }
6114 else
6115 cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]
6116 = new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE];
6117 new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE] = NULL;
6118 gfc_free_omp_clauses (new_st.ext.omp_clauses);
6119 break;
6120 case EXEC_NOP:
6121 break;
6122 default:
6123 gcc_unreachable ();
6124 }
6125
6126 gfc_clear_new_st ();
6127 gfc_commit_symbols ();
6128 gfc_warning_check ();
6129 pop_state ();
6130 st = next_statement ();
6131 return st;
6132 }
6133
6134
6135 /* Accept a series of executable statements. We return the first
6136 statement that doesn't fit to the caller. Any block statements are
6137 passed on to the correct handler, which usually passes the buck
6138 right back here. */
6139
6140 static gfc_statement
6141 parse_executable (gfc_statement st)
6142 {
6143 int close_flag;
6144 in_exec_part = true;
6145
6146 if (st == ST_NONE)
6147 st = next_statement ();
6148
6149 for (;;)
6150 {
6151 close_flag = check_do_closure ();
6152 if (close_flag)
6153 switch (st)
6154 {
6155 case ST_GOTO:
6156 case ST_END_PROGRAM:
6157 case ST_RETURN:
6158 case ST_EXIT:
6159 case ST_END_FUNCTION:
6160 case ST_CYCLE:
6161 case ST_PAUSE:
6162 case ST_STOP:
6163 case ST_ERROR_STOP:
6164 case ST_END_SUBROUTINE:
6165
6166 case ST_DO:
6167 case ST_FORALL:
6168 case ST_WHERE:
6169 case ST_SELECT_CASE:
6170 gfc_error ("%s statement at %C cannot terminate a non-block "
6171 "DO loop", gfc_ascii_statement (st));
6172 break;
6173
6174 default:
6175 break;
6176 }
6177
6178 switch (st)
6179 {
6180 case ST_NONE:
6181 unexpected_eof ();
6182
6183 case ST_DATA:
6184 gfc_notify_std (GFC_STD_F95_OBS, "DATA statement at %C after the "
6185 "first executable statement");
6186 /* Fall through. */
6187
6188 case ST_FORMAT:
6189 case ST_ENTRY:
6190 case_executable:
6191 accept_statement (st);
6192 if (close_flag == 1)
6193 return ST_IMPLIED_ENDDO;
6194 break;
6195
6196 case ST_BLOCK:
6197 parse_block_construct ();
6198 break;
6199
6200 case ST_ASSOCIATE:
6201 parse_associate ();
6202 break;
6203
6204 case ST_IF_BLOCK:
6205 parse_if_block ();
6206 break;
6207
6208 case ST_SELECT_CASE:
6209 parse_select_block ();
6210 break;
6211
6212 case ST_SELECT_TYPE:
6213 parse_select_type_block ();
6214 break;
6215
6216 case ST_SELECT_RANK:
6217 parse_select_rank_block ();
6218 break;
6219
6220 case ST_DO:
6221 parse_do_block ();
6222 if (check_do_closure () == 1)
6223 return ST_IMPLIED_ENDDO;
6224 break;
6225
6226 case ST_CRITICAL:
6227 parse_critical_block ();
6228 break;
6229
6230 case ST_WHERE_BLOCK:
6231 parse_where_block ();
6232 break;
6233
6234 case ST_FORALL_BLOCK:
6235 parse_forall_block ();
6236 break;
6237
6238 case ST_OACC_PARALLEL_LOOP:
6239 case ST_OACC_KERNELS_LOOP:
6240 case ST_OACC_SERIAL_LOOP:
6241 case ST_OACC_LOOP:
6242 st = parse_oacc_loop (st);
6243 if (st == ST_IMPLIED_ENDDO)
6244 return st;
6245 continue;
6246
6247 case ST_OACC_PARALLEL:
6248 case ST_OACC_KERNELS:
6249 case ST_OACC_SERIAL:
6250 case ST_OACC_DATA:
6251 case ST_OACC_HOST_DATA:
6252 parse_oacc_structured_block (st);
6253 break;
6254
6255 case ST_OMP_ALLOCATE_EXEC:
6256 case ST_OMP_ALLOCATORS:
6257 st = parse_openmp_allocate_block (st);
6258 continue;
6259
6260 case ST_OMP_ASSUME:
6261 case ST_OMP_PARALLEL:
6262 case ST_OMP_PARALLEL_MASKED:
6263 case ST_OMP_PARALLEL_MASTER:
6264 case ST_OMP_PARALLEL_SECTIONS:
6265 case ST_OMP_ORDERED:
6266 case ST_OMP_CRITICAL:
6267 case ST_OMP_MASKED:
6268 case ST_OMP_MASTER:
6269 case ST_OMP_SCOPE:
6270 case ST_OMP_SECTIONS:
6271 case ST_OMP_SINGLE:
6272 case ST_OMP_TARGET:
6273 case ST_OMP_TARGET_DATA:
6274 case ST_OMP_TARGET_PARALLEL:
6275 case ST_OMP_TARGET_TEAMS:
6276 case ST_OMP_TEAMS:
6277 case ST_OMP_TASK:
6278 case ST_OMP_TASKGROUP:
6279 st = parse_omp_structured_block (st, false);
6280 continue;
6281
6282 case ST_OMP_WORKSHARE:
6283 case ST_OMP_PARALLEL_WORKSHARE:
6284 st = parse_omp_structured_block (st, true);
6285 continue;
6286
6287 case ST_OMP_DISTRIBUTE:
6288 case ST_OMP_DISTRIBUTE_PARALLEL_DO:
6289 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
6290 case ST_OMP_DISTRIBUTE_SIMD:
6291 case ST_OMP_DO:
6292 case ST_OMP_DO_SIMD:
6293 case ST_OMP_LOOP:
6294 case ST_OMP_PARALLEL_DO:
6295 case ST_OMP_PARALLEL_DO_SIMD:
6296 case ST_OMP_PARALLEL_LOOP:
6297 case ST_OMP_PARALLEL_MASKED_TASKLOOP:
6298 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
6299 case ST_OMP_PARALLEL_MASTER_TASKLOOP:
6300 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
6301 case ST_OMP_MASKED_TASKLOOP:
6302 case ST_OMP_MASKED_TASKLOOP_SIMD:
6303 case ST_OMP_MASTER_TASKLOOP:
6304 case ST_OMP_MASTER_TASKLOOP_SIMD:
6305 case ST_OMP_SIMD:
6306 case ST_OMP_TARGET_PARALLEL_DO:
6307 case ST_OMP_TARGET_PARALLEL_DO_SIMD:
6308 case ST_OMP_TARGET_PARALLEL_LOOP:
6309 case ST_OMP_TARGET_SIMD:
6310 case ST_OMP_TARGET_TEAMS_DISTRIBUTE:
6311 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
6312 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
6313 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
6314 case ST_OMP_TARGET_TEAMS_LOOP:
6315 case ST_OMP_TASKLOOP:
6316 case ST_OMP_TASKLOOP_SIMD:
6317 case ST_OMP_TEAMS_DISTRIBUTE:
6318 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
6319 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
6320 case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
6321 case ST_OMP_TEAMS_LOOP:
6322 st = parse_omp_do (st);
6323 if (st == ST_IMPLIED_ENDDO)
6324 return st;
6325 continue;
6326
6327 case ST_OACC_ATOMIC:
6328 st = parse_omp_oacc_atomic (false);
6329 continue;
6330
6331 case ST_OMP_ATOMIC:
6332 st = parse_omp_oacc_atomic (true);
6333 continue;
6334
6335 default:
6336 return st;
6337 }
6338
6339 if (directive_unroll != -1)
6340 gfc_error ("%<GCC unroll%> directive not at the start of a loop at %C");
6341
6342 if (directive_ivdep)
6343 gfc_error ("%<GCC ivdep%> directive not at the start of a loop at %C");
6344
6345 if (directive_vector)
6346 gfc_error ("%<GCC vector%> directive not at the start of a loop at %C");
6347
6348 if (directive_novector)
6349 gfc_error ("%<GCC novector%> "
6350 "directive not at the start of a loop at %C");
6351
6352 st = next_statement ();
6353 }
6354 }
6355
6356
6357 /* Fix the symbols for sibling functions. These are incorrectly added to
6358 the child namespace as the parser didn't know about this procedure. */
6359
6360 static void
6361 gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings)
6362 {
6363 gfc_namespace *ns;
6364 gfc_symtree *st;
6365 gfc_symbol *old_sym;
6366
6367 for (ns = siblings; ns; ns = ns->sibling)
6368 {
6369 st = gfc_find_symtree (ns->sym_root, sym->name);
6370
6371 if (!st || (st->n.sym->attr.dummy && ns == st->n.sym->ns))
6372 goto fixup_contained;
6373
6374 if ((st->n.sym->attr.flavor == FL_DERIVED
6375 && sym->attr.generic && sym->attr.function)
6376 ||(sym->attr.flavor == FL_DERIVED
6377 && st->n.sym->attr.generic && st->n.sym->attr.function))
6378 goto fixup_contained;
6379
6380 old_sym = st->n.sym;
6381 if (old_sym->ns == ns
6382 && !old_sym->attr.contained
6383
6384 /* By 14.6.1.3, host association should be excluded
6385 for the following. */
6386 && !(old_sym->attr.external
6387 || (old_sym->ts.type != BT_UNKNOWN
6388 && !old_sym->attr.implicit_type)
6389 || old_sym->attr.flavor == FL_PARAMETER
6390 || old_sym->attr.use_assoc
6391 || old_sym->attr.in_common
6392 || old_sym->attr.in_equivalence
6393 || old_sym->attr.data
6394 || old_sym->attr.dummy
6395 || old_sym->attr.result
6396 || old_sym->attr.dimension
6397 || old_sym->attr.allocatable
6398 || old_sym->attr.intrinsic
6399 || old_sym->attr.generic
6400 || old_sym->attr.flavor == FL_NAMELIST
6401 || old_sym->attr.flavor == FL_LABEL
6402 || old_sym->attr.proc == PROC_ST_FUNCTION))
6403 {
6404 /* Replace it with the symbol from the parent namespace. */
6405 st->n.sym = sym;
6406 sym->refs++;
6407
6408 gfc_release_symbol (old_sym);
6409 }
6410
6411 fixup_contained:
6412 /* Do the same for any contained procedures. */
6413 gfc_fixup_sibling_symbols (sym, ns->contained);
6414 }
6415 }
6416
6417 static void
6418 parse_contained (int module)
6419 {
6420 gfc_namespace *ns, *parent_ns, *tmp;
6421 gfc_state_data s1, s2;
6422 gfc_statement st;
6423 gfc_symbol *sym;
6424 gfc_entry_list *el;
6425 locus old_loc;
6426 int contains_statements = 0;
6427 int seen_error = 0;
6428
6429 push_state (&s1, COMP_CONTAINS, NULL);
6430 parent_ns = gfc_current_ns;
6431
6432 do
6433 {
6434 gfc_current_ns = gfc_get_namespace (parent_ns, 1);
6435
6436 gfc_current_ns->sibling = parent_ns->contained;
6437 parent_ns->contained = gfc_current_ns;
6438
6439 next:
6440 /* Process the next available statement. We come here if we got an error
6441 and rejected the last statement. */
6442 old_loc = gfc_current_locus;
6443 st = next_statement ();
6444
6445 switch (st)
6446 {
6447 case ST_NONE:
6448 unexpected_eof ();
6449
6450 case ST_FUNCTION:
6451 case ST_SUBROUTINE:
6452 contains_statements = 1;
6453 accept_statement (st);
6454
6455 push_state (&s2,
6456 (st == ST_FUNCTION) ? COMP_FUNCTION : COMP_SUBROUTINE,
6457 gfc_new_block);
6458
6459 /* For internal procedures, create/update the symbol in the
6460 parent namespace. */
6461
6462 if (!module)
6463 {
6464 if (gfc_get_symbol (gfc_new_block->name, parent_ns, &sym))
6465 gfc_error ("Contained procedure %qs at %C is already "
6466 "ambiguous", gfc_new_block->name);
6467 else
6468 {
6469 if (gfc_add_procedure (&sym->attr, PROC_INTERNAL,
6470 sym->name,
6471 &gfc_new_block->declared_at))
6472 {
6473 if (st == ST_FUNCTION)
6474 gfc_add_function (&sym->attr, sym->name,
6475 &gfc_new_block->declared_at);
6476 else
6477 gfc_add_subroutine (&sym->attr, sym->name,
6478 &gfc_new_block->declared_at);
6479 }
6480 }
6481
6482 gfc_commit_symbols ();
6483 }
6484 else
6485 sym = gfc_new_block;
6486
6487 /* Mark this as a contained function, so it isn't replaced
6488 by other module functions. */
6489 sym->attr.contained = 1;
6490
6491 /* Set implicit_pure so that it can be reset if any of the
6492 tests for purity fail. This is used for some optimisation
6493 during translation. */
6494 if (!sym->attr.pure)
6495 sym->attr.implicit_pure = 1;
6496
6497 parse_progunit (ST_NONE);
6498
6499 /* Fix up any sibling functions that refer to this one. */
6500 gfc_fixup_sibling_symbols (sym, gfc_current_ns);
6501 /* Or refer to any of its alternate entry points. */
6502 for (el = gfc_current_ns->entries; el; el = el->next)
6503 gfc_fixup_sibling_symbols (el->sym, gfc_current_ns);
6504
6505 gfc_current_ns->code = s2.head;
6506 gfc_current_ns = parent_ns;
6507
6508 pop_state ();
6509 break;
6510
6511 /* These statements are associated with the end of the host unit. */
6512 case ST_END_FUNCTION:
6513 case ST_END_MODULE:
6514 case ST_END_SUBMODULE:
6515 case ST_END_PROGRAM:
6516 case ST_END_SUBROUTINE:
6517 accept_statement (st);
6518 gfc_current_ns->code = s1.head;
6519 break;
6520
6521 default:
6522 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
6523 gfc_ascii_statement (st));
6524 reject_statement ();
6525 seen_error = 1;
6526 goto next;
6527 break;
6528 }
6529 }
6530 while (st != ST_END_FUNCTION && st != ST_END_SUBROUTINE
6531 && st != ST_END_MODULE && st != ST_END_SUBMODULE
6532 && st != ST_END_PROGRAM);
6533
6534 /* The first namespace in the list is guaranteed to not have
6535 anything (worthwhile) in it. */
6536 tmp = gfc_current_ns;
6537 gfc_current_ns = parent_ns;
6538 if (seen_error && tmp->refs > 1)
6539 gfc_free_namespace (tmp);
6540
6541 ns = gfc_current_ns->contained;
6542 gfc_current_ns->contained = ns->sibling;
6543 gfc_free_namespace (ns);
6544
6545 pop_state ();
6546 if (!contains_statements)
6547 gfc_notify_std (GFC_STD_F2008, "CONTAINS statement without "
6548 "FUNCTION or SUBROUTINE statement at %L", &old_loc);
6549 }
6550
6551
6552 /* The result variable in a MODULE PROCEDURE needs to be created and
6553 its characteristics copied from the interface since it is neither
6554 declared in the procedure declaration nor in the specification
6555 part. */
6556
6557 static void
6558 get_modproc_result (void)
6559 {
6560 gfc_symbol *proc;
6561 if (gfc_state_stack->previous
6562 && gfc_state_stack->previous->state == COMP_CONTAINS
6563 && gfc_state_stack->previous->previous->state == COMP_SUBMODULE)
6564 {
6565 proc = gfc_current_ns->proc_name ? gfc_current_ns->proc_name : NULL;
6566 if (proc != NULL
6567 && proc->attr.function
6568 && proc->tlink
6569 && proc->tlink->result
6570 && proc->tlink->result != proc->tlink)
6571 {
6572 gfc_copy_dummy_sym (&proc->result, proc->tlink->result, 1);
6573 gfc_set_sym_referenced (proc->result);
6574 proc->result->attr.if_source = IFSRC_DECL;
6575 gfc_commit_symbol (proc->result);
6576 }
6577 }
6578 }
6579
6580
6581 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
6582
6583 static void
6584 parse_progunit (gfc_statement st)
6585 {
6586 gfc_state_data *p;
6587 int n;
6588
6589 gfc_adjust_builtins ();
6590
6591 if (gfc_new_block
6592 && gfc_new_block->abr_modproc_decl
6593 && gfc_new_block->attr.function)
6594 get_modproc_result ();
6595
6596 st = parse_spec (st);
6597 switch (st)
6598 {
6599 case ST_NONE:
6600 unexpected_eof ();
6601
6602 case ST_CONTAINS:
6603 /* This is not allowed within BLOCK! */
6604 if (gfc_current_state () != COMP_BLOCK)
6605 goto contains;
6606 break;
6607
6608 case_end:
6609 accept_statement (st);
6610 goto done;
6611
6612 default:
6613 break;
6614 }
6615
6616 if (gfc_current_state () == COMP_FUNCTION)
6617 gfc_check_function_type (gfc_current_ns);
6618
6619 loop:
6620 for (;;)
6621 {
6622 st = parse_executable (st);
6623
6624 switch (st)
6625 {
6626 case ST_NONE:
6627 unexpected_eof ();
6628
6629 case ST_CONTAINS:
6630 /* This is not allowed within BLOCK! */
6631 if (gfc_current_state () != COMP_BLOCK)
6632 goto contains;
6633 break;
6634
6635 case_end:
6636 accept_statement (st);
6637 goto done;
6638
6639 default:
6640 break;
6641 }
6642
6643 unexpected_statement (st);
6644 reject_statement ();
6645 st = next_statement ();
6646 }
6647
6648 contains:
6649 n = 0;
6650
6651 for (p = gfc_state_stack; p; p = p->previous)
6652 if (p->state == COMP_CONTAINS)
6653 n++;
6654
6655 if (gfc_find_state (COMP_MODULE) == true
6656 || gfc_find_state (COMP_SUBMODULE) == true)
6657 n--;
6658
6659 if (n > 0)
6660 {
6661 gfc_error ("CONTAINS statement at %C is already in a contained "
6662 "program unit");
6663 reject_statement ();
6664 st = next_statement ();
6665 goto loop;
6666 }
6667
6668 parse_contained (0);
6669
6670 done:
6671 gfc_current_ns->code = gfc_state_stack->head;
6672 }
6673
6674
6675 /* Come here to complain about a global symbol already in use as
6676 something else. */
6677
6678 void
6679 gfc_global_used (gfc_gsymbol *sym, locus *where)
6680 {
6681 const char *name;
6682
6683 if (where == NULL)
6684 where = &gfc_current_locus;
6685
6686 switch(sym->type)
6687 {
6688 case GSYM_PROGRAM:
6689 name = "PROGRAM";
6690 break;
6691 case GSYM_FUNCTION:
6692 name = "FUNCTION";
6693 break;
6694 case GSYM_SUBROUTINE:
6695 name = "SUBROUTINE";
6696 break;
6697 case GSYM_COMMON:
6698 name = "COMMON";
6699 break;
6700 case GSYM_BLOCK_DATA:
6701 name = "BLOCK DATA";
6702 break;
6703 case GSYM_MODULE:
6704 name = "MODULE";
6705 break;
6706 default:
6707 name = NULL;
6708 }
6709
6710 if (name)
6711 {
6712 if (sym->binding_label)
6713 gfc_error ("Global binding name %qs at %L is already being used "
6714 "as a %s at %L", sym->binding_label, where, name,
6715 &sym->where);
6716 else
6717 gfc_error ("Global name %qs at %L is already being used as "
6718 "a %s at %L", sym->name, where, name, &sym->where);
6719 }
6720 else
6721 {
6722 if (sym->binding_label)
6723 gfc_error ("Global binding name %qs at %L is already being used "
6724 "at %L", sym->binding_label, where, &sym->where);
6725 else
6726 gfc_error ("Global name %qs at %L is already being used at %L",
6727 sym->name, where, &sym->where);
6728 }
6729 }
6730
6731
6732 /* Parse a block data program unit. */
6733
6734 static void
6735 parse_block_data (void)
6736 {
6737 gfc_statement st;
6738 static locus blank_locus;
6739 static int blank_block=0;
6740 gfc_gsymbol *s;
6741
6742 gfc_current_ns->proc_name = gfc_new_block;
6743 gfc_current_ns->is_block_data = 1;
6744
6745 if (gfc_new_block == NULL)
6746 {
6747 if (blank_block)
6748 gfc_error ("Blank BLOCK DATA at %C conflicts with "
6749 "prior BLOCK DATA at %L", &blank_locus);
6750 else
6751 {
6752 blank_block = 1;
6753 blank_locus = gfc_current_locus;
6754 }
6755 }
6756 else
6757 {
6758 s = gfc_get_gsymbol (gfc_new_block->name, false);
6759 if (s->defined
6760 || (s->type != GSYM_UNKNOWN && s->type != GSYM_BLOCK_DATA))
6761 gfc_global_used (s, &gfc_new_block->declared_at);
6762 else
6763 {
6764 s->type = GSYM_BLOCK_DATA;
6765 s->where = gfc_new_block->declared_at;
6766 s->defined = 1;
6767 }
6768 }
6769
6770 st = parse_spec (ST_NONE);
6771
6772 while (st != ST_END_BLOCK_DATA)
6773 {
6774 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
6775 gfc_ascii_statement (st));
6776 reject_statement ();
6777 st = next_statement ();
6778 }
6779 }
6780
6781
6782 /* Following the association of the ancestor (sub)module symbols, they
6783 must be set host rather than use associated and all must be public.
6784 They are flagged up by 'used_in_submodule' so that they can be set
6785 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
6786 linker chokes on multiple symbol definitions. */
6787
6788 static void
6789 set_syms_host_assoc (gfc_symbol *sym)
6790 {
6791 gfc_component *c;
6792 const char dot[2] = ".";
6793 /* Symbols take the form module.submodule_ or module.name_. */
6794 char parent1[2 * GFC_MAX_SYMBOL_LEN + 2];
6795 char parent2[2 * GFC_MAX_SYMBOL_LEN + 2];
6796
6797 if (sym == NULL)
6798 return;
6799
6800 if (sym->attr.module_procedure)
6801 sym->attr.external = 0;
6802
6803 sym->attr.use_assoc = 0;
6804 sym->attr.host_assoc = 1;
6805 sym->attr.used_in_submodule =1;
6806
6807 if (sym->attr.flavor == FL_DERIVED)
6808 {
6809 /* Derived types with PRIVATE components that are declared in
6810 modules other than the parent module must not be changed to be
6811 PUBLIC. The 'use-assoc' attribute must be reset so that the
6812 test in symbol.cc(gfc_find_component) works correctly. This is
6813 not necessary for PRIVATE symbols since they are not read from
6814 the module. */
6815 memset(parent1, '\0', sizeof(parent1));
6816 memset(parent2, '\0', sizeof(parent2));
6817 strcpy (parent1, gfc_new_block->name);
6818 strcpy (parent2, sym->module);
6819 if (strcmp (strtok (parent1, dot), strtok (parent2, dot)) == 0)
6820 {
6821 for (c = sym->components; c; c = c->next)
6822 c->attr.access = ACCESS_PUBLIC;
6823 }
6824 else
6825 {
6826 sym->attr.use_assoc = 1;
6827 sym->attr.host_assoc = 0;
6828 }
6829 }
6830 }
6831
6832 /* Parse a module subprogram. */
6833
6834 static void
6835 parse_module (void)
6836 {
6837 gfc_statement st;
6838 gfc_gsymbol *s;
6839
6840 s = gfc_get_gsymbol (gfc_new_block->name, false);
6841 if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_MODULE))
6842 gfc_global_used (s, &gfc_new_block->declared_at);
6843 else
6844 {
6845 s->type = GSYM_MODULE;
6846 s->where = gfc_new_block->declared_at;
6847 s->defined = 1;
6848 }
6849
6850 /* Something is nulling the module_list after this point. This is good
6851 since it allows us to 'USE' the parent modules that the submodule
6852 inherits and to set (most) of the symbols as host associated. */
6853 if (gfc_current_state () == COMP_SUBMODULE)
6854 {
6855 use_modules ();
6856 gfc_traverse_ns (gfc_current_ns, set_syms_host_assoc);
6857 }
6858
6859 st = parse_spec (ST_NONE);
6860
6861 loop:
6862 switch (st)
6863 {
6864 case ST_NONE:
6865 unexpected_eof ();
6866
6867 case ST_CONTAINS:
6868 parse_contained (1);
6869 break;
6870
6871 case ST_END_MODULE:
6872 case ST_END_SUBMODULE:
6873 accept_statement (st);
6874 break;
6875
6876 default:
6877 gfc_error ("Unexpected %s statement in MODULE at %C",
6878 gfc_ascii_statement (st));
6879 reject_statement ();
6880 st = next_statement ();
6881 goto loop;
6882 }
6883 s->ns = gfc_current_ns;
6884 }
6885
6886
6887 /* Add a procedure name to the global symbol table. */
6888
6889 static void
6890 add_global_procedure (bool sub)
6891 {
6892 gfc_gsymbol *s;
6893
6894 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
6895 name is a global identifier. */
6896 if (!gfc_new_block->binding_label || gfc_notification_std (GFC_STD_F2008))
6897 {
6898 s = gfc_get_gsymbol (gfc_new_block->name, false);
6899
6900 if (s->defined
6901 || (s->type != GSYM_UNKNOWN
6902 && s->type != (sub ? GSYM_SUBROUTINE : GSYM_FUNCTION)))
6903 {
6904 gfc_global_used (s, &gfc_new_block->declared_at);
6905 /* Silence follow-up errors. */
6906 gfc_new_block->binding_label = NULL;
6907 }
6908 else
6909 {
6910 s->type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION;
6911 s->sym_name = gfc_new_block->name;
6912 s->where = gfc_new_block->declared_at;
6913 s->defined = 1;
6914 s->ns = gfc_current_ns;
6915 }
6916 }
6917
6918 /* Don't add the symbol multiple times. */
6919 if (gfc_new_block->binding_label
6920 && (!gfc_notification_std (GFC_STD_F2008)
6921 || strcmp (gfc_new_block->name, gfc_new_block->binding_label) != 0))
6922 {
6923 s = gfc_get_gsymbol (gfc_new_block->binding_label, true);
6924
6925 if (s->defined
6926 || (s->type != GSYM_UNKNOWN
6927 && s->type != (sub ? GSYM_SUBROUTINE : GSYM_FUNCTION)))
6928 {
6929 gfc_global_used (s, &gfc_new_block->declared_at);
6930 /* Silence follow-up errors. */
6931 gfc_new_block->binding_label = NULL;
6932 }
6933 else
6934 {
6935 s->type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION;
6936 s->sym_name = gfc_new_block->name;
6937 s->binding_label = gfc_new_block->binding_label;
6938 s->where = gfc_new_block->declared_at;
6939 s->defined = 1;
6940 s->ns = gfc_current_ns;
6941 }
6942 }
6943 }
6944
6945
6946 /* Add a program to the global symbol table. */
6947
6948 static void
6949 add_global_program (void)
6950 {
6951 gfc_gsymbol *s;
6952
6953 if (gfc_new_block == NULL)
6954 return;
6955 s = gfc_get_gsymbol (gfc_new_block->name, false);
6956
6957 if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_PROGRAM))
6958 gfc_global_used (s, &gfc_new_block->declared_at);
6959 else
6960 {
6961 s->type = GSYM_PROGRAM;
6962 s->where = gfc_new_block->declared_at;
6963 s->defined = 1;
6964 s->ns = gfc_current_ns;
6965 }
6966 }
6967
6968
6969 /* Resolve all the program units. */
6970 static void
6971 resolve_all_program_units (gfc_namespace *gfc_global_ns_list)
6972 {
6973 gfc_derived_types = NULL;
6974 gfc_current_ns = gfc_global_ns_list;
6975 for (; gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
6976 {
6977 if (gfc_current_ns->proc_name
6978 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
6979 continue; /* Already resolved. */
6980
6981 if (gfc_current_ns->proc_name)
6982 gfc_current_locus = gfc_current_ns->proc_name->declared_at;
6983 gfc_resolve (gfc_current_ns);
6984 gfc_current_ns->derived_types = gfc_derived_types;
6985 gfc_derived_types = NULL;
6986 }
6987 }
6988
6989
6990 static void
6991 clean_up_modules (gfc_gsymbol *&gsym)
6992 {
6993 if (gsym == NULL)
6994 return;
6995
6996 clean_up_modules (gsym->left);
6997 clean_up_modules (gsym->right);
6998
6999 if (gsym->type != GSYM_MODULE)
7000 return;
7001
7002 if (gsym->ns)
7003 {
7004 gfc_current_ns = gsym->ns;
7005 gfc_derived_types = gfc_current_ns->derived_types;
7006 gfc_done_2 ();
7007 gsym->ns = NULL;
7008 }
7009 free (gsym);
7010 gsym = NULL;
7011 }
7012
7013
7014 /* Translate all the program units. This could be in a different order
7015 to resolution if there are forward references in the file. */
7016 static void
7017 translate_all_program_units (gfc_namespace *gfc_global_ns_list)
7018 {
7019 int errors;
7020
7021 gfc_current_ns = gfc_global_ns_list;
7022 gfc_get_errors (NULL, &errors);
7023
7024 /* We first translate all modules to make sure that later parts
7025 of the program can use the decl. Then we translate the nonmodules. */
7026
7027 for (; !errors && gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
7028 {
7029 if (!gfc_current_ns->proc_name
7030 || gfc_current_ns->proc_name->attr.flavor != FL_MODULE)
7031 continue;
7032
7033 gfc_current_locus = gfc_current_ns->proc_name->declared_at;
7034 gfc_derived_types = gfc_current_ns->derived_types;
7035 gfc_generate_module_code (gfc_current_ns);
7036 gfc_current_ns->translated = 1;
7037 }
7038
7039 gfc_current_ns = gfc_global_ns_list;
7040 for (; !errors && gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
7041 {
7042 if (gfc_current_ns->proc_name
7043 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
7044 continue;
7045
7046 gfc_current_locus = gfc_current_ns->proc_name->declared_at;
7047 gfc_derived_types = gfc_current_ns->derived_types;
7048 gfc_generate_code (gfc_current_ns);
7049 gfc_current_ns->translated = 1;
7050 }
7051
7052 /* Clean up all the namespaces after translation. */
7053 gfc_current_ns = gfc_global_ns_list;
7054 for (;gfc_current_ns;)
7055 {
7056 gfc_namespace *ns;
7057
7058 if (gfc_current_ns->proc_name
7059 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
7060 {
7061 gfc_current_ns = gfc_current_ns->sibling;
7062 continue;
7063 }
7064
7065 ns = gfc_current_ns->sibling;
7066 gfc_derived_types = gfc_current_ns->derived_types;
7067 gfc_done_2 ();
7068 gfc_current_ns = ns;
7069 }
7070
7071 clean_up_modules (gfc_gsym_root);
7072 }
7073
7074
7075 /* Top level parser. */
7076
7077 bool
7078 gfc_parse_file (void)
7079 {
7080 int seen_program, errors_before, errors;
7081 gfc_state_data top, s;
7082 gfc_statement st;
7083 locus prog_locus;
7084 gfc_namespace *next;
7085
7086 gfc_start_source_files ();
7087
7088 top.state = COMP_NONE;
7089 top.sym = NULL;
7090 top.previous = NULL;
7091 top.head = top.tail = NULL;
7092 top.do_variable = NULL;
7093
7094 gfc_state_stack = &top;
7095
7096 gfc_clear_new_st ();
7097
7098 gfc_statement_label = NULL;
7099
7100 if (setjmp (eof_buf))
7101 return false; /* Come here on unexpected EOF */
7102
7103 /* Prepare the global namespace that will contain the
7104 program units. */
7105 gfc_global_ns_list = next = NULL;
7106
7107 seen_program = 0;
7108 errors_before = 0;
7109
7110 /* Exit early for empty files. */
7111 if (gfc_at_eof ())
7112 goto done;
7113
7114 in_specification_block = true;
7115 loop:
7116 gfc_init_2 ();
7117 st = next_statement ();
7118 switch (st)
7119 {
7120 case ST_NONE:
7121 gfc_done_2 ();
7122 goto done;
7123
7124 case ST_PROGRAM:
7125 if (seen_program)
7126 goto duplicate_main;
7127 seen_program = 1;
7128 prog_locus = gfc_current_locus;
7129
7130 push_state (&s, COMP_PROGRAM, gfc_new_block);
7131 main_program_symbol (gfc_current_ns, gfc_new_block->name);
7132 accept_statement (st);
7133 add_global_program ();
7134 parse_progunit (ST_NONE);
7135 goto prog_units;
7136
7137 case ST_SUBROUTINE:
7138 add_global_procedure (true);
7139 push_state (&s, COMP_SUBROUTINE, gfc_new_block);
7140 accept_statement (st);
7141 parse_progunit (ST_NONE);
7142 goto prog_units;
7143
7144 case ST_FUNCTION:
7145 add_global_procedure (false);
7146 push_state (&s, COMP_FUNCTION, gfc_new_block);
7147 accept_statement (st);
7148 parse_progunit (ST_NONE);
7149 goto prog_units;
7150
7151 case ST_BLOCK_DATA:
7152 push_state (&s, COMP_BLOCK_DATA, gfc_new_block);
7153 accept_statement (st);
7154 parse_block_data ();
7155 break;
7156
7157 case ST_MODULE:
7158 push_state (&s, COMP_MODULE, gfc_new_block);
7159 accept_statement (st);
7160
7161 gfc_get_errors (NULL, &errors_before);
7162 parse_module ();
7163 break;
7164
7165 case ST_SUBMODULE:
7166 push_state (&s, COMP_SUBMODULE, gfc_new_block);
7167 accept_statement (st);
7168
7169 gfc_get_errors (NULL, &errors_before);
7170 parse_module ();
7171 break;
7172
7173 /* Anything else starts a nameless main program block. */
7174 default:
7175 if (seen_program)
7176 goto duplicate_main;
7177 seen_program = 1;
7178 prog_locus = gfc_current_locus;
7179
7180 push_state (&s, COMP_PROGRAM, gfc_new_block);
7181 main_program_symbol (gfc_current_ns, "MAIN__");
7182 parse_progunit (st);
7183 goto prog_units;
7184 }
7185
7186 /* Handle the non-program units. */
7187 gfc_current_ns->code = s.head;
7188
7189 gfc_resolve (gfc_current_ns);
7190
7191 /* Fix the implicit_pure attribute for those procedures who should
7192 not have it. */
7193 while (gfc_fix_implicit_pure (gfc_current_ns))
7194 ;
7195
7196 /* Dump the parse tree if requested. */
7197 if (flag_dump_fortran_original)
7198 gfc_dump_parse_tree (gfc_current_ns, stdout);
7199
7200 gfc_get_errors (NULL, &errors);
7201 if (s.state == COMP_MODULE || s.state == COMP_SUBMODULE)
7202 {
7203 gfc_dump_module (s.sym->name, errors_before == errors);
7204 gfc_current_ns->derived_types = gfc_derived_types;
7205 gfc_derived_types = NULL;
7206 goto prog_units;
7207 }
7208 else
7209 {
7210 if (errors == 0)
7211 gfc_generate_code (gfc_current_ns);
7212 pop_state ();
7213 gfc_done_2 ();
7214 }
7215
7216 goto loop;
7217
7218 prog_units:
7219 /* The main program and non-contained procedures are put
7220 in the global namespace list, so that they can be processed
7221 later and all their interfaces resolved. */
7222 gfc_current_ns->code = s.head;
7223 if (next)
7224 {
7225 for (; next->sibling; next = next->sibling)
7226 ;
7227 next->sibling = gfc_current_ns;
7228 }
7229 else
7230 gfc_global_ns_list = gfc_current_ns;
7231
7232 next = gfc_current_ns;
7233
7234 pop_state ();
7235 goto loop;
7236
7237 done:
7238 /* Do the resolution. */
7239 resolve_all_program_units (gfc_global_ns_list);
7240
7241 /* Go through all top-level namespaces and unset the implicit_pure
7242 attribute for any procedures that call something not pure or
7243 implicit_pure. Because the a procedure marked as not implicit_pure
7244 in one sweep may be called by another routine, we repeat this
7245 process until there are no more changes. */
7246 bool changed;
7247 do
7248 {
7249 changed = false;
7250 for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
7251 gfc_current_ns = gfc_current_ns->sibling)
7252 {
7253 if (gfc_fix_implicit_pure (gfc_current_ns))
7254 changed = true;
7255 }
7256 }
7257 while (changed);
7258
7259 /* Fixup for external procedures and resolve 'omp requires'. */
7260 int omp_requires;
7261 bool omp_target_seen;
7262 omp_requires = 0;
7263 omp_target_seen = false;
7264 for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
7265 gfc_current_ns = gfc_current_ns->sibling)
7266 {
7267 omp_requires |= gfc_current_ns->omp_requires;
7268 omp_target_seen |= gfc_current_ns->omp_target_seen;
7269 gfc_check_externals (gfc_current_ns);
7270 }
7271 for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
7272 gfc_current_ns = gfc_current_ns->sibling)
7273 gfc_check_omp_requires (gfc_current_ns, omp_requires);
7274
7275 /* Populate omp_requires_mask (needed for resolving OpenMP
7276 metadirectives and declare variant). */
7277 switch (omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
7278 {
7279 case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST:
7280 omp_requires_mask
7281 = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_SEQ_CST);
7282 break;
7283 case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL:
7284 omp_requires_mask
7285 = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_ACQ_REL);
7286 break;
7287 case OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE:
7288 omp_requires_mask
7289 = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_ACQUIRE);
7290 break;
7291 case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED:
7292 omp_requires_mask
7293 = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_RELAXED);
7294 break;
7295 case OMP_REQ_ATOMIC_MEM_ORDER_RELEASE:
7296 omp_requires_mask
7297 = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_RELEASE);
7298 break;
7299 }
7300
7301 if (omp_target_seen)
7302 omp_requires_mask = (enum omp_requires) (omp_requires_mask
7303 | OMP_REQUIRES_TARGET_USED);
7304 if (omp_requires & OMP_REQ_REVERSE_OFFLOAD)
7305 omp_requires_mask = (enum omp_requires) (omp_requires_mask
7306 | OMP_REQUIRES_REVERSE_OFFLOAD);
7307 if (omp_requires & OMP_REQ_UNIFIED_ADDRESS)
7308 omp_requires_mask = (enum omp_requires) (omp_requires_mask
7309 | OMP_REQUIRES_UNIFIED_ADDRESS);
7310 if (omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY)
7311 omp_requires_mask
7312 = (enum omp_requires) (omp_requires_mask
7313 | OMP_REQUIRES_UNIFIED_SHARED_MEMORY);
7314 if (omp_requires & OMP_REQ_DYNAMIC_ALLOCATORS)
7315 omp_requires_mask = (enum omp_requires) (omp_requires_mask
7316 | OMP_REQUIRES_DYNAMIC_ALLOCATORS);
7317 /* Do the parse tree dump. */
7318 gfc_current_ns = flag_dump_fortran_original ? gfc_global_ns_list : NULL;
7319
7320 for (; gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
7321 if (!gfc_current_ns->proc_name
7322 || gfc_current_ns->proc_name->attr.flavor != FL_MODULE)
7323 {
7324 gfc_dump_parse_tree (gfc_current_ns, stdout);
7325 fputs ("------------------------------------------\n\n", stdout);
7326 }
7327
7328 /* Dump C prototypes. */
7329 if (flag_c_prototypes || flag_c_prototypes_external)
7330 {
7331 fprintf (stdout,
7332 "#include <stddef.h>\n"
7333 "#ifdef __cplusplus\n"
7334 "#include <complex>\n"
7335 "#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n"
7336 "#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n"
7337 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n"
7338 "extern \"C\" {\n"
7339 "#else\n"
7340 "#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n"
7341 "#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n"
7342 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n"
7343 "#endif\n\n");
7344 }
7345
7346 /* First dump BIND(C) prototypes. */
7347 if (flag_c_prototypes)
7348 {
7349 for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
7350 gfc_current_ns = gfc_current_ns->sibling)
7351 gfc_dump_c_prototypes (gfc_current_ns, stdout);
7352 }
7353
7354 /* Dump external prototypes. */
7355 if (flag_c_prototypes_external)
7356 gfc_dump_external_c_prototypes (stdout);
7357
7358 if (flag_c_prototypes || flag_c_prototypes_external)
7359 fprintf (stdout, "\n#ifdef __cplusplus\n}\n#endif\n");
7360
7361 /* Do the translation. */
7362 translate_all_program_units (gfc_global_ns_list);
7363
7364 /* Dump the global symbol ist. We only do this here because part
7365 of it is generated after mangling the identifiers in
7366 trans-decl.cc. */
7367
7368 if (flag_dump_fortran_global)
7369 gfc_dump_global_symbols (stdout);
7370
7371 gfc_end_source_files ();
7372 return true;
7373
7374 duplicate_main:
7375 /* If we see a duplicate main program, shut down. If the second
7376 instance is an implied main program, i.e. data decls or executable
7377 statements, we're in for lots of errors. */
7378 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus);
7379 reject_statement ();
7380 gfc_done_2 ();
7381 return true;
7382 }
7383
7384 /* Return true if this state data represents an OpenACC region. */
7385 bool
7386 is_oacc (gfc_state_data *sd)
7387 {
7388 switch (sd->construct->op)
7389 {
7390 case EXEC_OACC_PARALLEL_LOOP:
7391 case EXEC_OACC_PARALLEL:
7392 case EXEC_OACC_KERNELS_LOOP:
7393 case EXEC_OACC_KERNELS:
7394 case EXEC_OACC_SERIAL_LOOP:
7395 case EXEC_OACC_SERIAL:
7396 case EXEC_OACC_DATA:
7397 case EXEC_OACC_HOST_DATA:
7398 case EXEC_OACC_LOOP:
7399 case EXEC_OACC_UPDATE:
7400 case EXEC_OACC_WAIT:
7401 case EXEC_OACC_CACHE:
7402 case EXEC_OACC_ENTER_DATA:
7403 case EXEC_OACC_EXIT_DATA:
7404 case EXEC_OACC_ATOMIC:
7405 case EXEC_OACC_ROUTINE:
7406 return true;
7407
7408 default:
7409 return false;
7410 }
7411 }