2 Copyright (C) 2000-2025 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
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
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/>. */
23 #include "coretypes.h"
29 #include "tree-core.h"
30 #include "omp-general.h"
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. */
35 gfc_st_label
*gfc_statement_label
;
37 static locus label_locus
;
38 static jmp_buf eof_buf
;
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;
47 gfc_state_data
*gfc_state_stack
;
48 static bool last_was_use_stmt
= false;
51 /* True when matching an OpenMP context selector. */
52 bool gfc_matching_omp_context_selector
;
54 /* True when parsing the body of an OpenMP metadirective. */
55 bool gfc_in_omp_metadirective_body
;
57 /* Each metadirective body in the translation unit is given a unique
58 number, used to ensure that labels in the body have unique names. */
59 int gfc_omp_metadirective_region_count
;
61 /* TODO: Re-order functions to kill these forward decls. */
62 static void check_statement_label (gfc_statement
);
63 static void undo_new_statement (void);
64 static void reject_statement (void);
67 /* A sort of half-matching function. We try to match the word on the
68 input with the passed string. If this succeeds, we call the
69 keyword-dependent matching function that will match the rest of the
70 statement. For single keywords, the matching subroutine is
74 match_word (const char *str
, match (*subr
) (void), locus
*old_locus
)
89 gfc_current_locus
= *old_locus
;
97 /* Like match_word, but if str is matched, set a flag that it
100 match_word_omp_simd (const char *str
, match (*subr
) (void), locus
*old_locus
,
110 *simd_matched
= true;
117 gfc_current_locus
= *old_locus
;
125 /* Load symbols from all USE statements encountered in this scoping unit. */
130 gfc_error_buffer old_error
;
132 gfc_push_error (&old_error
);
133 gfc_buffer_error (false);
135 gfc_buffer_error (true);
136 gfc_pop_error (&old_error
);
137 gfc_commit_symbols ();
138 gfc_warning_check ();
139 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
140 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
141 last_was_use_stmt
= false;
145 /* Figure out what the next statement is, (mostly) regardless of
146 proper ordering. The do...while(0) is there to prevent if/else
149 #define match(keyword, subr, st) \
151 if (match_word (keyword, subr, &old_locus) == MATCH_YES) \
154 undo_new_statement (); \
158 /* This is a specialist version of decode_statement that is used
159 for the specification statements in a function, whose
160 characteristics are deferred into the specification statements.
161 eg.: INTEGER (king = mykind) foo ()
162 USE mymodule, ONLY mykind.....
163 The KIND parameter needs a return after USE or IMPORT, whereas
164 derived type declarations can occur anywhere, up the executable
165 block. ST_GET_FCN_CHARACTERISTICS is returned when we have run
166 out of the correct kind of specification statements. */
168 decode_specification_statement (void)
174 if (gfc_match_eos () == MATCH_YES
)
177 old_locus
= gfc_current_locus
;
179 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
181 last_was_use_stmt
= true;
186 undo_new_statement ();
187 if (last_was_use_stmt
)
191 match ("import", gfc_match_import
, ST_IMPORT
);
193 if (gfc_current_block ()->result
->ts
.type
!= BT_DERIVED
)
196 match (NULL
, gfc_match_st_function
, ST_STATEMENT_FUNCTION
);
197 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
198 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
200 /* General statement matching: Instead of testing every possible
201 statement, we eliminate most possibilities by peeking at the
204 c
= gfc_peek_ascii_char ();
209 match ("abstract% interface", gfc_match_abstract_interface
,
211 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
212 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
213 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
217 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
221 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
222 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
226 match ("data", gfc_match_data
, ST_DATA
);
227 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
231 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
232 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
233 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
234 match ("external", gfc_match_external
, ST_ATTR_DECL
);
238 match ("format", gfc_match_format
, ST_FORMAT
);
245 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
246 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
247 match ("interface", gfc_match_interface
, ST_INTERFACE
);
248 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
249 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
256 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
260 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
264 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
265 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
266 if (gfc_match_private (&st
) == MATCH_YES
)
268 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
269 if (gfc_match_public (&st
) == MATCH_YES
)
271 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
278 match ("save", gfc_match_save
, ST_ATTR_DECL
);
279 match ("static", gfc_match_static
, ST_ATTR_DECL
);
280 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
284 match ("target", gfc_match_target
, ST_ATTR_DECL
);
285 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
292 match ("value", gfc_match_value
, ST_ATTR_DECL
);
293 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
300 /* This is not a specification statement. See if any of the matchers
301 has stored an error message of some sort. */
305 gfc_buffer_error (false);
306 gfc_current_locus
= old_locus
;
308 return ST_GET_FCN_CHARACTERISTICS
;
312 /* Tells whether gfc_get_current_interface_head can be used safely. */
315 current_interface_valid_p ()
317 switch (current_interface
.type
)
319 case INTERFACE_INTRINSIC_OP
:
320 return current_interface
.ns
!= nullptr;
322 case INTERFACE_GENERIC
:
324 return current_interface
.sym
!= nullptr;
326 case INTERFACE_USER_OP
:
327 return current_interface
.uop
!= nullptr;
335 /* Return a pointer to the interface currently being parsed, or nullptr if
336 we are not currently parsing an interface body. */
338 static gfc_interface
**
339 get_current_interface_ptr ()
341 if (current_interface_valid_p ())
343 gfc_interface
*& ifc_ptr
= gfc_current_interface_head ();
351 static bool in_specification_block
;
353 /* This is the primary 'decode_statement'. */
355 decode_statement (void)
362 gfc_enforce_clean_symbol_state ();
364 gfc_clear_error (); /* Clear any pending errors. */
365 gfc_clear_warning (); /* Clear any pending warnings. */
367 current_interface_ptr
= get_current_interface_ptr ();
368 previous_interface_head
= current_interface_ptr
== nullptr
370 : *current_interface_ptr
;
372 gfc_matching_function
= false;
374 if (gfc_match_eos () == MATCH_YES
)
377 if (gfc_current_state () == COMP_FUNCTION
378 && gfc_current_block ()->result
->ts
.kind
== -1)
379 return decode_specification_statement ();
381 old_locus
= gfc_current_locus
;
383 c
= gfc_peek_ascii_char ();
387 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
389 last_was_use_stmt
= true;
393 undo_new_statement ();
396 if (last_was_use_stmt
)
399 /* Try matching a data declaration or function declaration. The
400 input "REALFUNCTIONA(N)" can mean several things in different
401 contexts, so it (and its relatives) get special treatment. */
403 if (gfc_current_state () == COMP_NONE
404 || gfc_current_state () == COMP_INTERFACE
405 || gfc_current_state () == COMP_CONTAINS
)
407 gfc_matching_function
= true;
408 m
= gfc_match_function_decl ();
411 else if (m
== MATCH_ERROR
)
415 gfc_current_locus
= old_locus
;
417 gfc_matching_function
= false;
419 /* Legacy parameter statements are ambiguous with assignments so try parameter
421 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
423 /* Match statements whose error messages are meant to be overwritten
424 by something better. */
426 match (NULL
, gfc_match_assignment
, ST_ASSIGNMENT
);
427 match (NULL
, gfc_match_pointer_assignment
, ST_POINTER_ASSIGNMENT
);
429 if (in_specification_block
)
431 m
= match_word (NULL
, gfc_match_st_function
, &old_locus
);
433 return ST_STATEMENT_FUNCTION
;
436 if (!(in_specification_block
&& m
== MATCH_ERROR
))
438 match (NULL
, gfc_match_ptr_fcn_assign
, ST_ASSIGNMENT
);
441 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
442 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
444 /* Try to match a subroutine statement, which has the same optional
445 prefixes that functions can have. */
447 if (gfc_match_subroutine () == MATCH_YES
)
448 return ST_SUBROUTINE
;
450 gfc_current_locus
= old_locus
;
452 if (gfc_match_submod_proc () == MATCH_YES
)
454 if (gfc_new_block
->attr
.subroutine
)
455 return ST_SUBROUTINE
;
456 else if (gfc_new_block
->attr
.function
)
460 gfc_current_locus
= old_locus
;
462 /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
463 statements, which might begin with a block label. The match functions for
464 these statements are unusual in that their keyword is not seen before
465 the matcher is called. */
467 if (gfc_match_if (&st
) == MATCH_YES
)
470 gfc_current_locus
= old_locus
;
472 if (gfc_match_where (&st
) == MATCH_YES
)
475 gfc_current_locus
= old_locus
;
477 if (gfc_match_forall (&st
) == MATCH_YES
)
480 gfc_current_locus
= old_locus
;
482 /* Try to match TYPE as an alias for PRINT. */
483 if (gfc_match_type (&st
) == MATCH_YES
)
486 gfc_current_locus
= old_locus
;
488 match (NULL
, gfc_match_do
, ST_DO
);
489 match (NULL
, gfc_match_block
, ST_BLOCK
);
490 match (NULL
, gfc_match_associate
, ST_ASSOCIATE
);
491 match (NULL
, gfc_match_critical
, ST_CRITICAL
);
492 match (NULL
, gfc_match_select
, ST_SELECT_CASE
);
493 match (NULL
, gfc_match_select_type
, ST_SELECT_TYPE
);
494 match (NULL
, gfc_match_select_rank
, ST_SELECT_RANK
);
496 /* General statement matching: Instead of testing every possible
497 statement, we eliminate most possibilities by peeking at the
503 match ("abstract% interface", gfc_match_abstract_interface
,
505 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
);
506 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
507 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
);
508 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
509 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
513 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
);
514 match ("block data", gfc_match_block_data
, ST_BLOCK_DATA
);
515 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
519 match ("call", gfc_match_call
, ST_CALL
);
520 match ("change% team", gfc_match_change_team
, ST_CHANGE_TEAM
);
521 match ("close", gfc_match_close
, ST_CLOSE
);
522 match ("continue", gfc_match_continue
, ST_CONTINUE
);
523 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
524 match ("cycle", gfc_match_cycle
, ST_CYCLE
);
525 match ("case", gfc_match_case
, ST_CASE
);
526 match ("common", gfc_match_common
, ST_COMMON
);
527 match ("contains", gfc_match_eos
, ST_CONTAINS
);
528 match ("class", gfc_match_class_is
, ST_CLASS_IS
);
529 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
533 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
);
534 match ("data", gfc_match_data
, ST_DATA
);
535 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
539 match ("end file", gfc_match_endfile
, ST_END_FILE
);
540 match ("end team", gfc_match_end_team
, ST_END_TEAM
);
541 match ("exit", gfc_match_exit
, ST_EXIT
);
542 match ("else", gfc_match_else
, ST_ELSE
);
543 match ("else where", gfc_match_elsewhere
, ST_ELSEWHERE
);
544 match ("else if", gfc_match_elseif
, ST_ELSEIF
);
545 match ("error% stop", gfc_match_error_stop
, ST_ERROR_STOP
);
546 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
548 if (gfc_match_end (&st
) == MATCH_YES
)
551 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
552 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
553 match ("external", gfc_match_external
, ST_ATTR_DECL
);
554 match ("event% post", gfc_match_event_post
, ST_EVENT_POST
);
555 match ("event% wait", gfc_match_event_wait
, ST_EVENT_WAIT
);
559 match ("fail% image", gfc_match_fail_image
, ST_FAIL_IMAGE
);
560 match ("final", gfc_match_final_decl
, ST_FINAL
);
561 match ("flush", gfc_match_flush
, ST_FLUSH
);
562 match ("form% team", gfc_match_form_team
, ST_FORM_TEAM
);
563 match ("format", gfc_match_format
, ST_FORMAT
);
567 match ("generic", gfc_match_generic
, ST_GENERIC
);
568 match ("go to", gfc_match_goto
, ST_GOTO
);
572 match ("inquire", gfc_match_inquire
, ST_INQUIRE
);
573 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
574 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
575 match ("import", gfc_match_import
, ST_IMPORT
);
576 match ("interface", gfc_match_interface
, ST_INTERFACE
);
577 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
578 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
582 match ("lock", gfc_match_lock
, ST_LOCK
);
586 match ("map", gfc_match_map
, ST_MAP
);
587 match ("module% procedure", gfc_match_modproc
, ST_MODULE_PROC
);
588 match ("module", gfc_match_module
, ST_MODULE
);
592 match ("nullify", gfc_match_nullify
, ST_NULLIFY
);
593 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
597 match ("open", gfc_match_open
, ST_OPEN
);
598 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
602 match ("print", gfc_match_print
, ST_WRITE
);
603 match ("pause", gfc_match_pause
, ST_PAUSE
);
604 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
605 if (gfc_match_private (&st
) == MATCH_YES
)
607 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
608 match ("program", gfc_match_program
, ST_PROGRAM
);
609 if (gfc_match_public (&st
) == MATCH_YES
)
611 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
615 match ("rank", gfc_match_rank_is
, ST_RANK
);
616 match ("read", gfc_match_read
, ST_READ
);
617 match ("return", gfc_match_return
, ST_RETURN
);
618 match ("rewind", gfc_match_rewind
, ST_REWIND
);
622 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
623 match ("sequence", gfc_match_eos
, ST_SEQUENCE
);
624 match ("stop", gfc_match_stop
, ST_STOP
);
625 match ("save", gfc_match_save
, ST_ATTR_DECL
);
626 match ("static", gfc_match_static
, ST_ATTR_DECL
);
627 match ("submodule", gfc_match_submodule
, ST_SUBMODULE
);
628 match ("sync% all", gfc_match_sync_all
, ST_SYNC_ALL
);
629 match ("sync% images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
630 match ("sync% memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
631 match ("sync% team", gfc_match_sync_team
, ST_SYNC_TEAM
);
635 match ("target", gfc_match_target
, ST_ATTR_DECL
);
636 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
637 match ("type% is", gfc_match_type_is
, ST_TYPE_IS
);
641 match ("union", gfc_match_union
, ST_UNION
);
642 match ("unlock", gfc_match_unlock
, ST_UNLOCK
);
646 match ("value", gfc_match_value
, ST_ATTR_DECL
);
647 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
651 match ("wait", gfc_match_wait
, ST_WAIT
);
652 match ("write", gfc_match_write
, ST_WRITE
);
656 /* All else has failed, so give up. See if any of the matchers has
657 stored an error message of some sort. Suppress the "Unclassifiable
658 statement" if a previous error message was emitted, e.g., by
660 if (!gfc_error_check ())
663 gfc_get_errors (NULL
, &ecnt
);
665 gfc_error_now ("Unclassifiable statement at %C");
670 gfc_error_recovery ();
675 /* Like match and if spec_only, goto do_spec_only without actually
677 /* If the directive matched but the clauses failed, do not start
678 matching the next directive in the same switch statement. */
679 #define matcha(keyword, subr, st) \
682 if (spec_only && gfc_match (keyword) == MATCH_YES) \
684 else if ((m2 = match_word (keyword, subr, &old_locus)) \
687 else if (m2 == MATCH_ERROR) \
688 goto error_handling; \
690 undo_new_statement (); \
694 decode_oacc_directive (void)
698 bool spec_only
= false;
700 gfc_enforce_clean_symbol_state ();
702 gfc_clear_error (); /* Clear any pending errors. */
703 gfc_clear_warning (); /* Clear any pending warnings. */
705 gfc_matching_function
= false;
707 if (gfc_current_state () == COMP_FUNCTION
708 && gfc_current_block ()->result
->ts
.kind
== -1)
711 old_locus
= gfc_current_locus
;
713 /* General OpenACC directive matching: Instead of testing every possible
714 statement, we eliminate most possibilities by peeking at the
717 c
= gfc_peek_ascii_char ();
722 matcha ("routine", gfc_match_oacc_routine
, ST_OACC_ROUTINE
);
726 gfc_unset_implicit_pure (NULL
);
729 gfc_error_now ("OpenACC directives other than ROUTINE may not appear in PURE "
737 matcha ("atomic", gfc_match_oacc_atomic
, ST_OACC_ATOMIC
);
740 matcha ("cache", gfc_match_oacc_cache
, ST_OACC_CACHE
);
743 matcha ("data", gfc_match_oacc_data
, ST_OACC_DATA
);
744 match ("declare", gfc_match_oacc_declare
, ST_OACC_DECLARE
);
747 matcha ("end atomic", gfc_match_omp_eos_error
, ST_OACC_END_ATOMIC
);
748 matcha ("end data", gfc_match_omp_eos_error
, ST_OACC_END_DATA
);
749 matcha ("end host_data", gfc_match_omp_eos_error
, ST_OACC_END_HOST_DATA
);
750 matcha ("end kernels loop", gfc_match_omp_eos_error
, ST_OACC_END_KERNELS_LOOP
);
751 matcha ("end kernels", gfc_match_omp_eos_error
, ST_OACC_END_KERNELS
);
752 matcha ("end loop", gfc_match_omp_eos_error
, ST_OACC_END_LOOP
);
753 matcha ("end parallel loop", gfc_match_omp_eos_error
,
754 ST_OACC_END_PARALLEL_LOOP
);
755 matcha ("end parallel", gfc_match_omp_eos_error
, ST_OACC_END_PARALLEL
);
756 matcha ("end serial loop", gfc_match_omp_eos_error
,
757 ST_OACC_END_SERIAL_LOOP
);
758 matcha ("end serial", gfc_match_omp_eos_error
, ST_OACC_END_SERIAL
);
759 matcha ("enter data", gfc_match_oacc_enter_data
, ST_OACC_ENTER_DATA
);
760 matcha ("exit data", gfc_match_oacc_exit_data
, ST_OACC_EXIT_DATA
);
763 matcha ("host_data", gfc_match_oacc_host_data
, ST_OACC_HOST_DATA
);
766 matcha ("parallel loop", gfc_match_oacc_parallel_loop
,
767 ST_OACC_PARALLEL_LOOP
);
768 matcha ("parallel", gfc_match_oacc_parallel
, ST_OACC_PARALLEL
);
771 matcha ("kernels loop", gfc_match_oacc_kernels_loop
,
772 ST_OACC_KERNELS_LOOP
);
773 matcha ("kernels", gfc_match_oacc_kernels
, ST_OACC_KERNELS
);
776 matcha ("loop", gfc_match_oacc_loop
, ST_OACC_LOOP
);
779 matcha ("serial loop", gfc_match_oacc_serial_loop
, ST_OACC_SERIAL_LOOP
);
780 matcha ("serial", gfc_match_oacc_serial
, ST_OACC_SERIAL
);
783 matcha ("update", gfc_match_oacc_update
, ST_OACC_UPDATE
);
786 matcha ("wait", gfc_match_oacc_wait
, ST_OACC_WAIT
);
790 /* Directive not found or stored an error message.
791 Check and give up. */
794 if (gfc_error_check () == 0)
795 gfc_error_now ("Unclassifiable OpenACC directive at %C");
799 gfc_error_recovery ();
806 gfc_buffer_error (false);
807 gfc_current_locus
= old_locus
;
808 return ST_GET_FCN_CHARACTERISTICS
;
811 /* Checks for the ST_OMP_ALLOCATE. First, check whether all list items
812 are allocatables/pointers - and if so, assume it is associated with a Fortran
813 ALLOCATE stmt. If not, do some initial parsing-related checks and append
814 namelist to namespace.
815 The check follows OpenMP 5.1 by requiring an executable stmt or OpenMP
816 construct before a directive associated with an allocate statement
817 (-> ST_OMP_ALLOCATE_EXEC); instead of showing an error, conversion of
818 ST_OMP_ALLOCATE -> ST_OMP_ALLOCATE_EXEC would be an alternative. */
821 check_omp_allocate_stmt (locus
*loc
)
825 if (new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]->sym
== NULL
)
827 gfc_error ("%qs directive at %L must either have a variable argument or, "
828 "if associated with an ALLOCATE stmt, must be preceded by an "
829 "executable statement or OpenMP construct",
830 gfc_ascii_statement (ST_OMP_ALLOCATE
), loc
);
833 bool has_allocatable
= false;
834 bool has_non_allocatable
= false;
835 for (n
= new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]; n
; n
= n
->next
)
839 gfc_error ("Structure-component expression at %L in %qs directive not"
840 " permitted in declarative directive; as directive "
841 "associated with an ALLOCATE stmt it must be preceded by "
842 "an executable statement or OpenMP construct",
843 &n
->expr
->where
, gfc_ascii_statement (ST_OMP_ALLOCATE
));
846 /* Procedure pointers are not allocatable; hence, we do not regard them as
847 pointers here - and reject them later in gfc_resolve_omp_allocate. */
849 if (n
->sym
->ts
.type
== BT_CLASS
&& n
->sym
->attr
.class_ok
)
850 alloc_ptr
= (CLASS_DATA (n
->sym
)->attr
.allocatable
851 || CLASS_DATA (n
->sym
)->attr
.class_pointer
);
853 alloc_ptr
= n
->sym
->attr
.allocatable
|| n
->sym
->attr
.pointer
;
855 || (n
->sym
->ns
&& n
->sym
->ns
->proc_name
856 && (n
->sym
->ns
->proc_name
->attr
.allocatable
857 || n
->sym
->ns
->proc_name
->attr
.pointer
)))
858 has_allocatable
= true;
860 has_non_allocatable
= true;
862 /* All allocatables - assume it is allocated with an ALLOCATE stmt. */
863 if (has_allocatable
&& !has_non_allocatable
)
865 gfc_error ("%qs directive at %L associated with an ALLOCATE stmt must be "
866 "preceded by an executable statement or OpenMP construct; "
867 "note the variables in the list all have the allocatable or "
868 "pointer attribute", gfc_ascii_statement (ST_OMP_ALLOCATE
),
872 if (!gfc_current_ns
->omp_allocate
)
873 gfc_current_ns
->omp_allocate
874 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
];
877 for (n
= gfc_current_ns
->omp_allocate
; n
->next
; n
= n
->next
)
879 n
->next
= new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
];
881 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
] = NULL
;
882 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
887 /* Like match, but set a flag simd_matched if keyword matched
888 and if spec_only, goto do_spec_only without actually matching. */
889 #define matchs(keyword, subr, st) \
892 if (spec_only && gfc_match (keyword) == MATCH_YES) \
894 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
895 &simd_matched)) == MATCH_YES) \
900 else if (m2 == MATCH_ERROR) \
901 goto error_handling; \
903 undo_new_statement (); \
906 /* Like match, but don't match anything if not -fopenmp
907 and if spec_only, goto do_spec_only without actually matching. */
908 /* If the directive matched but the clauses failed, do not start
909 matching the next directive in the same switch statement. */
910 #define matcho(keyword, subr, st) \
915 else if (spec_only && gfc_match (keyword) == MATCH_YES) \
917 else if ((m2 = match_word (keyword, subr, &old_locus)) \
923 else if (m2 == MATCH_ERROR) \
924 goto error_handling; \
926 undo_new_statement (); \
929 /* Like match, but set a flag simd_matched if keyword matched. */
930 #define matchds(keyword, subr, st) \
933 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
934 &simd_matched)) == MATCH_YES) \
939 else if (m2 == MATCH_ERROR) \
940 goto error_handling; \
942 undo_new_statement (); \
945 /* Like match, but don't match anything if not -fopenmp. */
946 #define matchdo(keyword, subr, st) \
951 else if ((m2 = match_word (keyword, subr, &old_locus)) \
957 else if (m2 == MATCH_ERROR) \
958 goto error_handling; \
960 undo_new_statement (); \
964 decode_omp_directive (void)
968 bool simd_matched
= false;
969 bool spec_only
= false;
970 gfc_statement ret
= ST_NONE
;
973 gfc_enforce_clean_symbol_state ();
975 gfc_clear_error (); /* Clear any pending errors. */
976 gfc_clear_warning (); /* Clear any pending warnings. */
978 gfc_matching_function
= false;
980 if (gfc_current_state () == COMP_FUNCTION
981 && gfc_current_block ()->result
->ts
.kind
== -1)
984 old_locus
= gfc_current_locus
;
986 /* General OpenMP directive matching: Instead of testing every possible
987 statement, we eliminate most possibilities by peeking at the
990 c
= gfc_peek_ascii_char ();
992 /* match is for directives that should be recognized only if
993 -fopenmp, matchs for directives that should be recognized
994 if either -fopenmp or -fopenmp-simd.
995 Handle only the directives allowed in PURE procedures
996 first (those also shall not turn off implicit pure). */
1000 /* For -fopenmp-simd, ignore 'assumes'; note no clause starts with 's'. */
1001 if (!flag_openmp
&& gfc_match ("assumes") == MATCH_YES
)
1003 matcho ("assumes", gfc_match_omp_assumes
, ST_OMP_ASSUMES
);
1004 matchs ("assume", gfc_match_omp_assume
, ST_OMP_ASSUME
);
1008 matcho ("begin metadirective", gfc_match_omp_begin_metadirective
,
1009 ST_OMP_BEGIN_METADIRECTIVE
);
1013 matchds ("declare reduction", gfc_match_omp_declare_reduction
,
1014 ST_OMP_DECLARE_REDUCTION
);
1015 matchds ("declare simd", gfc_match_omp_declare_simd
,
1016 ST_OMP_DECLARE_SIMD
);
1017 matchdo ("declare target", gfc_match_omp_declare_target
,
1018 ST_OMP_DECLARE_TARGET
);
1019 matchdo ("declare variant", gfc_match_omp_declare_variant
,
1020 ST_OMP_DECLARE_VARIANT
);
1023 matchs ("end assume", gfc_match_omp_eos_error
, ST_OMP_END_ASSUME
);
1024 matcho ("end metadirective", gfc_match_omp_eos_error
,
1025 ST_OMP_END_METADIRECTIVE
);
1026 matchs ("end simd", gfc_match_omp_eos_error
, ST_OMP_END_SIMD
);
1027 matchs ("end tile", gfc_match_omp_eos_error
, ST_OMP_END_TILE
);
1028 matchs ("end unroll", gfc_match_omp_eos_error
, ST_OMP_END_UNROLL
);
1029 matcho ("error", gfc_match_omp_error
, ST_OMP_ERROR
);
1033 matcho ("metadirective", gfc_match_omp_metadirective
,
1034 ST_OMP_METADIRECTIVE
);
1038 matcho ("nothing", gfc_match_omp_nothing
, ST_NONE
);
1041 matchs ("scan", gfc_match_omp_scan
, ST_OMP_SCAN
);
1042 matchs ("simd", gfc_match_omp_simd
, ST_OMP_SIMD
);
1045 matchs ("tile", gfc_match_omp_tile
, ST_OMP_TILE
);
1048 matchs ("unroll", gfc_match_omp_unroll
, ST_OMP_UNROLL
);
1053 if (flag_openmp
&& gfc_pure (NULL
))
1055 gfc_error_now ("OpenMP directive at %C is not pure and thus may not "
1056 "appear in a PURE procedure");
1057 gfc_error_recovery ();
1061 /* match is for directives that should be recognized only if
1062 -fopenmp, matchs for directives that should be recognized
1063 if either -fopenmp or -fopenmp-simd. */
1068 matcho ("allocate", gfc_match_omp_allocate
, ST_OMP_ALLOCATE_EXEC
);
1070 matcho ("allocate", gfc_match_omp_allocate
, ST_OMP_ALLOCATE
);
1071 matcho ("allocators", gfc_match_omp_allocators
, ST_OMP_ALLOCATORS
);
1072 matcho ("atomic", gfc_match_omp_atomic
, ST_OMP_ATOMIC
);
1075 matcho ("barrier", gfc_match_omp_barrier
, ST_OMP_BARRIER
);
1078 matcho ("cancellation% point", gfc_match_omp_cancellation_point
,
1079 ST_OMP_CANCELLATION_POINT
);
1080 matcho ("cancel", gfc_match_omp_cancel
, ST_OMP_CANCEL
);
1081 matcho ("critical", gfc_match_omp_critical
, ST_OMP_CRITICAL
);
1084 matcho ("depobj", gfc_match_omp_depobj
, ST_OMP_DEPOBJ
);
1085 matcho ("dispatch", gfc_match_omp_dispatch
, ST_OMP_DISPATCH
);
1086 matchs ("distribute parallel do simd",
1087 gfc_match_omp_distribute_parallel_do_simd
,
1088 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
);
1089 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do
,
1090 ST_OMP_DISTRIBUTE_PARALLEL_DO
);
1091 matchs ("distribute simd", gfc_match_omp_distribute_simd
,
1092 ST_OMP_DISTRIBUTE_SIMD
);
1093 matcho ("distribute", gfc_match_omp_distribute
, ST_OMP_DISTRIBUTE
);
1094 matchs ("do simd", gfc_match_omp_do_simd
, ST_OMP_DO_SIMD
);
1095 matcho ("do", gfc_match_omp_do
, ST_OMP_DO
);
1098 matcho ("end allocators", gfc_match_omp_eos_error
, ST_OMP_END_ALLOCATORS
);
1099 matcho ("end atomic", gfc_match_omp_eos_error
, ST_OMP_END_ATOMIC
);
1100 matcho ("end critical", gfc_match_omp_end_critical
, ST_OMP_END_CRITICAL
);
1101 matcho ("end dispatch", gfc_match_omp_end_nowait
, ST_OMP_END_DISPATCH
);
1102 matchs ("end distribute parallel do simd", gfc_match_omp_eos_error
,
1103 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
);
1104 matcho ("end distribute parallel do", gfc_match_omp_eos_error
,
1105 ST_OMP_END_DISTRIBUTE_PARALLEL_DO
);
1106 matchs ("end distribute simd", gfc_match_omp_eos_error
,
1107 ST_OMP_END_DISTRIBUTE_SIMD
);
1108 matcho ("end distribute", gfc_match_omp_eos_error
, ST_OMP_END_DISTRIBUTE
);
1109 matchs ("end do simd", gfc_match_omp_end_nowait
, ST_OMP_END_DO_SIMD
);
1110 matcho ("end do", gfc_match_omp_end_nowait
, ST_OMP_END_DO
);
1111 matchs ("end loop", gfc_match_omp_eos_error
, ST_OMP_END_LOOP
);
1112 matcho ("end masked taskloop simd", gfc_match_omp_eos_error
,
1113 ST_OMP_END_MASKED_TASKLOOP_SIMD
);
1114 matcho ("end masked taskloop", gfc_match_omp_eos_error
,
1115 ST_OMP_END_MASKED_TASKLOOP
);
1116 matcho ("end masked", gfc_match_omp_eos_error
, ST_OMP_END_MASKED
);
1117 matcho ("end master taskloop simd", gfc_match_omp_eos_error
,
1118 ST_OMP_END_MASTER_TASKLOOP_SIMD
);
1119 matcho ("end master taskloop", gfc_match_omp_eos_error
,
1120 ST_OMP_END_MASTER_TASKLOOP
);
1121 matcho ("end master", gfc_match_omp_eos_error
, ST_OMP_END_MASTER
);
1122 matchs ("end ordered", gfc_match_omp_eos_error
, ST_OMP_END_ORDERED
);
1123 matchs ("end parallel do simd", gfc_match_omp_eos_error
,
1124 ST_OMP_END_PARALLEL_DO_SIMD
);
1125 matcho ("end parallel do", gfc_match_omp_eos_error
,
1126 ST_OMP_END_PARALLEL_DO
);
1127 matcho ("end parallel loop", gfc_match_omp_eos_error
,
1128 ST_OMP_END_PARALLEL_LOOP
);
1129 matcho ("end parallel masked taskloop simd", gfc_match_omp_eos_error
,
1130 ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
);
1131 matcho ("end parallel masked taskloop", gfc_match_omp_eos_error
,
1132 ST_OMP_END_PARALLEL_MASKED_TASKLOOP
);
1133 matcho ("end parallel masked", gfc_match_omp_eos_error
,
1134 ST_OMP_END_PARALLEL_MASKED
);
1135 matcho ("end parallel master taskloop simd", gfc_match_omp_eos_error
,
1136 ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
);
1137 matcho ("end parallel master taskloop", gfc_match_omp_eos_error
,
1138 ST_OMP_END_PARALLEL_MASTER_TASKLOOP
);
1139 matcho ("end parallel master", gfc_match_omp_eos_error
,
1140 ST_OMP_END_PARALLEL_MASTER
);
1141 matcho ("end parallel sections", gfc_match_omp_eos_error
,
1142 ST_OMP_END_PARALLEL_SECTIONS
);
1143 matcho ("end parallel workshare", gfc_match_omp_eos_error
,
1144 ST_OMP_END_PARALLEL_WORKSHARE
);
1145 matcho ("end parallel", gfc_match_omp_eos_error
, ST_OMP_END_PARALLEL
);
1146 matcho ("end scope", gfc_match_omp_end_nowait
, ST_OMP_END_SCOPE
);
1147 matcho ("end sections", gfc_match_omp_end_nowait
, ST_OMP_END_SECTIONS
);
1148 matcho ("end single", gfc_match_omp_end_single
, ST_OMP_END_SINGLE
);
1149 matcho ("end target data", gfc_match_omp_eos_error
, ST_OMP_END_TARGET_DATA
);
1150 matchs ("end target parallel do simd", gfc_match_omp_end_nowait
,
1151 ST_OMP_END_TARGET_PARALLEL_DO_SIMD
);
1152 matcho ("end target parallel do", gfc_match_omp_end_nowait
,
1153 ST_OMP_END_TARGET_PARALLEL_DO
);
1154 matcho ("end target parallel loop", gfc_match_omp_end_nowait
,
1155 ST_OMP_END_TARGET_PARALLEL_LOOP
);
1156 matcho ("end target parallel", gfc_match_omp_end_nowait
,
1157 ST_OMP_END_TARGET_PARALLEL
);
1158 matchs ("end target simd", gfc_match_omp_end_nowait
, ST_OMP_END_TARGET_SIMD
);
1159 matchs ("end target teams distribute parallel do simd",
1160 gfc_match_omp_end_nowait
,
1161 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1162 matcho ("end target teams distribute parallel do", gfc_match_omp_end_nowait
,
1163 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1164 matchs ("end target teams distribute simd", gfc_match_omp_end_nowait
,
1165 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
);
1166 matcho ("end target teams distribute", gfc_match_omp_end_nowait
,
1167 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
);
1168 matcho ("end target teams loop", gfc_match_omp_end_nowait
,
1169 ST_OMP_END_TARGET_TEAMS_LOOP
);
1170 matcho ("end target teams", gfc_match_omp_end_nowait
,
1171 ST_OMP_END_TARGET_TEAMS
);
1172 matcho ("end target", gfc_match_omp_end_nowait
, ST_OMP_END_TARGET
);
1173 matcho ("end taskgroup", gfc_match_omp_eos_error
, ST_OMP_END_TASKGROUP
);
1174 matchs ("end taskloop simd", gfc_match_omp_eos_error
,
1175 ST_OMP_END_TASKLOOP_SIMD
);
1176 matcho ("end taskloop", gfc_match_omp_eos_error
, ST_OMP_END_TASKLOOP
);
1177 matcho ("end task", gfc_match_omp_eos_error
, ST_OMP_END_TASK
);
1178 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos_error
,
1179 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1180 matcho ("end teams distribute parallel do", gfc_match_omp_eos_error
,
1181 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1182 matchs ("end teams distribute simd", gfc_match_omp_eos_error
,
1183 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
);
1184 matcho ("end teams distribute", gfc_match_omp_eos_error
,
1185 ST_OMP_END_TEAMS_DISTRIBUTE
);
1186 matcho ("end teams loop", gfc_match_omp_eos_error
, ST_OMP_END_TEAMS_LOOP
);
1187 matcho ("end teams", gfc_match_omp_eos_error
, ST_OMP_END_TEAMS
);
1188 matcho ("end workshare", gfc_match_omp_end_nowait
,
1189 ST_OMP_END_WORKSHARE
);
1192 matcho ("flush", gfc_match_omp_flush
, ST_OMP_FLUSH
);
1195 matcho ("interop", gfc_match_omp_interop
, ST_OMP_INTEROP
);
1198 matcho ("masked taskloop simd", gfc_match_omp_masked_taskloop_simd
,
1199 ST_OMP_MASKED_TASKLOOP_SIMD
);
1200 matcho ("masked taskloop", gfc_match_omp_masked_taskloop
,
1201 ST_OMP_MASKED_TASKLOOP
);
1202 matcho ("masked", gfc_match_omp_masked
, ST_OMP_MASKED
);
1203 matcho ("master taskloop simd", gfc_match_omp_master_taskloop_simd
,
1204 ST_OMP_MASTER_TASKLOOP_SIMD
);
1205 matcho ("master taskloop", gfc_match_omp_master_taskloop
,
1206 ST_OMP_MASTER_TASKLOOP
);
1207 matcho ("master", gfc_match_omp_master
, ST_OMP_MASTER
);
1210 matcho ("nothing", gfc_match_omp_nothing
, ST_NONE
);
1213 matchs ("loop", gfc_match_omp_loop
, ST_OMP_LOOP
);
1216 if (gfc_match ("ordered depend (") == MATCH_YES
1217 || gfc_match ("ordered doacross (") == MATCH_YES
)
1219 gfc_current_locus
= old_locus
;
1222 matcho ("ordered", gfc_match_omp_ordered_depend
,
1223 ST_OMP_ORDERED_DEPEND
);
1226 matchs ("ordered", gfc_match_omp_ordered
, ST_OMP_ORDERED
);
1229 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd
,
1230 ST_OMP_PARALLEL_DO_SIMD
);
1231 matcho ("parallel do", gfc_match_omp_parallel_do
, ST_OMP_PARALLEL_DO
);
1232 matcho ("parallel loop", gfc_match_omp_parallel_loop
,
1233 ST_OMP_PARALLEL_LOOP
);
1234 matcho ("parallel masked taskloop simd",
1235 gfc_match_omp_parallel_masked_taskloop_simd
,
1236 ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
);
1237 matcho ("parallel masked taskloop",
1238 gfc_match_omp_parallel_masked_taskloop
,
1239 ST_OMP_PARALLEL_MASKED_TASKLOOP
);
1240 matcho ("parallel masked", gfc_match_omp_parallel_masked
,
1241 ST_OMP_PARALLEL_MASKED
);
1242 matcho ("parallel master taskloop simd",
1243 gfc_match_omp_parallel_master_taskloop_simd
,
1244 ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
);
1245 matcho ("parallel master taskloop",
1246 gfc_match_omp_parallel_master_taskloop
,
1247 ST_OMP_PARALLEL_MASTER_TASKLOOP
);
1248 matcho ("parallel master", gfc_match_omp_parallel_master
,
1249 ST_OMP_PARALLEL_MASTER
);
1250 matcho ("parallel sections", gfc_match_omp_parallel_sections
,
1251 ST_OMP_PARALLEL_SECTIONS
);
1252 matcho ("parallel workshare", gfc_match_omp_parallel_workshare
,
1253 ST_OMP_PARALLEL_WORKSHARE
);
1254 matcho ("parallel", gfc_match_omp_parallel
, ST_OMP_PARALLEL
);
1257 matcho ("requires", gfc_match_omp_requires
, ST_OMP_REQUIRES
);
1260 matcho ("scope", gfc_match_omp_scope
, ST_OMP_SCOPE
);
1261 matcho ("sections", gfc_match_omp_sections
, ST_OMP_SECTIONS
);
1262 matcho ("section", gfc_match_omp_eos_error
, ST_OMP_SECTION
);
1263 matcho ("single", gfc_match_omp_single
, ST_OMP_SINGLE
);
1266 matcho ("target data", gfc_match_omp_target_data
, ST_OMP_TARGET_DATA
);
1267 matcho ("target enter data", gfc_match_omp_target_enter_data
,
1268 ST_OMP_TARGET_ENTER_DATA
);
1269 matcho ("target exit data", gfc_match_omp_target_exit_data
,
1270 ST_OMP_TARGET_EXIT_DATA
);
1271 matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd
,
1272 ST_OMP_TARGET_PARALLEL_DO_SIMD
);
1273 matcho ("target parallel do", gfc_match_omp_target_parallel_do
,
1274 ST_OMP_TARGET_PARALLEL_DO
);
1275 matcho ("target parallel loop", gfc_match_omp_target_parallel_loop
,
1276 ST_OMP_TARGET_PARALLEL_LOOP
);
1277 matcho ("target parallel", gfc_match_omp_target_parallel
,
1278 ST_OMP_TARGET_PARALLEL
);
1279 matchs ("target simd", gfc_match_omp_target_simd
, ST_OMP_TARGET_SIMD
);
1280 matchs ("target teams distribute parallel do simd",
1281 gfc_match_omp_target_teams_distribute_parallel_do_simd
,
1282 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1283 matcho ("target teams distribute parallel do",
1284 gfc_match_omp_target_teams_distribute_parallel_do
,
1285 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1286 matchs ("target teams distribute simd",
1287 gfc_match_omp_target_teams_distribute_simd
,
1288 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
);
1289 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute
,
1290 ST_OMP_TARGET_TEAMS_DISTRIBUTE
);
1291 matcho ("target teams loop", gfc_match_omp_target_teams_loop
,
1292 ST_OMP_TARGET_TEAMS_LOOP
);
1293 matcho ("target teams", gfc_match_omp_target_teams
, ST_OMP_TARGET_TEAMS
);
1294 matcho ("target update", gfc_match_omp_target_update
,
1295 ST_OMP_TARGET_UPDATE
);
1296 matcho ("target", gfc_match_omp_target
, ST_OMP_TARGET
);
1297 matcho ("taskgroup", gfc_match_omp_taskgroup
, ST_OMP_TASKGROUP
);
1298 matchs ("taskloop simd", gfc_match_omp_taskloop_simd
,
1299 ST_OMP_TASKLOOP_SIMD
);
1300 matcho ("taskloop", gfc_match_omp_taskloop
, ST_OMP_TASKLOOP
);
1301 matcho ("taskwait", gfc_match_omp_taskwait
, ST_OMP_TASKWAIT
);
1302 matcho ("taskyield", gfc_match_omp_taskyield
, ST_OMP_TASKYIELD
);
1303 matcho ("task", gfc_match_omp_task
, ST_OMP_TASK
);
1304 matchs ("teams distribute parallel do simd",
1305 gfc_match_omp_teams_distribute_parallel_do_simd
,
1306 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1307 matcho ("teams distribute parallel do",
1308 gfc_match_omp_teams_distribute_parallel_do
,
1309 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1310 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd
,
1311 ST_OMP_TEAMS_DISTRIBUTE_SIMD
);
1312 matcho ("teams distribute", gfc_match_omp_teams_distribute
,
1313 ST_OMP_TEAMS_DISTRIBUTE
);
1314 matcho ("teams loop", gfc_match_omp_teams_loop
, ST_OMP_TEAMS_LOOP
);
1315 matcho ("teams", gfc_match_omp_teams
, ST_OMP_TEAMS
);
1316 matchdo ("threadprivate", gfc_match_omp_threadprivate
,
1317 ST_OMP_THREADPRIVATE
);
1320 matcho ("workshare", gfc_match_omp_workshare
, ST_OMP_WORKSHARE
);
1324 /* All else has failed, so give up. See if any of the matchers has
1325 stored an error message of some sort. Don't error out if
1326 not -fopenmp and simd_matched is false, i.e. if a directive other
1327 than one marked with match has been seen. */
1330 if (flag_openmp
|| simd_matched
)
1332 if (!gfc_error_check ())
1333 gfc_error_now ("Unclassifiable OpenMP directive at %C");
1336 /* If parsing a metadirective, let the caller deal with the cleanup. */
1337 if (gfc_matching_omp_context_selector
)
1340 reject_statement ();
1342 gfc_error_recovery ();
1347 if (ret
== ST_OMP_ERROR
&& new_st
.ext
.omp_clauses
->at
== OMP_AT_EXECUTION
)
1349 gfc_unset_implicit_pure (NULL
);
1351 if (gfc_pure (NULL
))
1353 gfc_error_now ("OpenMP ERROR directive at %L with %<at(execution)%> "
1354 "clause in a PURE procedure", &old_locus
);
1355 reject_statement ();
1356 gfc_error_recovery ();
1362 gfc_unset_implicit_pure (NULL
);
1364 if (!flag_openmp
&& gfc_pure (NULL
))
1366 gfc_error_now ("OpenMP directive at %C is not pure and thus may not "
1367 "appear in a PURE procedure");
1368 reject_statement ();
1369 gfc_error_recovery ();
1373 if (ret
== ST_OMP_ALLOCATE
&& !check_omp_allocate_stmt (&old_locus
))
1374 goto error_handling
;
1378 /* For the constraints on clauses with the global requirement property,
1379 we set omp_target_seen. This included all clauses that take the
1380 DEVICE clause, (BEGIN) DECLARE_TARGET and procedures run the device
1381 (which effectively is implied by the former). */
1382 case ST_OMP_DECLARE_TARGET
:
1383 case ST_OMP_INTEROP
:
1385 case ST_OMP_TARGET_DATA
:
1386 case ST_OMP_TARGET_ENTER_DATA
:
1387 case ST_OMP_TARGET_EXIT_DATA
:
1388 case ST_OMP_TARGET_TEAMS
:
1389 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
1390 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
1391 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
1392 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
1393 case ST_OMP_TARGET_TEAMS_LOOP
:
1394 case ST_OMP_TARGET_PARALLEL
:
1395 case ST_OMP_TARGET_PARALLEL_DO
:
1396 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
1397 case ST_OMP_TARGET_PARALLEL_LOOP
:
1398 case ST_OMP_TARGET_SIMD
:
1399 case ST_OMP_TARGET_UPDATE
:
1401 gfc_namespace
*prog_unit
= gfc_current_ns
;
1402 while (prog_unit
->parent
)
1404 if (gfc_state_stack
->previous
1405 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
1407 prog_unit
= prog_unit
->parent
;
1409 prog_unit
->omp_target_seen
= true;
1412 case ST_OMP_ALLOCATE_EXEC
:
1413 case ST_OMP_ALLOCATORS
:
1415 case ST_OMP_TEAMS_DISTRIBUTE
:
1416 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
1417 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
1418 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
1419 case ST_OMP_TEAMS_LOOP
:
1420 for (gfc_state_data
*stk
= gfc_state_stack
->previous
; stk
;
1421 stk
= stk
->previous
)
1422 if (stk
&& stk
->tail
)
1423 switch (stk
->tail
->op
)
1425 case EXEC_OMP_TARGET
:
1426 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
1427 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
1428 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
1429 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
1430 case EXEC_OMP_TARGET_TEAMS_LOOP
:
1431 case EXEC_OMP_TARGET_PARALLEL
:
1432 case EXEC_OMP_TARGET_PARALLEL_DO
:
1433 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD
:
1434 case EXEC_OMP_TARGET_PARALLEL_LOOP
:
1435 case EXEC_OMP_TARGET_SIMD
:
1436 if (ret
== ST_OMP_ALLOCATE_EXEC
|| ret
== ST_OMP_ALLOCATORS
)
1437 new_st
.ext
.omp_clauses
->contained_in_target_construct
= 1;
1439 stk
->tail
->ext
.omp_clauses
->contains_teams_construct
= 1;
1446 if (new_st
.ext
.omp_clauses
->at
!= OMP_AT_EXECUTION
)
1454 reject_statement ();
1456 gfc_buffer_error (false);
1457 gfc_current_locus
= old_locus
;
1458 return ST_GET_FCN_CHARACTERISTICS
;
1462 match_omp_directive (void)
1464 return decode_omp_directive ();
1467 static gfc_statement
1468 decode_gcc_attribute (void)
1472 gfc_enforce_clean_symbol_state ();
1474 gfc_clear_error (); /* Clear any pending errors. */
1475 gfc_clear_warning (); /* Clear any pending warnings. */
1476 old_locus
= gfc_current_locus
;
1478 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
1479 match ("unroll", gfc_match_gcc_unroll
, ST_NONE
);
1480 match ("builtin", gfc_match_gcc_builtin
, ST_NONE
);
1481 match ("ivdep", gfc_match_gcc_ivdep
, ST_NONE
);
1482 match ("vector", gfc_match_gcc_vector
, ST_NONE
);
1483 match ("novector", gfc_match_gcc_novector
, ST_NONE
);
1485 /* All else has failed, so give up. See if any of the matchers has
1486 stored an error message of some sort. */
1488 if (!gfc_error_check ())
1491 gfc_error_now ("Unclassifiable GCC directive at %C");
1493 gfc_warning_now (0, "Unclassifiable GCC directive at %C, ignored");
1496 reject_statement ();
1498 gfc_error_recovery ();
1505 /* Assert next length characters to be equal to token in free form. */
1508 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
1513 c
= gfc_next_ascii_char ();
1514 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
1515 gcc_assert (c
== token
[i
]);
1517 gcc_assert (gfc_is_whitespace(c
));
1518 gfc_gobble_whitespace ();
1519 if (last_was_use_stmt
)
1523 /* Get the next statement in free form source. */
1525 static gfc_statement
1532 at_bol
= gfc_at_bol ();
1533 gfc_gobble_whitespace ();
1535 c
= gfc_peek_ascii_char ();
1541 /* Found a statement label? */
1542 m
= gfc_match_st_label (&gfc_statement_label
);
1544 d
= gfc_peek_ascii_char ();
1545 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
1547 gfc_match_small_literal_int (&i
, &cnt
);
1550 gfc_error_now ("Too many digits in statement label at %C");
1553 gfc_error_now ("Zero is not a valid statement label at %C");
1556 c
= gfc_next_ascii_char ();
1559 if (!gfc_is_whitespace (c
))
1560 gfc_error_now ("Non-numeric character in statement label at %C");
1566 label_locus
= gfc_current_locus
;
1568 gfc_gobble_whitespace ();
1570 if (at_bol
&& gfc_peek_ascii_char () == ';')
1572 gfc_error_now ("Semicolon at %C needs to be preceded by "
1574 gfc_next_ascii_char (); /* Eat up the semicolon. */
1578 if (gfc_match_eos () == MATCH_YES
)
1579 gfc_error_now ("Statement label without statement at %L",
1585 /* Comments have already been skipped by the time we get here,
1586 except for GCC attributes and OpenMP/OpenACC directives. */
1588 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1589 c
= gfc_peek_ascii_char ();
1595 c
= gfc_next_ascii_char ();
1596 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1597 gcc_assert (c
== "gcc$"[i
]);
1599 gfc_gobble_whitespace ();
1600 return decode_gcc_attribute ();
1605 /* Since both OpenMP and OpenACC directives starts with
1606 !$ character sequence, we must check all flags combinations */
1607 if ((flag_openmp
|| flag_openmp_simd
)
1610 verify_token_free ("$omp", 4, last_was_use_stmt
);
1611 return decode_omp_directive ();
1613 else if ((flag_openmp
|| flag_openmp_simd
)
1616 gfc_next_ascii_char (); /* Eat up dollar character */
1617 c
= gfc_peek_ascii_char ();
1621 verify_token_free ("omp", 3, last_was_use_stmt
);
1622 return decode_omp_directive ();
1626 verify_token_free ("acc", 3, last_was_use_stmt
);
1627 return decode_oacc_directive ();
1630 else if (flag_openacc
)
1632 verify_token_free ("$acc", 4, last_was_use_stmt
);
1633 return decode_oacc_directive ();
1639 if (at_bol
&& c
== ';')
1641 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1642 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1644 gfc_next_ascii_char (); /* Eat up the semicolon. */
1648 return decode_statement ();
1651 /* Assert next length characters to be equal to token in fixed form. */
1654 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1657 char c
= gfc_next_char_literal (NONSTRING
);
1659 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1660 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1662 if (c
!= ' ' && c
!= '0')
1664 gfc_buffer_error (false);
1665 gfc_error ("Bad continuation line at %C");
1668 if (last_was_use_stmt
)
1674 /* Get the next statement in fixed-form source. */
1676 static gfc_statement
1679 int label
, digit_flag
, i
;
1684 return decode_statement ();
1686 /* Skip past the current label field, parsing a statement label if
1687 one is there. This is a weird number parser, since the number is
1688 contained within five columns and can have any kind of embedded
1689 spaces. We also check for characters that make the rest of the
1695 for (i
= 0; i
< 5; i
++)
1697 c
= gfc_next_char_literal (NONSTRING
);
1714 label
= label
* 10 + ((unsigned char) c
- '0');
1715 label_locus
= gfc_current_locus
;
1719 /* Comments have already been skipped by the time we get
1720 here, except for GCC attributes and OpenMP directives. */
1723 c
= gfc_next_char_literal (NONSTRING
);
1725 if (TOLOWER (c
) == 'g')
1727 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1728 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1730 return decode_gcc_attribute ();
1734 if ((flag_openmp
|| flag_openmp_simd
)
1737 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1739 return decode_omp_directive ();
1741 else if ((flag_openmp
|| flag_openmp_simd
)
1744 c
= gfc_next_char_literal(NONSTRING
);
1745 if (c
== 'o' || c
== 'O')
1747 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1749 return decode_omp_directive ();
1751 else if (c
== 'a' || c
== 'A')
1753 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1755 return decode_oacc_directive ();
1758 else if (flag_openacc
)
1760 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1762 return decode_oacc_directive ();
1767 /* Comments have already been skipped by the time we get
1768 here so don't bother checking for them. */
1771 gfc_buffer_error (false);
1772 gfc_error ("Non-numeric character in statement label at %C");
1780 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1783 /* We've found a valid statement label. */
1784 gfc_statement_label
= gfc_get_st_label (label
);
1788 /* Since this line starts a statement, it cannot be a continuation
1789 of a previous statement. If we see something here besides a
1790 space or zero, it must be a bad continuation line. */
1792 c
= gfc_next_char_literal (NONSTRING
);
1796 if (c
!= ' ' && c
!= '0')
1798 gfc_buffer_error (false);
1799 gfc_error ("Bad continuation line at %C");
1803 /* Now that we've taken care of the statement label columns, we have
1804 to make sure that the first nonblank character is not a '!'. If
1805 it is, the rest of the line is a comment. */
1809 loc
= gfc_current_locus
;
1810 c
= gfc_next_char_literal (NONSTRING
);
1812 while (gfc_is_whitespace (c
));
1816 gfc_current_locus
= loc
;
1821 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1822 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1823 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1828 if (gfc_match_eos () == MATCH_YES
)
1831 /* At this point, we've got a nonblank statement to parse. */
1832 return decode_statement ();
1836 gfc_error_now ("Statement label without statement at %L", &label_locus
);
1838 gfc_current_locus
.u
.lb
->truncated
= 0;
1839 gfc_advance_line ();
1844 /* Return the next non-ST_NONE statement to the caller. We also worry
1845 about including files and the ends of include files at this stage. */
1847 static gfc_statement
1848 next_statement (void)
1853 gfc_enforce_clean_symbol_state ();
1854 gfc_save_module_list ();
1856 gfc_new_block
= NULL
;
1858 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1859 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1862 gfc_statement_label
= NULL
;
1863 gfc_buffer_error (true);
1866 gfc_advance_line ();
1868 gfc_skip_comments ();
1876 if (gfc_define_undef_line ())
1879 old_locus
= gfc_current_locus
;
1881 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1887 gfc_buffer_error (false);
1889 if (st
== ST_GET_FCN_CHARACTERISTICS
)
1891 if (gfc_statement_label
!= NULL
)
1893 gfc_free_st_label (gfc_statement_label
);
1894 gfc_statement_label
= NULL
;
1896 gfc_current_locus
= old_locus
;
1900 check_statement_label (st
);
1906 /****************************** Parser ***********************************/
1908 /* The parser subroutines are of type 'try' that fail if the file ends
1911 /* Macros that expand to case-labels for various classes of
1912 statements. Start with executable statements that directly do
1915 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1916 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1917 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1918 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1919 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1920 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1921 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1922 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1923 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1924 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: case ST_OMP_DEPOBJ: \
1925 case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
1926 case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: case ST_OMP_ERROR: \
1927 case ST_OMP_INTEROP: \
1928 case ST_ERROR_STOP: case ST_OMP_SCAN: case ST_SYNC_ALL: \
1929 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1930 case ST_FORM_TEAM: case ST_CHANGE_TEAM: \
1931 case ST_END_TEAM: case ST_SYNC_TEAM: \
1932 case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \
1933 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1934 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1936 /* Statements that mark other executable statements. */
1938 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1939 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1940 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1941 case ST_SELECT_RANK: case ST_OMP_PARALLEL: case ST_OMP_PARALLEL_MASKED: \
1942 case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
1943 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case ST_OMP_PARALLEL_MASTER: \
1944 case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
1945 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
1946 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1947 case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASKED_TASKLOOP: \
1948 case ST_OMP_MASKED_TASKLOOP_SIMD: \
1949 case ST_OMP_MASTER: case ST_OMP_MASTER_TASKLOOP: \
1950 case ST_OMP_MASTER_TASKLOOP_SIMD: case ST_OMP_SCOPE: case ST_OMP_SINGLE: \
1951 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1952 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1953 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1954 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1955 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1956 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1957 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1958 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1959 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1960 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1961 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1962 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1963 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1964 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1965 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
1966 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
1967 case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
1968 case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \
1969 case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \
1970 case ST_OMP_ALLOCATE_EXEC: case ST_OMP_ALLOCATORS: case ST_OMP_ASSUME: \
1971 case ST_OMP_TILE: case ST_OMP_UNROLL: case ST_OMP_DISPATCH: \
1973 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1974 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1975 case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \
1978 /* Declaration statements */
1980 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1981 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1982 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE
1984 /* OpenMP and OpenACC declaration statements, which may appear anywhere in
1985 the specification part. */
1987 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1988 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \
1989 case ST_OMP_DECLARE_VARIANT: case ST_OMP_ALLOCATE: case ST_OMP_ASSUMES: \
1990 case ST_OMP_REQUIRES: case ST_OACC_ROUTINE: case ST_OACC_DECLARE
1992 /* OpenMP statements that are followed by a structured block. */
1994 #define case_omp_structured_block case ST_OMP_ASSUME: case ST_OMP_PARALLEL: \
1995 case ST_OMP_PARALLEL_MASKED: case ST_OMP_PARALLEL_MASTER: \
1996 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_ORDERED: \
1997 case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASTER: \
1998 case ST_OMP_SCOPE: case ST_OMP_SECTIONS: case ST_OMP_SINGLE: \
1999 case ST_OMP_TARGET: case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_PARALLEL: \
2000 case ST_OMP_TARGET_TEAMS: case ST_OMP_TEAMS: case ST_OMP_TASK: \
2001 case ST_OMP_TASKGROUP: \
2002 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE
2004 /* OpenMP statements that are followed by a do loop. */
2006 #define case_omp_do case ST_OMP_DISTRIBUTE: \
2007 case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
2008 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE_SIMD: \
2009 case ST_OMP_DO: case ST_OMP_DO_SIMD: case ST_OMP_LOOP: \
2010 case ST_OMP_PARALLEL_DO: case ST_OMP_PARALLEL_DO_SIMD: \
2011 case ST_OMP_PARALLEL_LOOP: case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
2012 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: \
2013 case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
2014 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
2015 case ST_OMP_MASKED_TASKLOOP: case ST_OMP_MASKED_TASKLOOP_SIMD: \
2016 case ST_OMP_MASTER_TASKLOOP: case ST_OMP_MASTER_TASKLOOP_SIMD: \
2018 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
2019 case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_SIMD: \
2020 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
2021 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
2022 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
2023 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: case ST_OMP_TARGET_TEAMS_LOOP: \
2024 case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
2025 case ST_OMP_TEAMS_DISTRIBUTE: case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
2026 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
2027 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: case ST_OMP_TEAMS_LOOP: \
2028 case ST_OMP_TILE: case ST_OMP_UNROLL
2030 /* Block end statements. Errors associated with interchanging these
2031 are detected in gfc_match_end(). */
2033 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
2034 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
2035 case ST_END_BLOCK: case ST_END_ASSOCIATE
2038 /* Push a new state onto the stack. */
2041 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
2043 p
->state
= new_state
;
2044 p
->previous
= gfc_state_stack
;
2046 p
->head
= p
->tail
= NULL
;
2047 p
->do_variable
= NULL
;
2048 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
2049 p
->ext
.oacc_declare_clauses
= NULL
;
2051 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
2052 construct statement was accepted right before pushing the state. Thus,
2053 the construct's gfc_code is available as tail of the parent state. */
2054 gcc_assert (gfc_state_stack
);
2055 p
->construct
= gfc_state_stack
->tail
;
2057 gfc_state_stack
= p
;
2061 /* Pop the current state. */
2065 gfc_state_stack
= gfc_state_stack
->previous
;
2069 /* Try to find the given state in the state stack. */
2072 gfc_find_state (gfc_compile_state state
)
2076 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
2077 if (p
->state
== state
)
2080 return (p
== NULL
) ? false : true;
2084 /* Starts a new level in the statement list. */
2087 new_level (gfc_code
*q
)
2091 p
= q
->block
= gfc_get_code (EXEC_NOP
);
2093 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
2099 /* Add the current new_st code structure and adds it to the current
2100 program unit. As a side-effect, it zeroes the new_st. */
2103 add_statement (void)
2107 p
= XCNEW (gfc_code
);
2110 p
->loc
= gfc_current_locus
;
2112 if (gfc_state_stack
->head
== NULL
)
2113 gfc_state_stack
->head
= p
;
2115 gfc_state_stack
->tail
->next
= p
;
2117 while (p
->next
!= NULL
)
2120 gfc_state_stack
->tail
= p
;
2122 gfc_clear_new_st ();
2128 /* Frees everything associated with the current statement. */
2131 undo_new_statement (void)
2133 gfc_free_statements (new_st
.block
);
2134 gfc_free_statements (new_st
.next
);
2135 gfc_free_statement (&new_st
);
2136 gfc_clear_new_st ();
2140 /* If the current statement has a statement label, make sure that it
2141 is allowed to, or should have one. */
2144 check_statement_label (gfc_statement st
)
2148 if (gfc_statement_label
== NULL
)
2150 if (st
== ST_FORMAT
)
2151 gfc_error ("FORMAT statement at %L does not have a statement label",
2158 case ST_END_PROGRAM
:
2159 case ST_END_FUNCTION
:
2160 case ST_END_SUBROUTINE
:
2164 case ST_END_CRITICAL
:
2166 case ST_END_ASSOCIATE
:
2169 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
2170 type
= ST_LABEL_DO_TARGET
;
2172 type
= ST_LABEL_TARGET
;
2176 type
= ST_LABEL_FORMAT
;
2179 /* Statement labels are not restricted from appearing on a
2180 particular line. However, there are plenty of situations
2181 where the resulting label can't be referenced. */
2184 type
= ST_LABEL_BAD_TARGET
;
2188 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
2190 new_st
.here
= gfc_statement_label
;
2194 /* Figures out what the enclosing program unit is. This will be a
2195 function, subroutine, program, block data or module. */
2198 gfc_enclosing_unit (gfc_compile_state
* result
)
2202 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
2203 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
2204 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
2205 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
2214 *result
= COMP_PROGRAM
;
2219 /* Translate a statement enum to a string. If strip_sentinel is true,
2220 the !$OMP/!$ACC sentinel is excluded. */
2223 gfc_ascii_statement (gfc_statement st
, bool strip_sentinel
)
2229 case ST_ARITHMETIC_IF
:
2230 p
= _("arithmetic IF");
2239 p
= _("attribute declaration");
2275 p
= _("data declaration");
2289 case ST_STRUCTURE_DECL
:
2292 case ST_DERIVED_DECL
:
2293 p
= _("derived type declaration");
2316 case ST_CHANGE_TEAM
:
2328 case ST_END_ASSOCIATE
:
2329 p
= "END ASSOCIATE";
2334 case ST_END_BLOCK_DATA
:
2335 p
= "END BLOCK DATA";
2337 case ST_END_CRITICAL
:
2349 case ST_END_FUNCTION
:
2355 case ST_END_INTERFACE
:
2356 p
= "END INTERFACE";
2361 case ST_END_SUBMODULE
:
2362 p
= "END SUBMODULE";
2364 case ST_END_PROGRAM
:
2370 case ST_END_SUBROUTINE
:
2371 p
= "END SUBROUTINE";
2376 case ST_END_STRUCTURE
:
2377 p
= "END STRUCTURE";
2391 case ST_EQUIVALENCE
:
2403 case ST_FORALL_BLOCK
: /* Fall through */
2425 case ST_IMPLICIT_NONE
:
2426 p
= "IMPLICIT NONE";
2428 case ST_IMPLIED_ENDDO
:
2429 p
= _("implied END DO");
2461 case ST_MODULE_PROC
:
2462 p
= "MODULE PROCEDURE";
2494 case ST_SYNC_IMAGES
:
2497 case ST_SYNC_MEMORY
:
2512 case ST_WHERE_BLOCK
: /* Fall through */
2523 p
= _("assignment");
2525 case ST_POINTER_ASSIGNMENT
:
2526 p
= _("pointer assignment");
2528 case ST_SELECT_CASE
:
2531 case ST_SELECT_TYPE
:
2534 case ST_SELECT_RANK
:
2552 case ST_STATEMENT_FUNCTION
:
2553 p
= "STATEMENT FUNCTION";
2555 case ST_LABEL_ASSIGNMENT
:
2556 p
= "LABEL ASSIGNMENT";
2559 p
= "ENUM DEFINITION";
2562 p
= "ENUMERATOR DEFINITION";
2567 case ST_OACC_PARALLEL_LOOP
:
2568 p
= "!$ACC PARALLEL LOOP";
2570 case ST_OACC_END_PARALLEL_LOOP
:
2571 p
= "!$ACC END PARALLEL LOOP";
2573 case ST_OACC_PARALLEL
:
2574 p
= "!$ACC PARALLEL";
2576 case ST_OACC_END_PARALLEL
:
2577 p
= "!$ACC END PARALLEL";
2579 case ST_OACC_KERNELS
:
2580 p
= "!$ACC KERNELS";
2582 case ST_OACC_END_KERNELS
:
2583 p
= "!$ACC END KERNELS";
2585 case ST_OACC_KERNELS_LOOP
:
2586 p
= "!$ACC KERNELS LOOP";
2588 case ST_OACC_END_KERNELS_LOOP
:
2589 p
= "!$ACC END KERNELS LOOP";
2591 case ST_OACC_SERIAL_LOOP
:
2592 p
= "!$ACC SERIAL LOOP";
2594 case ST_OACC_END_SERIAL_LOOP
:
2595 p
= "!$ACC END SERIAL LOOP";
2597 case ST_OACC_SERIAL
:
2600 case ST_OACC_END_SERIAL
:
2601 p
= "!$ACC END SERIAL";
2606 case ST_OACC_END_DATA
:
2607 p
= "!$ACC END DATA";
2609 case ST_OACC_HOST_DATA
:
2610 p
= "!$ACC HOST_DATA";
2612 case ST_OACC_END_HOST_DATA
:
2613 p
= "!$ACC END HOST_DATA";
2618 case ST_OACC_END_LOOP
:
2619 p
= "!$ACC END LOOP";
2621 case ST_OACC_DECLARE
:
2622 p
= "!$ACC DECLARE";
2624 case ST_OACC_UPDATE
:
2633 case ST_OACC_ENTER_DATA
:
2634 p
= "!$ACC ENTER DATA";
2636 case ST_OACC_EXIT_DATA
:
2637 p
= "!$ACC EXIT DATA";
2639 case ST_OACC_ROUTINE
:
2640 p
= "!$ACC ROUTINE";
2642 case ST_OACC_ATOMIC
:
2645 case ST_OACC_END_ATOMIC
:
2646 p
= "!$ACC END ATOMIC";
2648 case ST_OMP_ALLOCATE
:
2649 case ST_OMP_ALLOCATE_EXEC
:
2650 p
= "!$OMP ALLOCATE";
2652 case ST_OMP_ALLOCATORS
:
2653 p
= "!$OMP ALLOCATORS";
2658 case ST_OMP_ASSUMES
:
2659 p
= "!$OMP ASSUMES";
2664 case ST_OMP_BARRIER
:
2665 p
= "!$OMP BARRIER";
2667 case ST_OMP_BEGIN_METADIRECTIVE
:
2668 p
= "!$OMP BEGIN METADIRECTIVE";
2673 case ST_OMP_CANCELLATION_POINT
:
2674 p
= "!$OMP CANCELLATION POINT";
2676 case ST_OMP_CRITICAL
:
2677 p
= "!$OMP CRITICAL";
2679 case ST_OMP_DECLARE_REDUCTION
:
2680 p
= "!$OMP DECLARE REDUCTION";
2682 case ST_OMP_DECLARE_SIMD
:
2683 p
= "!$OMP DECLARE SIMD";
2685 case ST_OMP_DECLARE_TARGET
:
2686 p
= "!$OMP DECLARE TARGET";
2688 case ST_OMP_DECLARE_VARIANT
:
2689 p
= "!$OMP DECLARE VARIANT";
2694 case ST_OMP_DISPATCH
:
2695 p
= "!$OMP DISPATCH";
2697 case ST_OMP_DISTRIBUTE
:
2698 p
= "!$OMP DISTRIBUTE";
2700 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
2701 p
= "!$OMP DISTRIBUTE PARALLEL DO";
2703 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
2704 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2706 case ST_OMP_DISTRIBUTE_SIMD
:
2707 p
= "!$OMP DISTRIBUTE SIMD";
2712 case ST_OMP_DO_SIMD
:
2713 p
= "!$OMP DO SIMD";
2715 case ST_OMP_END_ALLOCATORS
:
2716 p
= "!$OMP END ALLOCATORS";
2718 case ST_OMP_END_ASSUME
:
2719 p
= "!$OMP END ASSUME";
2721 case ST_OMP_END_ATOMIC
:
2722 p
= "!$OMP END ATOMIC";
2724 case ST_OMP_END_CRITICAL
:
2725 p
= "!$OMP END CRITICAL";
2727 case ST_OMP_END_DISPATCH
:
2728 p
= "!$OMP END DISPATCH";
2730 case ST_OMP_END_DISTRIBUTE
:
2731 p
= "!$OMP END DISTRIBUTE";
2733 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2734 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2736 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2737 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2739 case ST_OMP_END_DISTRIBUTE_SIMD
:
2740 p
= "!$OMP END DISTRIBUTE SIMD";
2745 case ST_OMP_END_DO_SIMD
:
2746 p
= "!$OMP END DO SIMD";
2748 case ST_OMP_END_SCOPE
:
2749 p
= "!$OMP END SCOPE";
2751 case ST_OMP_END_SIMD
:
2752 p
= "!$OMP END SIMD";
2754 case ST_OMP_END_LOOP
:
2755 p
= "!$OMP END LOOP";
2757 case ST_OMP_END_MASKED
:
2758 p
= "!$OMP END MASKED";
2760 case ST_OMP_END_MASKED_TASKLOOP
:
2761 p
= "!$OMP END MASKED TASKLOOP";
2763 case ST_OMP_END_MASKED_TASKLOOP_SIMD
:
2764 p
= "!$OMP END MASKED TASKLOOP SIMD";
2766 case ST_OMP_END_MASTER
:
2767 p
= "!$OMP END MASTER";
2769 case ST_OMP_END_MASTER_TASKLOOP
:
2770 p
= "!$OMP END MASTER TASKLOOP";
2772 case ST_OMP_END_MASTER_TASKLOOP_SIMD
:
2773 p
= "!$OMP END MASTER TASKLOOP SIMD";
2775 case ST_OMP_END_METADIRECTIVE
:
2776 p
= "!$OMP END METADIRECTIVE";
2778 case ST_OMP_END_ORDERED
:
2779 p
= "!$OMP END ORDERED";
2781 case ST_OMP_END_PARALLEL
:
2782 p
= "!$OMP END PARALLEL";
2784 case ST_OMP_END_PARALLEL_DO
:
2785 p
= "!$OMP END PARALLEL DO";
2787 case ST_OMP_END_PARALLEL_DO_SIMD
:
2788 p
= "!$OMP END PARALLEL DO SIMD";
2790 case ST_OMP_END_PARALLEL_LOOP
:
2791 p
= "!$OMP END PARALLEL LOOP";
2793 case ST_OMP_END_PARALLEL_MASKED
:
2794 p
= "!$OMP END PARALLEL MASKED";
2796 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP
:
2797 p
= "!$OMP END PARALLEL MASKED TASKLOOP";
2799 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
:
2800 p
= "!$OMP END PARALLEL MASKED TASKLOOP SIMD";
2802 case ST_OMP_END_PARALLEL_MASTER
:
2803 p
= "!$OMP END PARALLEL MASTER";
2805 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP
:
2806 p
= "!$OMP END PARALLEL MASTER TASKLOOP";
2808 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
:
2809 p
= "!$OMP END PARALLEL MASTER TASKLOOP SIMD";
2811 case ST_OMP_END_PARALLEL_SECTIONS
:
2812 p
= "!$OMP END PARALLEL SECTIONS";
2814 case ST_OMP_END_PARALLEL_WORKSHARE
:
2815 p
= "!$OMP END PARALLEL WORKSHARE";
2817 case ST_OMP_END_SECTIONS
:
2818 p
= "!$OMP END SECTIONS";
2820 case ST_OMP_END_SINGLE
:
2821 p
= "!$OMP END SINGLE";
2823 case ST_OMP_END_TASK
:
2824 p
= "!$OMP END TASK";
2826 case ST_OMP_END_TARGET
:
2827 p
= "!$OMP END TARGET";
2829 case ST_OMP_END_TARGET_DATA
:
2830 p
= "!$OMP END TARGET DATA";
2832 case ST_OMP_END_TARGET_PARALLEL
:
2833 p
= "!$OMP END TARGET PARALLEL";
2835 case ST_OMP_END_TARGET_PARALLEL_DO
:
2836 p
= "!$OMP END TARGET PARALLEL DO";
2838 case ST_OMP_END_TARGET_PARALLEL_DO_SIMD
:
2839 p
= "!$OMP END TARGET PARALLEL DO SIMD";
2841 case ST_OMP_END_TARGET_PARALLEL_LOOP
:
2842 p
= "!$OMP END TARGET PARALLEL LOOP";
2844 case ST_OMP_END_TARGET_SIMD
:
2845 p
= "!$OMP END TARGET SIMD";
2847 case ST_OMP_END_TARGET_TEAMS
:
2848 p
= "!$OMP END TARGET TEAMS";
2850 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2851 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2853 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2854 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2856 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2857 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2859 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2860 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2862 case ST_OMP_END_TARGET_TEAMS_LOOP
:
2863 p
= "!$OMP END TARGET TEAMS LOOP";
2865 case ST_OMP_END_TASKGROUP
:
2866 p
= "!$OMP END TASKGROUP";
2868 case ST_OMP_END_TASKLOOP
:
2869 p
= "!$OMP END TASKLOOP";
2871 case ST_OMP_END_TASKLOOP_SIMD
:
2872 p
= "!$OMP END TASKLOOP SIMD";
2874 case ST_OMP_END_TEAMS
:
2875 p
= "!$OMP END TEAMS";
2877 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2878 p
= "!$OMP END TEAMS DISTRIBUTE";
2880 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2881 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2883 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2884 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2886 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2887 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2889 case ST_OMP_END_TEAMS_LOOP
:
2890 p
= "!$OMP END TEAMS LOOP";
2892 case ST_OMP_END_TILE
:
2893 p
= "!$OMP END TILE";
2895 case ST_OMP_END_UNROLL
:
2896 p
= "!$OMP END UNROLL";
2898 case ST_OMP_END_WORKSHARE
:
2899 p
= "!$OMP END WORKSHARE";
2907 case ST_OMP_INTEROP
:
2908 p
= "!$OMP INTEROP";
2916 case ST_OMP_MASKED_TASKLOOP
:
2917 p
= "!$OMP MASKED TASKLOOP";
2919 case ST_OMP_MASKED_TASKLOOP_SIMD
:
2920 p
= "!$OMP MASKED TASKLOOP SIMD";
2925 case ST_OMP_MASTER_TASKLOOP
:
2926 p
= "!$OMP MASTER TASKLOOP";
2928 case ST_OMP_MASTER_TASKLOOP_SIMD
:
2929 p
= "!$OMP MASTER TASKLOOP SIMD";
2931 case ST_OMP_METADIRECTIVE
:
2932 p
= "!$OMP METADIRECTIVE";
2934 case ST_OMP_ORDERED
:
2935 case ST_OMP_ORDERED_DEPEND
:
2936 p
= "!$OMP ORDERED";
2938 case ST_OMP_NOTHING
:
2939 /* Note: gfc_match_omp_nothing returns ST_NONE. */
2940 p
= "!$OMP NOTHING";
2942 case ST_OMP_PARALLEL
:
2943 p
= "!$OMP PARALLEL";
2945 case ST_OMP_PARALLEL_DO
:
2946 p
= "!$OMP PARALLEL DO";
2948 case ST_OMP_PARALLEL_LOOP
:
2949 p
= "!$OMP PARALLEL LOOP";
2951 case ST_OMP_PARALLEL_DO_SIMD
:
2952 p
= "!$OMP PARALLEL DO SIMD";
2954 case ST_OMP_PARALLEL_MASKED
:
2955 p
= "!$OMP PARALLEL MASKED";
2957 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
2958 p
= "!$OMP PARALLEL MASKED TASKLOOP";
2960 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
2961 p
= "!$OMP PARALLEL MASKED TASKLOOP SIMD";
2963 case ST_OMP_PARALLEL_MASTER
:
2964 p
= "!$OMP PARALLEL MASTER";
2966 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
2967 p
= "!$OMP PARALLEL MASTER TASKLOOP";
2969 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
2970 p
= "!$OMP PARALLEL MASTER TASKLOOP SIMD";
2972 case ST_OMP_PARALLEL_SECTIONS
:
2973 p
= "!$OMP PARALLEL SECTIONS";
2975 case ST_OMP_PARALLEL_WORKSHARE
:
2976 p
= "!$OMP PARALLEL WORKSHARE";
2978 case ST_OMP_REQUIRES
:
2979 p
= "!$OMP REQUIRES";
2987 case ST_OMP_SECTIONS
:
2988 p
= "!$OMP SECTIONS";
2990 case ST_OMP_SECTION
:
2991 p
= "!$OMP SECTION";
3002 case ST_OMP_TARGET_DATA
:
3003 p
= "!$OMP TARGET DATA";
3005 case ST_OMP_TARGET_ENTER_DATA
:
3006 p
= "!$OMP TARGET ENTER DATA";
3008 case ST_OMP_TARGET_EXIT_DATA
:
3009 p
= "!$OMP TARGET EXIT DATA";
3011 case ST_OMP_TARGET_PARALLEL
:
3012 p
= "!$OMP TARGET PARALLEL";
3014 case ST_OMP_TARGET_PARALLEL_DO
:
3015 p
= "!$OMP TARGET PARALLEL DO";
3017 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
3018 p
= "!$OMP TARGET PARALLEL DO SIMD";
3020 case ST_OMP_TARGET_PARALLEL_LOOP
:
3021 p
= "!$OMP TARGET PARALLEL LOOP";
3023 case ST_OMP_TARGET_SIMD
:
3024 p
= "!$OMP TARGET SIMD";
3026 case ST_OMP_TARGET_TEAMS
:
3027 p
= "!$OMP TARGET TEAMS";
3029 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
3030 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
3032 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
3033 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
3035 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
3036 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
3038 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
3039 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
3041 case ST_OMP_TARGET_TEAMS_LOOP
:
3042 p
= "!$OMP TARGET TEAMS LOOP";
3044 case ST_OMP_TARGET_UPDATE
:
3045 p
= "!$OMP TARGET UPDATE";
3050 case ST_OMP_TASKGROUP
:
3051 p
= "!$OMP TASKGROUP";
3053 case ST_OMP_TASKLOOP
:
3054 p
= "!$OMP TASKLOOP";
3056 case ST_OMP_TASKLOOP_SIMD
:
3057 p
= "!$OMP TASKLOOP SIMD";
3059 case ST_OMP_TASKWAIT
:
3060 p
= "!$OMP TASKWAIT";
3062 case ST_OMP_TASKYIELD
:
3063 p
= "!$OMP TASKYIELD";
3068 case ST_OMP_TEAMS_DISTRIBUTE
:
3069 p
= "!$OMP TEAMS DISTRIBUTE";
3071 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
3072 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
3074 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
3075 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
3077 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
3078 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
3080 case ST_OMP_TEAMS_LOOP
:
3081 p
= "!$OMP TEAMS LOOP";
3083 case ST_OMP_THREADPRIVATE
:
3084 p
= "!$OMP THREADPRIVATE";
3092 case ST_OMP_WORKSHARE
:
3093 p
= "!$OMP WORKSHARE";
3096 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
3099 if (strip_sentinel
&& p
[0] == '!')
3100 return p
+ strlen ("!$OMP ");
3105 /* Create a symbol for the main program and assign it to ns->proc_name. */
3108 main_program_symbol (gfc_namespace
*ns
, const char *name
)
3110 gfc_symbol
*main_program
;
3111 symbol_attribute attr
;
3113 gfc_get_symbol (name
, ns
, &main_program
);
3114 gfc_clear_attr (&attr
);
3115 attr
.flavor
= FL_PROGRAM
;
3116 attr
.proc
= PROC_UNKNOWN
;
3117 attr
.subroutine
= 1;
3118 attr
.access
= ACCESS_PUBLIC
;
3119 attr
.is_main_program
= 1;
3120 main_program
->attr
= attr
;
3121 main_program
->declared_at
= gfc_current_locus
;
3122 ns
->proc_name
= main_program
;
3123 gfc_commit_symbols ();
3127 /* Do whatever is necessary to accept the last statement. */
3130 accept_statement (gfc_statement st
)
3134 case ST_IMPLICIT_NONE
:
3142 gfc_current_ns
->proc_name
= gfc_new_block
;
3145 /* If the statement is the end of a block, lay down a special code
3146 that allows a branch to the end of the block from within the
3147 construct. IF and SELECT are treated differently from DO
3148 (where EXEC_NOP is added inside the loop) for two
3150 1. END DO has a meaning in the sense that after a GOTO to
3151 it, the loop counter must be increased.
3152 2. IF blocks and SELECT blocks can consist of multiple
3153 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
3154 Putting the label before the END IF would make the jump
3155 from, say, the ELSE IF block to the END IF illegal. */
3159 case ST_END_CRITICAL
:
3160 if (gfc_statement_label
!= NULL
)
3162 new_st
.op
= EXEC_END_NESTED_BLOCK
;
3167 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
3168 one parallel block. Thus, we add the special code to the nested block
3169 itself, instead of the parent one. */
3171 case ST_END_ASSOCIATE
:
3172 if (gfc_statement_label
!= NULL
)
3174 new_st
.op
= EXEC_END_BLOCK
;
3179 /* The end-of-program unit statements do not get the special
3180 marker and require a statement of some sort if they are a
3183 case ST_END_PROGRAM
:
3184 case ST_END_FUNCTION
:
3185 case ST_END_SUBROUTINE
:
3186 if (gfc_statement_label
!= NULL
)
3188 new_st
.op
= EXEC_RETURN
;
3193 new_st
.op
= EXEC_END_PROCEDURE
;
3200 case ST_OMP_METADIRECTIVE
:
3201 case ST_OMP_BEGIN_METADIRECTIVE
:
3211 gfc_commit_symbols ();
3212 gfc_warning_check ();
3213 gfc_clear_new_st ();
3217 /* Undo anything tentative that has been built for the current statement,
3218 except if a gfc_charlen structure has been added to current namespace's
3219 list of gfc_charlen structure. */
3222 reject_statement (void)
3224 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
3225 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
3226 gfc_drop_interface_elements_before (current_interface_ptr
,
3227 previous_interface_head
);
3229 gfc_reject_data (gfc_current_ns
);
3231 /* Don't queue use-association of a module if we reject the use statement. */
3232 gfc_restore_old_module_list ();
3234 gfc_new_block
= NULL
;
3235 gfc_undo_symbols ();
3236 gfc_clear_warning ();
3237 undo_new_statement ();
3241 /* Generic complaint about an out of order statement. We also do
3242 whatever is necessary to clean up. */
3245 unexpected_statement (gfc_statement st
)
3247 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
3249 reject_statement ();
3253 /* Given the next statement seen by the matcher, make sure that it is
3254 in proper order with the last. This subroutine is initialized by
3255 calling it with an argument of ST_NONE. If there is a problem, we
3256 issue an error and return false. Otherwise we return true.
3258 Individual parsers need to verify that the statements seen are
3259 valid before calling here, i.e., ENTRY statements are not allowed in
3260 INTERFACE blocks. The following diagram is taken from the standard:
3262 +---------------------------------------+
3263 | program subroutine function module |
3264 +---------------------------------------+
3266 +---------------------------------------+
3268 +---------------------------------------+
3270 | +-----------+------------------+
3271 | | parameter | implicit |
3272 | +-----------+------------------+
3273 | format | | derived type |
3274 | entry | parameter | interface |
3275 | | data | specification |
3276 | | | statement func |
3277 | +-----------+------------------+
3278 | | data | executable |
3279 +--------+-----------+------------------+
3281 +---------------------------------------+
3282 | internal module/subprogram |
3283 +---------------------------------------+
3285 +---------------------------------------+
3294 ORDER_IMPLICIT_NONE
,
3302 enum state_order state
;
3303 gfc_statement last_statement
;
3309 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
3315 p
->state
= ORDER_START
;
3316 in_exec_part
= false;
3320 if (p
->state
> ORDER_USE
)
3322 p
->state
= ORDER_USE
;
3326 if (p
->state
> ORDER_IMPORT
)
3328 p
->state
= ORDER_IMPORT
;
3331 case ST_IMPLICIT_NONE
:
3332 if (p
->state
> ORDER_IMPLICIT
)
3335 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
3336 statement disqualifies a USE but not an IMPLICIT NONE.
3337 Duplicate IMPLICIT NONEs are caught when the implicit types
3340 p
->state
= ORDER_IMPLICIT_NONE
;
3344 if (p
->state
> ORDER_IMPLICIT
)
3346 p
->state
= ORDER_IMPLICIT
;
3351 if (p
->state
< ORDER_IMPLICIT_NONE
)
3352 p
->state
= ORDER_IMPLICIT_NONE
;
3356 if (p
->state
>= ORDER_EXEC
)
3358 if (p
->state
< ORDER_IMPLICIT
)
3359 p
->state
= ORDER_IMPLICIT
;
3363 if (p
->state
< ORDER_SPEC
)
3364 p
->state
= ORDER_SPEC
;
3369 case ST_STRUCTURE_DECL
:
3370 case ST_DERIVED_DECL
:
3372 if (p
->state
>= ORDER_EXEC
)
3374 if (p
->state
< ORDER_SPEC
)
3375 p
->state
= ORDER_SPEC
;
3379 /* The OpenMP/OpenACC directives have to be somewhere in the specification
3380 part, but there are no further requirements on their ordering.
3381 Thus don't adjust p->state, just ignore them. */
3382 if (p
->state
>= ORDER_EXEC
)
3388 if (p
->state
< ORDER_EXEC
)
3389 p
->state
= ORDER_EXEC
;
3390 in_exec_part
= true;
3397 /* All is well, record the statement in case we need it next time. */
3398 p
->where
= gfc_current_locus
;
3399 p
->last_statement
= st
;
3404 gfc_error ("%s statement at %C cannot follow %s statement at %L",
3405 gfc_ascii_statement (st
),
3406 gfc_ascii_statement (p
->last_statement
), &p
->where
);
3412 /* Handle an unexpected end of file. This is a show-stopper... */
3414 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
3417 unexpected_eof (void)
3421 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
3423 /* Memory cleanup. Move to "second to last". */
3424 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
3427 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
3430 longjmp (eof_buf
, 1);
3432 /* Avoids build error on systems where longjmp is not declared noreturn. */
3437 /* Parse the CONTAINS section of a derived type definition. */
3439 gfc_access gfc_typebound_default_access
;
3442 parse_derived_contains (void)
3445 bool seen_private
= false;
3446 bool seen_comps
= false;
3447 bool error_flag
= false;
3450 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3451 gcc_assert (gfc_current_block ());
3453 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
3455 if (gfc_current_block ()->attr
.sequence
)
3456 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
3457 " section at %C", gfc_current_block ()->name
);
3458 if (gfc_current_block ()->attr
.is_bind_c
)
3459 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
3460 " section at %C", gfc_current_block ()->name
);
3462 accept_statement (ST_CONTAINS
);
3463 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
3465 gfc_typebound_default_access
= ACCESS_PUBLIC
;
3471 st
= next_statement ();
3479 gfc_error ("Components in TYPE at %C must precede CONTAINS");
3483 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
3486 accept_statement (ST_PROCEDURE
);
3491 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
3494 accept_statement (ST_GENERIC
);
3499 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
3503 accept_statement (ST_FINAL
);
3511 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
3512 "at %C with empty CONTAINS section")))
3515 /* ST_END_TYPE is accepted by parse_derived after return. */
3519 if (!gfc_find_state (COMP_MODULE
))
3521 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3528 gfc_error ("PRIVATE statement at %C must precede procedure"
3535 gfc_error ("Duplicate PRIVATE statement at %C");
3539 accept_statement (ST_PRIVATE
);
3540 gfc_typebound_default_access
= ACCESS_PRIVATE
;
3541 seen_private
= true;
3545 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
3549 gfc_error ("Already inside a CONTAINS block at %C");
3553 unexpected_statement (st
);
3561 reject_statement ();
3565 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3571 /* Set attributes for the parent symbol based on the attributes of a component
3572 and raise errors if conflicting attributes are found for the component. */
3575 check_component (gfc_symbol
*sym
, gfc_component
*c
, gfc_component
**lockp
,
3576 gfc_component
**eventp
)
3578 bool coarray
, lock_type
, event_type
, allocatable
, pointer
;
3579 coarray
= lock_type
= event_type
= allocatable
= pointer
= false;
3580 gfc_component
*lock_comp
= NULL
, *event_comp
= NULL
;
3582 if (lockp
) lock_comp
= *lockp
;
3583 if (eventp
) event_comp
= *eventp
;
3585 /* Look for allocatable components. */
3586 if (c
->attr
.allocatable
3587 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3588 && CLASS_DATA (c
)->attr
.allocatable
)
3589 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
3590 && c
->ts
.u
.derived
->attr
.alloc_comp
))
3593 sym
->attr
.alloc_comp
= 1;
3596 /* Look for pointer components. */
3598 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3599 && CLASS_DATA (c
)->attr
.class_pointer
)
3600 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
3603 sym
->attr
.pointer_comp
= 1;
3606 /* Look for procedure pointer components. */
3607 if (c
->attr
.proc_pointer
3608 || (c
->ts
.type
== BT_DERIVED
3609 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
3610 sym
->attr
.proc_pointer_comp
= 1;
3612 /* Looking for coarray components. */
3613 if (c
->attr
.codimension
3614 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3615 && CLASS_DATA (c
)->attr
.codimension
))
3618 sym
->attr
.coarray_comp
= 1;
3621 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
3622 && !c
->attr
.pointer
)
3625 sym
->attr
.coarray_comp
= 1;
3628 /* Looking for lock_type components. */
3629 if ((c
->ts
.type
== BT_DERIVED
3630 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3631 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
3632 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3633 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3634 == INTMOD_ISO_FORTRAN_ENV
3635 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3636 == ISOFORTRAN_LOCK_TYPE
)
3637 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
3638 && !allocatable
&& !pointer
))
3642 sym
->attr
.lock_comp
= 1;
3645 /* Looking for event_type components. */
3646 if ((c
->ts
.type
== BT_DERIVED
3647 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3648 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
3649 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3650 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3651 == INTMOD_ISO_FORTRAN_ENV
3652 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3653 == ISOFORTRAN_EVENT_TYPE
)
3654 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.event_comp
3655 && !allocatable
&& !pointer
))
3659 sym
->attr
.event_comp
= 1;
3662 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
3663 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
3664 unless there are nondirect [allocatable or pointer] components
3665 involved (cf. 1.3.33.1 and 1.3.33.3). */
3667 if (pointer
&& !coarray
&& lock_type
)
3668 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
3669 "codimension or be a subcomponent of a coarray, "
3670 "which is not possible as the component has the "
3671 "pointer attribute", c
->name
, &c
->loc
);
3672 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3673 && c
->ts
.u
.derived
->attr
.lock_comp
)
3674 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3675 "of type LOCK_TYPE, which must have a codimension or be a "
3676 "subcomponent of a coarray", c
->name
, &c
->loc
);
3678 if (lock_type
&& allocatable
&& !coarray
)
3679 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
3680 "a codimension", c
->name
, &c
->loc
);
3681 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3682 && c
->ts
.u
.derived
->attr
.lock_comp
)
3683 gfc_error ("Allocatable component %s at %L must have a codimension as "
3684 "it has a noncoarray subcomponent of type LOCK_TYPE",
3687 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
3688 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3689 "subcomponent of type LOCK_TYPE must have a codimension or "
3690 "be a subcomponent of a coarray. (Variables of type %s may "
3691 "not have a codimension as already a coarray "
3692 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3694 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
3695 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3696 "subcomponent of type LOCK_TYPE must have a codimension or "
3697 "be a subcomponent of a coarray. (Variables of type %s may "
3698 "not have a codimension as %s at %L has a codimension or a "
3699 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
3700 sym
->name
, c
->name
, &c
->loc
);
3702 /* Similarly for EVENT TYPE. */
3704 if (pointer
&& !coarray
&& event_type
)
3705 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
3706 "codimension or be a subcomponent of a coarray, "
3707 "which is not possible as the component has the "
3708 "pointer attribute", c
->name
, &c
->loc
);
3709 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3710 && c
->ts
.u
.derived
->attr
.event_comp
)
3711 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3712 "of type EVENT_TYPE, which must have a codimension or be a "
3713 "subcomponent of a coarray", c
->name
, &c
->loc
);
3715 if (event_type
&& allocatable
&& !coarray
)
3716 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
3717 "a codimension", c
->name
, &c
->loc
);
3718 else if (event_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3719 && c
->ts
.u
.derived
->attr
.event_comp
)
3720 gfc_error ("Allocatable component %s at %L must have a codimension as "
3721 "it has a noncoarray subcomponent of type EVENT_TYPE",
3724 if (sym
->attr
.coarray_comp
&& !coarray
&& event_type
)
3725 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3726 "subcomponent of type EVENT_TYPE must have a codimension or "
3727 "be a subcomponent of a coarray. (Variables of type %s may "
3728 "not have a codimension as already a coarray "
3729 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3731 if (sym
->attr
.event_comp
&& coarray
&& !event_type
)
3732 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3733 "subcomponent of type EVENT_TYPE must have a codimension or "
3734 "be a subcomponent of a coarray. (Variables of type %s may "
3735 "not have a codimension as %s at %L has a codimension or a "
3736 "coarray subcomponent)", event_comp
->name
, &event_comp
->loc
,
3737 sym
->name
, c
->name
, &c
->loc
);
3739 /* Look for private components. */
3740 if (sym
->component_access
== ACCESS_PRIVATE
3741 || c
->attr
.access
== ACCESS_PRIVATE
3742 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
3743 sym
->attr
.private_comp
= 1;
3745 if (lockp
) *lockp
= lock_comp
;
3746 if (eventp
) *eventp
= event_comp
;
3750 static void parse_struct_map (gfc_statement
);
3752 /* Parse a union component definition within a structure definition. */
3760 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3763 accept_statement(ST_UNION
);
3764 push_state (&s
, COMP_UNION
, gfc_new_block
);
3771 st
= next_statement ();
3772 /* Only MAP declarations valid within a union. */
3779 accept_statement (ST_MAP
);
3780 parse_struct_map (ST_MAP
);
3781 /* Add a component to the union for each map. */
3782 if (!gfc_add_component (un
, gfc_new_block
->name
, &c
))
3784 gfc_internal_error ("failed to create map component '%s'",
3785 gfc_new_block
->name
);
3786 reject_statement ();
3789 c
->ts
.type
= BT_DERIVED
;
3790 c
->ts
.u
.derived
= gfc_new_block
;
3791 /* Normally components get their initialization expressions when they
3792 are created in decl.cc (build_struct) so we can look through the
3793 flat component list for initializers during resolution. Unions and
3794 maps create components along with their type definitions so we
3795 have to generate initializers here. */
3796 c
->initializer
= gfc_default_initializer (&c
->ts
);
3801 accept_statement (ST_END_UNION
);
3805 unexpected_statement (st
);
3810 for (c
= un
->components
; c
; c
= c
->next
)
3811 check_component (un
, c
, &lock_comp
, &event_comp
);
3813 /* Add the union as a component in its parent structure. */
3815 if (!gfc_add_component (gfc_current_block (), un
->name
, &c
))
3817 gfc_internal_error ("failed to create union component '%s'", un
->name
);
3818 reject_statement ();
3821 c
->ts
.type
= BT_UNION
;
3822 c
->ts
.u
.derived
= un
;
3823 c
->initializer
= gfc_default_initializer (&c
->ts
);
3825 un
->attr
.zero_comp
= un
->components
== NULL
;
3829 /* Parse a STRUCTURE or MAP. */
3832 parse_struct_map (gfc_statement block
)
3838 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3839 gfc_compile_state comp
;
3842 if (block
== ST_STRUCTURE_DECL
)
3844 comp
= COMP_STRUCTURE
;
3845 ends
= ST_END_STRUCTURE
;
3849 gcc_assert (block
== ST_MAP
);
3854 accept_statement(block
);
3855 push_state (&s
, comp
, gfc_new_block
);
3857 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3860 while (compiling_type
)
3862 st
= next_statement ();
3868 /* Nested structure declarations will be captured as ST_DATA_DECL. */
3869 case ST_STRUCTURE_DECL
:
3870 /* Let a more specific error make it to decode_statement(). */
3871 if (gfc_error_check () == 0)
3872 gfc_error ("Syntax error in nested structure declaration at %C");
3873 reject_statement ();
3874 /* Skip the rest of this statement. */
3875 gfc_error_recovery ();
3879 accept_statement (ST_UNION
);
3884 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
3885 accept_statement (ST_DATA_DECL
);
3886 if (gfc_new_block
&& gfc_new_block
!= gfc_current_block ()
3887 && gfc_new_block
->attr
.flavor
== FL_STRUCT
)
3888 parse_struct_map (ST_STRUCTURE_DECL
);
3891 case ST_END_STRUCTURE
:
3895 accept_statement (st
);
3899 unexpected_statement (st
);
3903 unexpected_statement (st
);
3908 /* Validate each component. */
3909 sym
= gfc_current_block ();
3910 for (c
= sym
->components
; c
; c
= c
->next
)
3911 check_component (sym
, c
, &lock_comp
, &event_comp
);
3913 sym
->attr
.zero_comp
= (sym
->components
== NULL
);
3915 /* Allow parse_union to find this structure to add to its list of maps. */
3916 if (block
== ST_MAP
)
3917 gfc_new_block
= gfc_current_block ();
3923 /* Parse a derived type. */
3926 parse_derived (void)
3928 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
3932 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3934 accept_statement (ST_DERIVED_DECL
);
3935 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
3937 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3944 while (compiling_type
)
3946 st
= next_statement ();
3954 accept_statement (st
);
3959 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3966 if (!seen_component
)
3967 gfc_notify_std (GFC_STD_F2003
, "Derived type "
3968 "definition at %C without components");
3970 accept_statement (ST_END_TYPE
);
3974 if (!gfc_find_state (COMP_MODULE
))
3976 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3983 gfc_error ("PRIVATE statement at %C must precede "
3984 "structure components");
3989 gfc_error ("Duplicate PRIVATE statement at %C");
3991 s
.sym
->component_access
= ACCESS_PRIVATE
;
3993 accept_statement (ST_PRIVATE
);
4000 gfc_error ("SEQUENCE statement at %C must precede "
4001 "structure components");
4005 if (gfc_current_block ()->attr
.sequence
)
4006 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
4011 gfc_error ("Duplicate SEQUENCE statement at %C");
4015 gfc_add_sequence (&gfc_current_block ()->attr
,
4016 gfc_current_block ()->name
, NULL
);
4020 gfc_notify_std (GFC_STD_F2003
,
4021 "CONTAINS block in derived type"
4022 " definition at %C");
4024 accept_statement (ST_CONTAINS
);
4025 parse_derived_contains ();
4029 unexpected_statement (st
);
4034 /* need to verify that all fields of the derived type are
4035 * interoperable with C if the type is declared to be bind(c)
4037 sym
= gfc_current_block ();
4038 for (c
= sym
->components
; c
; c
= c
->next
)
4039 check_component (sym
, c
, &lock_comp
, &event_comp
);
4041 if (!seen_component
)
4042 sym
->attr
.zero_comp
= 1;
4048 /* Parse an ENUM. */
4056 int seen_enumerator
= 0;
4058 push_state (&s
, COMP_ENUM
, gfc_new_block
);
4062 while (compiling_enum
)
4064 st
= next_statement ();
4072 seen_enumerator
= 1;
4073 accept_statement (st
);
4078 if (!seen_enumerator
)
4079 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
4080 accept_statement (st
);
4084 gfc_free_enum_history ();
4085 unexpected_statement (st
);
4093 /* Parse an interface. We must be able to deal with the possibility
4094 of recursive interfaces. The parse_spec() subroutine is mutually
4095 recursive with parse_interface(). */
4097 static gfc_statement
parse_spec (gfc_statement
);
4100 parse_interface (void)
4102 gfc_compile_state new_state
= COMP_NONE
, current_state
;
4103 gfc_symbol
*prog_unit
, *sym
;
4104 gfc_interface_info save
;
4105 gfc_state_data s1
, s2
;
4108 accept_statement (ST_INTERFACE
);
4110 current_interface
.ns
= gfc_current_ns
;
4111 save
= current_interface
;
4113 sym
= (current_interface
.type
== INTERFACE_GENERIC
4114 || current_interface
.type
== INTERFACE_USER_OP
)
4115 ? gfc_new_block
: NULL
;
4117 push_state (&s1
, COMP_INTERFACE
, sym
);
4118 current_state
= COMP_NONE
;
4121 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
4123 st
= next_statement ();
4131 if (st
== ST_SUBROUTINE
)
4132 new_state
= COMP_SUBROUTINE
;
4133 else if (st
== ST_FUNCTION
)
4134 new_state
= COMP_FUNCTION
;
4135 if (gfc_new_block
->attr
.pointer
)
4137 gfc_new_block
->attr
.pointer
= 0;
4138 gfc_new_block
->attr
.proc_pointer
= 1;
4140 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
4141 gfc_new_block
->formal
, NULL
))
4143 reject_statement ();
4144 gfc_free_namespace (gfc_current_ns
);
4147 /* F2008 C1210 forbids the IMPORT statement in module procedure
4148 interface bodies and the flag is set to import symbols. */
4149 if (gfc_new_block
->attr
.module_procedure
)
4150 gfc_current_ns
->has_import_set
= 1;
4154 case ST_MODULE_PROC
: /* The module procedure matcher makes
4155 sure the context is correct. */
4156 accept_statement (st
);
4157 gfc_free_namespace (gfc_current_ns
);
4160 case ST_END_INTERFACE
:
4161 gfc_free_namespace (gfc_current_ns
);
4162 gfc_current_ns
= current_interface
.ns
;
4166 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
4167 gfc_ascii_statement (st
));
4168 current_interface
= save
;
4169 reject_statement ();
4170 gfc_free_namespace (gfc_current_ns
);
4175 /* Make sure that the generic name has the right attribute. */
4176 if (current_interface
.type
== INTERFACE_GENERIC
4177 && current_state
== COMP_NONE
)
4179 if (new_state
== COMP_FUNCTION
&& sym
)
4180 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
4181 else if (new_state
== COMP_SUBROUTINE
&& sym
)
4182 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
4184 current_state
= new_state
;
4187 if (current_interface
.type
== INTERFACE_ABSTRACT
)
4189 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
4190 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
4191 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
4192 "cannot be the same as an intrinsic type",
4193 gfc_new_block
->name
);
4196 push_state (&s2
, new_state
, gfc_new_block
);
4197 accept_statement (st
);
4198 prog_unit
= gfc_new_block
;
4199 prog_unit
->formal_ns
= gfc_current_ns
;
4202 /* Read data declaration statements. */
4203 st
= parse_spec (ST_NONE
);
4204 in_specification_block
= true;
4206 /* Since the interface block does not permit an IMPLICIT statement,
4207 the default type for the function or the result must be taken
4208 from the formal namespace. */
4209 if (new_state
== COMP_FUNCTION
)
4211 if (prog_unit
->result
== prog_unit
4212 && prog_unit
->ts
.type
== BT_UNKNOWN
)
4213 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
4214 else if (prog_unit
->result
!= prog_unit
4215 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
4216 gfc_set_default_type (prog_unit
->result
, 1,
4217 prog_unit
->formal_ns
);
4220 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
4222 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
4223 gfc_ascii_statement (st
));
4224 reject_statement ();
4228 /* Add EXTERNAL attribute to function or subroutine. */
4229 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
4230 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
4232 current_interface
= save
;
4233 gfc_add_interface (prog_unit
);
4236 if (current_interface
.ns
4237 && current_interface
.ns
->proc_name
4238 && strcmp (current_interface
.ns
->proc_name
->name
,
4239 prog_unit
->name
) == 0)
4240 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
4241 "enclosing procedure", prog_unit
->name
,
4242 ¤t_interface
.ns
->proc_name
->declared_at
);
4251 /* Associate function characteristics by going back to the function
4252 declaration and rematching the prefix. */
4255 match_deferred_characteristics (gfc_typespec
* ts
)
4258 match m
= MATCH_ERROR
;
4259 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4261 loc
= gfc_current_locus
;
4263 gfc_current_locus
= gfc_current_block ()->declared_at
;
4266 gfc_buffer_error (true);
4267 m
= gfc_match_prefix (ts
);
4268 gfc_buffer_error (false);
4270 if (ts
->type
== BT_DERIVED
|| ts
->type
== BT_CLASS
)
4278 /* Only permit one go at the characteristic association. */
4282 /* Set the function locus correctly. If we have not found the
4283 function name, there is an error. */
4285 && gfc_match ("function% %n", name
) == MATCH_YES
4286 && strcmp (name
, gfc_current_block ()->name
) == 0)
4288 gfc_current_block ()->declared_at
= gfc_current_locus
;
4289 gfc_commit_symbols ();
4294 gfc_undo_symbols ();
4297 gfc_current_locus
=loc
;
4302 /* Check specification-expressions in the function result of the currently
4303 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
4304 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
4305 scope are not yet parsed so this has to be delayed up to parse_spec. */
4308 check_function_result_typed (void)
4312 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
4314 if (!gfc_current_ns
->proc_name
->result
)
4317 ts
= gfc_current_ns
->proc_name
->result
->ts
;
4319 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
4320 /* TODO: Extend when KIND type parameters are implemented. */
4321 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
4323 /* Reject invalid type of specification expression for length. */
4324 if (ts
.u
.cl
->length
->ts
.type
!= BT_INTEGER
)
4327 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
4334 /* Parse a set of specification statements. Returns the statement
4335 that doesn't fit. */
4337 static gfc_statement
4338 parse_spec (gfc_statement st
)
4341 bool function_result_typed
= false;
4342 bool bad_characteristic
= false;
4345 in_specification_block
= true;
4347 verify_st_order (&ss
, ST_NONE
, false);
4349 st
= next_statement ();
4351 /* If we are not inside a function or don't have a result specified so far,
4352 do nothing special about it. */
4353 if (gfc_current_state () != COMP_FUNCTION
)
4354 function_result_typed
= true;
4357 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
4360 if (proc
->result
&& proc
->result
->ts
.type
== BT_UNKNOWN
)
4361 function_result_typed
= true;
4366 /* If we're inside a BLOCK construct, some statements are disallowed.
4367 Check this here. Attribute declaration statements like INTENT, OPTIONAL
4368 or VALUE are also disallowed, but they don't have a particular ST_*
4369 key so we have to check for them individually in their matcher routine. */
4370 if (gfc_current_state () == COMP_BLOCK
)
4374 case ST_IMPLICIT_NONE
:
4377 case ST_EQUIVALENCE
:
4378 case ST_STATEMENT_FUNCTION
:
4379 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
4380 gfc_ascii_statement (st
));
4381 reject_statement ();
4387 else if (gfc_current_state () == COMP_BLOCK_DATA
)
4388 /* Fortran 2008, C1116. */
4395 case ST_DERIVED_DECL
:
4396 case ST_END_BLOCK_DATA
:
4397 case ST_EQUIVALENCE
:
4399 case ST_IMPLICIT_NONE
:
4400 case ST_OMP_THREADPRIVATE
:
4402 case ST_STRUCTURE_DECL
:
4411 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
4412 gfc_ascii_statement (st
));
4413 reject_statement ();
4417 /* If we find a statement that cannot be followed by an IMPLICIT statement
4418 (and thus we can expect to see none any further), type the function result
4419 if it has not yet been typed. Be careful not to give the END statement
4420 to verify_st_order! */
4421 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
4423 bool verify_now
= false;
4425 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
4430 verify_st_order (&dummyss
, ST_NONE
, false);
4431 verify_st_order (&dummyss
, st
, false);
4433 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
4438 function_result_typed
= check_function_result_typed ();
4446 case ST_IMPLICIT_NONE
:
4448 if (!function_result_typed
)
4449 function_result_typed
= check_function_result_typed ();
4454 case ST_DATA
: /* Not allowed in interfaces */
4455 if (gfc_current_state () == COMP_INTERFACE
)
4465 case ST_STRUCTURE_DECL
:
4466 case ST_DERIVED_DECL
:
4470 if (!verify_st_order (&ss
, st
, false))
4472 reject_statement ();
4473 st
= next_statement ();
4483 case ST_STRUCTURE_DECL
:
4484 parse_struct_map (ST_STRUCTURE_DECL
);
4487 case ST_DERIVED_DECL
:
4493 if (gfc_current_state () != COMP_MODULE
)
4495 gfc_error ("%s statement must appear in a MODULE",
4496 gfc_ascii_statement (st
));
4497 reject_statement ();
4501 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
4503 gfc_error ("%s statement at %C follows another accessibility "
4504 "specification", gfc_ascii_statement (st
));
4505 reject_statement ();
4509 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
4510 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
4514 case ST_STATEMENT_FUNCTION
:
4515 if (gfc_current_state () == COMP_MODULE
4516 || gfc_current_state () == COMP_SUBMODULE
)
4518 unexpected_statement (st
);
4526 accept_statement (st
);
4527 st
= next_statement ();
4531 accept_statement (st
);
4533 st
= next_statement ();
4536 case ST_GET_FCN_CHARACTERISTICS
:
4537 /* This statement triggers the association of a function's result
4539 ts
= &gfc_current_block ()->result
->ts
;
4540 if (match_deferred_characteristics (ts
) != MATCH_YES
)
4541 bad_characteristic
= true;
4543 st
= next_statement ();
4550 /* If match_deferred_characteristics failed, then there is an error. */
4551 if (bad_characteristic
)
4553 ts
= &gfc_current_block ()->result
->ts
;
4554 if (ts
->type
!= BT_DERIVED
&& ts
->type
!= BT_CLASS
)
4555 gfc_error ("Bad kind expression for function %qs at %L",
4556 gfc_current_block ()->name
,
4557 &gfc_current_block ()->declared_at
);
4559 gfc_error ("The type for function %qs at %L is not accessible",
4560 gfc_current_block ()->name
,
4561 &gfc_current_block ()->declared_at
);
4563 gfc_current_block ()->ts
.kind
= 0;
4564 /* Keep the derived type; if it's bad, it will be discovered later. */
4565 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
4566 ts
->type
= BT_UNKNOWN
;
4569 in_specification_block
= false;
4575 /* Parse a WHERE block, (not a simple WHERE statement). */
4578 parse_where_block (void)
4580 int seen_empty_else
;
4585 accept_statement (ST_WHERE_BLOCK
);
4586 top
= gfc_state_stack
->tail
;
4588 push_state (&s
, COMP_WHERE
, gfc_new_block
);
4590 d
= add_statement ();
4591 d
->expr1
= top
->expr1
;
4597 seen_empty_else
= 0;
4601 st
= next_statement ();
4607 case ST_WHERE_BLOCK
:
4608 parse_where_block ();
4613 accept_statement (st
);
4617 if (seen_empty_else
)
4619 gfc_error ("ELSEWHERE statement at %C follows previous "
4620 "unmasked ELSEWHERE");
4621 reject_statement ();
4625 if (new_st
.expr1
== NULL
)
4626 seen_empty_else
= 1;
4628 d
= new_level (gfc_state_stack
->head
);
4630 d
->expr1
= new_st
.expr1
;
4632 accept_statement (st
);
4637 accept_statement (st
);
4641 gfc_error ("Unexpected %s statement in WHERE block at %C",
4642 gfc_ascii_statement (st
));
4643 reject_statement ();
4647 while (st
!= ST_END_WHERE
);
4653 /* Parse a FORALL block (not a simple FORALL statement). */
4656 parse_forall_block (void)
4662 accept_statement (ST_FORALL_BLOCK
);
4663 top
= gfc_state_stack
->tail
;
4665 push_state (&s
, COMP_FORALL
, gfc_new_block
);
4667 d
= add_statement ();
4668 d
->op
= EXEC_FORALL
;
4673 st
= next_statement ();
4678 case ST_POINTER_ASSIGNMENT
:
4681 accept_statement (st
);
4684 case ST_WHERE_BLOCK
:
4685 parse_where_block ();
4688 case ST_FORALL_BLOCK
:
4689 parse_forall_block ();
4693 accept_statement (st
);
4700 gfc_error ("Unexpected %s statement in FORALL block at %C",
4701 gfc_ascii_statement (st
));
4703 reject_statement ();
4707 while (st
!= ST_END_FORALL
);
4713 static gfc_statement
parse_executable (gfc_statement
);
4715 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
4718 parse_if_block (void)
4727 accept_statement (ST_IF_BLOCK
);
4729 top
= gfc_state_stack
->tail
;
4730 push_state (&s
, COMP_IF
, gfc_new_block
);
4732 new_st
.op
= EXEC_IF
;
4733 d
= add_statement ();
4735 d
->expr1
= top
->expr1
;
4741 st
= parse_executable (ST_NONE
);
4751 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
4752 "statement at %L", &else_locus
);
4754 reject_statement ();
4758 d
= new_level (gfc_state_stack
->head
);
4760 d
->expr1
= new_st
.expr1
;
4762 accept_statement (st
);
4769 gfc_error ("Duplicate ELSE statements at %L and %C",
4771 reject_statement ();
4776 else_locus
= gfc_current_locus
;
4778 d
= new_level (gfc_state_stack
->head
);
4781 accept_statement (st
);
4789 unexpected_statement (st
);
4793 while (st
!= ST_ENDIF
);
4796 accept_statement (st
);
4800 /* Parse a SELECT block. */
4803 parse_select_block (void)
4809 accept_statement (ST_SELECT_CASE
);
4811 cp
= gfc_state_stack
->tail
;
4812 push_state (&s
, COMP_SELECT
, gfc_new_block
);
4814 /* Make sure that the next statement is a CASE or END SELECT. */
4817 st
= next_statement ();
4820 if (st
== ST_END_SELECT
)
4822 /* Empty SELECT CASE is OK. */
4823 accept_statement (st
);
4830 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
4833 reject_statement ();
4836 /* At this point, we've got a nonempty select block. */
4837 cp
= new_level (cp
);
4840 accept_statement (st
);
4844 st
= parse_executable (ST_NONE
);
4851 cp
= new_level (gfc_state_stack
->head
);
4853 gfc_clear_new_st ();
4855 accept_statement (st
);
4861 /* Can't have an executable statement because of
4862 parse_executable(). */
4864 unexpected_statement (st
);
4868 while (st
!= ST_END_SELECT
);
4871 accept_statement (st
);
4875 /* Pop the current selector from the SELECT TYPE stack. */
4878 select_type_pop (void)
4880 gfc_select_type_stack
*old
= select_type_stack
;
4881 select_type_stack
= old
->prev
;
4886 /* Parse a SELECT TYPE construct (F03:R821). */
4889 parse_select_type_block (void)
4895 gfc_current_ns
= new_st
.ext
.block
.ns
;
4896 accept_statement (ST_SELECT_TYPE
);
4898 cp
= gfc_state_stack
->tail
;
4899 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
4901 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4905 st
= next_statement ();
4908 if (st
== ST_END_SELECT
)
4909 /* Empty SELECT CASE is OK. */
4911 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
4914 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4915 "following SELECT TYPE at %C");
4917 reject_statement ();
4920 /* At this point, we've got a nonempty select block. */
4921 cp
= new_level (cp
);
4924 accept_statement (st
);
4928 st
= parse_executable (ST_NONE
);
4936 cp
= new_level (gfc_state_stack
->head
);
4938 gfc_clear_new_st ();
4940 accept_statement (st
);
4946 /* Can't have an executable statement because of
4947 parse_executable(). */
4949 unexpected_statement (st
);
4953 while (st
!= ST_END_SELECT
);
4957 accept_statement (st
);
4958 gfc_current_ns
= gfc_current_ns
->parent
;
4963 /* Parse a SELECT RANK construct. */
4966 parse_select_rank_block (void)
4972 gfc_current_ns
= new_st
.ext
.block
.ns
;
4973 accept_statement (ST_SELECT_RANK
);
4975 cp
= gfc_state_stack
->tail
;
4976 push_state (&s
, COMP_SELECT_RANK
, gfc_new_block
);
4978 /* Make sure that the next statement is a RANK IS or RANK DEFAULT. */
4981 st
= next_statement ();
4984 if (st
== ST_END_SELECT
)
4985 /* Empty SELECT CASE is OK. */
4990 gfc_error ("Expected RANK or RANK DEFAULT "
4991 "following SELECT RANK at %C");
4993 reject_statement ();
4996 /* At this point, we've got a nonempty select block. */
4997 cp
= new_level (cp
);
5000 accept_statement (st
);
5004 st
= parse_executable (ST_NONE
);
5011 cp
= new_level (gfc_state_stack
->head
);
5013 gfc_clear_new_st ();
5015 accept_statement (st
);
5021 /* Can't have an executable statement because of
5022 parse_executable(). */
5024 unexpected_statement (st
);
5028 while (st
!= ST_END_SELECT
);
5032 accept_statement (st
);
5033 gfc_current_ns
= gfc_current_ns
->parent
;
5038 /* Given a symbol, make sure it is not an iteration variable for a DO
5039 statement. This subroutine is called when the symbol is seen in a
5040 context that causes it to become redefined. If the symbol is an
5041 iterator, we generate an error message and return nonzero. */
5044 gfc_check_do_variable (gfc_symtree
*st
)
5051 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
5052 if (s
->do_variable
== st
)
5054 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
5055 "loop beginning at %L", st
->name
, &s
->head
->loc
);
5063 /* Checks to see if the current statement label closes an enddo.
5064 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
5065 an error) if it incorrectly closes an ENDDO. */
5068 check_do_closure (void)
5072 if (gfc_statement_label
== NULL
)
5075 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
5076 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
5080 return 0; /* No loops to close */
5082 if (p
->ext
.end_do_label
== gfc_statement_label
)
5084 if (p
== gfc_state_stack
)
5087 gfc_error ("End of nonblock DO statement at %C is within another block");
5091 /* At this point, the label doesn't terminate the innermost loop.
5092 Make sure it doesn't terminate another one. */
5093 for (; p
; p
= p
->previous
)
5094 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
5095 && p
->ext
.end_do_label
== gfc_statement_label
)
5097 gfc_error ("End of nonblock DO statement at %C is interwoven "
5098 "with another DO loop");
5106 /* Parse a series of contained program units. */
5108 static void parse_progunit (gfc_statement
);
5111 /* Parse a CRITICAL block. */
5114 parse_critical_block (void)
5117 gfc_state_data s
, *sd
;
5120 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5121 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
5122 gfc_error_now (is_oacc (sd
)
5123 ? G_("CRITICAL block inside of OpenACC region at %C")
5124 : G_("CRITICAL block inside of OpenMP region at %C"));
5126 s
.ext
.end_do_label
= new_st
.label1
;
5128 accept_statement (ST_CRITICAL
);
5129 top
= gfc_state_stack
->tail
;
5131 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
5133 d
= add_statement ();
5134 d
->op
= EXEC_CRITICAL
;
5139 st
= parse_executable (ST_NONE
);
5147 case ST_END_CRITICAL
:
5148 if (s
.ext
.end_do_label
!= NULL
5149 && s
.ext
.end_do_label
!= gfc_statement_label
)
5150 gfc_error_now ("Statement label in END CRITICAL at %C does not "
5151 "match CRITICAL label");
5153 if (gfc_statement_label
!= NULL
)
5155 new_st
.op
= EXEC_NOP
;
5161 unexpected_statement (st
);
5165 while (st
!= ST_END_CRITICAL
);
5168 accept_statement (st
);
5172 /* Set up the local namespace for a BLOCK construct. */
5175 gfc_build_block_ns (gfc_namespace
*parent_ns
)
5177 gfc_namespace
* my_ns
;
5178 static int numblock
= 1;
5180 my_ns
= gfc_get_namespace (parent_ns
, 1);
5181 my_ns
->construct_entities
= 1;
5183 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
5184 code generation (so it must not be NULL).
5185 We set its recursive argument if our container procedure is recursive, so
5186 that local variables are accordingly placed on the stack when it
5187 will be necessary. */
5189 my_ns
->proc_name
= gfc_new_block
;
5193 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
5195 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
5196 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
5197 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
5198 my_ns
->proc_name
->name
, NULL
);
5200 gfc_commit_symbol (my_ns
->proc_name
);
5203 if (parent_ns
->proc_name
)
5204 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
5210 /* Parse a BLOCK construct. */
5213 parse_block_construct (void)
5215 gfc_namespace
* my_ns
;
5216 gfc_namespace
* my_parent
;
5219 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
5221 my_ns
= gfc_build_block_ns (gfc_current_ns
);
5223 new_st
.op
= EXEC_BLOCK
;
5224 new_st
.ext
.block
.ns
= my_ns
;
5225 new_st
.ext
.block
.assoc
= NULL
;
5226 accept_statement (ST_BLOCK
);
5228 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
5229 gfc_current_ns
= my_ns
;
5230 my_parent
= my_ns
->parent
;
5232 parse_progunit (ST_NONE
);
5234 /* Don't depend on the value of gfc_current_ns; it might have been
5235 reset if the block had errors and was cleaned up. */
5236 gfc_current_ns
= my_parent
;
5242 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
5243 behind the scenes with compiler-generated variables. */
5246 parse_associate (void)
5248 gfc_namespace
* my_ns
;
5251 gfc_association_list
* a
;
5254 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
5256 my_ns
= gfc_build_block_ns (gfc_current_ns
);
5258 new_st
.op
= EXEC_BLOCK
;
5259 new_st
.ext
.block
.ns
= my_ns
;
5260 gcc_assert (new_st
.ext
.block
.assoc
);
5262 /* Add all associate-names as BLOCK variables. Creating them is enough
5263 for now, they'll get their values during trans-* phase. */
5264 gfc_current_ns
= my_ns
;
5265 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
5267 gfc_symbol
*sym
, *tsym
;
5271 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
5275 sym
->attr
.flavor
= FL_VARIABLE
;
5277 sym
->declared_at
= a
->where
;
5278 gfc_set_sym_referenced (sym
);
5280 /* If the selector is a inferred type then the associate_name had better
5281 be as well. Use array references, if present, to identify it as an
5283 if (IS_INFERRED_TYPE (a
->target
))
5285 sym
->assoc
->inferred_type
= 1;
5286 for (gfc_ref
*r
= a
->target
->ref
; r
; r
= r
->next
)
5287 if (r
->type
== REF_ARRAY
)
5288 sym
->attr
.dimension
= 1;
5291 /* Initialize the typespec. It is not available in all cases,
5292 however, as it may only be set on the target during resolution.
5293 Still, sometimes it helps to have it right now -- especially
5294 for parsing component references on the associate-name
5295 in case of association to a derived-type. */
5296 sym
->ts
= a
->target
->ts
;
5299 /* Don’t share the character length information between associate
5300 variable and target if the length is not a compile-time constant,
5301 as we don’t want to touch some other character length variable when
5302 we try to initialize the associate variable’s character length
5304 We do it here rather than later so that expressions referencing the
5305 associate variable will automatically have the correctly setup length
5306 information. If we did it at resolution stage the expressions would
5307 use the original length information, and the variable a new different
5308 one, but only the latter one would be correctly initialized at
5309 translation stage, and the former one would need some additional setup
5311 if (sym
->ts
.type
== BT_CHARACTER
5313 && !(sym
->ts
.u
.cl
->length
5314 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
))
5315 sym
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5317 /* If the function has been parsed, go straight to the result to
5318 obtain the expression rank. */
5319 if (target
->expr_type
== EXPR_FUNCTION
5321 && target
->symtree
->n
.sym
)
5323 tsym
= target
->symtree
->n
.sym
;
5325 tsym
->result
= tsym
;
5326 sym
->ts
= tsym
->result
->ts
;
5327 if (sym
->ts
.type
== BT_CLASS
)
5329 if (CLASS_DATA (sym
)->as
)
5331 target
->rank
= CLASS_DATA (sym
)->as
->rank
;
5332 target
->corank
= CLASS_DATA (sym
)->as
->corank
;
5334 sym
->attr
.class_ok
= 1;
5338 target
->rank
= tsym
->result
->as
? tsym
->result
->as
->rank
: 0;
5339 target
->corank
= tsym
->result
->as
? tsym
->result
->as
->corank
: 0;
5343 /* Check if the target expression is array valued. This cannot be done
5344 by calling gfc_resolve_expr because the context is unavailable.
5345 However, the references can be resolved and the rank of the target
5347 if (!sym
->assoc
->inferred_type
5348 && target
->ref
&& gfc_resolve_ref (target
)
5349 && target
->expr_type
!= EXPR_ARRAY
5350 && target
->expr_type
!= EXPR_COMPCALL
)
5351 gfc_expression_rank (target
);
5353 /* Determine whether or not function expressions with unknown type are
5354 structure constructors. If so, the function result can be converted
5355 to be a derived type. */
5356 if (target
->expr_type
== EXPR_FUNCTION
5357 && target
->ts
.type
== BT_UNKNOWN
)
5359 gfc_symbol
*derived
;
5360 /* The derived type has a leading uppercase character. */
5361 gfc_find_symbol (gfc_dt_upper_string (target
->symtree
->name
),
5362 my_ns
->parent
, 1, &derived
);
5363 if (derived
&& derived
->attr
.flavor
== FL_DERIVED
)
5365 sym
->ts
.type
= BT_DERIVED
;
5366 sym
->ts
.u
.derived
= derived
;
5367 sym
->assoc
->inferred_type
= 0;
5371 rank
= target
->rank
;
5372 corank
= target
->corank
;
5373 /* Fixup cases where the ranks are mismatched. */
5374 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
5376 if ((!CLASS_DATA (sym
)->as
&& (rank
!= 0 || corank
!= 0))
5377 || (CLASS_DATA (sym
)->as
5378 && (CLASS_DATA (sym
)->as
->rank
!= rank
5379 || CLASS_DATA (sym
)->as
->corank
!= corank
))
5382 /* Don't just (re-)set the attr and as in the sym.ts,
5383 because this modifies the target's attr and as. Copy the
5384 data and do a build_class_symbol. */
5385 symbol_attribute attr
= CLASS_DATA (target
)->attr
;
5387 if (rank
== -1 && a
->ar
)
5389 as
= gfc_get_array_spec ();
5390 as
->rank
= a
->ar
->dimen
;
5392 as
->type
= AS_DEFERRED
;
5393 attr
.dimension
= rank
? 1 : 0;
5394 attr
.codimension
= as
->corank
? 1 : 0;
5395 sym
->assoc
->variable
= true;
5397 else if (rank
|| corank
)
5399 as
= gfc_get_array_spec ();
5400 as
->type
= AS_DEFERRED
;
5402 as
->corank
= corank
;
5403 attr
.dimension
= rank
? 1 : 0;
5404 attr
.codimension
= corank
? 1 : 0;
5409 attr
.dimension
= attr
.codimension
= 0;
5412 attr
.associate_var
= 1;
5413 type
= CLASS_DATA (sym
)->ts
;
5414 if (!gfc_build_class_symbol (&type
, &attr
, &as
))
5417 sym
->ts
.type
= BT_CLASS
;
5418 sym
->attr
.class_ok
= 1;
5421 sym
->attr
.class_ok
= 1;
5423 else if (rank
== -1 && a
->ar
)
5425 sym
->as
= gfc_get_array_spec ();
5426 sym
->as
->rank
= a
->ar
->dimen
;
5427 sym
->as
->corank
= a
->ar
->codimen
;
5428 sym
->as
->type
= AS_DEFERRED
;
5429 sym
->attr
.dimension
= 1;
5430 sym
->attr
.codimension
= sym
->as
->corank
? 1 : 0;
5431 sym
->attr
.pointer
= 1;
5433 else if ((!sym
->as
&& (rank
!= 0 || corank
!= 0))
5435 && (sym
->as
->rank
!= rank
|| sym
->as
->corank
!= corank
)))
5437 as
= gfc_get_array_spec ();
5438 as
->type
= AS_DEFERRED
;
5440 as
->corank
= corank
;
5443 sym
->attr
.dimension
= 1;
5446 as
->cotype
= AS_ASSUMED_SHAPE
;
5447 sym
->attr
.codimension
= 1;
5450 gfc_commit_symbols ();
5453 accept_statement (ST_ASSOCIATE
);
5454 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
5457 st
= parse_executable (ST_NONE
);
5464 accept_statement (st
);
5465 my_ns
->code
= gfc_state_stack
->head
;
5469 unexpected_statement (st
);
5473 gfc_current_ns
= gfc_current_ns
->parent
;
5478 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
5479 handled inside of parse_executable(), because they aren't really
5483 parse_do_block (void)
5492 s
.ext
.end_do_label
= new_st
.label1
;
5494 if (do_op
== EXEC_DO_CONCURRENT
)
5496 gfc_forall_iterator
*fa
;
5497 for (fa
= new_st
.ext
.concur
.forall_iterator
; fa
; fa
= fa
->next
)
5499 /* Apply unroll only to innermost loop (first control
5501 if (directive_unroll
!= -1)
5503 fa
->annot
.unroll
= directive_unroll
;
5504 directive_unroll
= -1;
5506 if (directive_ivdep
)
5507 fa
->annot
.ivdep
= directive_ivdep
;
5508 if (directive_vector
)
5509 fa
->annot
.vector
= directive_vector
;
5510 if (directive_novector
)
5511 fa
->annot
.novector
= directive_novector
;
5513 directive_ivdep
= false;
5514 directive_vector
= false;
5515 directive_novector
= false;
5518 else if (new_st
.ext
.iterator
!= NULL
)
5520 stree
= new_st
.ext
.iterator
->var
->symtree
;
5521 if (directive_unroll
!= -1)
5523 new_st
.ext
.iterator
->annot
.unroll
= directive_unroll
;
5524 directive_unroll
= -1;
5526 if (directive_ivdep
)
5528 new_st
.ext
.iterator
->annot
.ivdep
= directive_ivdep
;
5529 directive_ivdep
= false;
5531 if (directive_vector
)
5533 new_st
.ext
.iterator
->annot
.vector
= directive_vector
;
5534 directive_vector
= false;
5536 if (directive_novector
)
5538 new_st
.ext
.iterator
->annot
.novector
= directive_novector
;
5539 directive_novector
= false;
5545 accept_statement (ST_DO
);
5547 top
= gfc_state_stack
->tail
;
5548 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
5551 s
.do_variable
= stree
;
5553 top
->block
= new_level (top
);
5554 top
->block
->op
= EXEC_DO
;
5557 st
= parse_executable (ST_NONE
);
5565 if (s
.ext
.end_do_label
!= NULL
5566 && s
.ext
.end_do_label
!= gfc_statement_label
)
5567 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
5570 if (gfc_statement_label
!= NULL
)
5572 new_st
.op
= EXEC_NOP
;
5577 case ST_IMPLIED_ENDDO
:
5578 /* If the do-stmt of this DO construct has a do-construct-name,
5579 the corresponding end-do must be an end-do-stmt (with a matching
5580 name, but in that case we must have seen ST_ENDDO first).
5581 We only complain about this in pedantic mode. */
5582 if (gfc_current_block () != NULL
)
5583 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
5584 &gfc_current_block()->declared_at
);
5589 unexpected_statement (st
);
5594 accept_statement (st
);
5597 /* Get the corresponding ending statement type for the OpenMP directive
5598 OMP_ST. If it does not have one, return ST_NONE. */
5601 gfc_omp_end_stmt (gfc_statement omp_st
,
5602 bool omp_do_p
, bool omp_structured_p
)
5608 case ST_OMP_DISTRIBUTE
: return ST_OMP_END_DISTRIBUTE
;
5609 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5610 return ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
5611 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5612 return ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
5613 case ST_OMP_DISTRIBUTE_SIMD
:
5614 return ST_OMP_END_DISTRIBUTE_SIMD
;
5615 case ST_OMP_DO
: return ST_OMP_END_DO
;
5616 case ST_OMP_DO_SIMD
: return ST_OMP_END_DO_SIMD
;
5617 case ST_OMP_LOOP
: return ST_OMP_END_LOOP
;
5618 case ST_OMP_PARALLEL_DO
: return ST_OMP_END_PARALLEL_DO
;
5619 case ST_OMP_PARALLEL_DO_SIMD
:
5620 return ST_OMP_END_PARALLEL_DO_SIMD
;
5621 case ST_OMP_PARALLEL_LOOP
:
5622 return ST_OMP_END_PARALLEL_LOOP
;
5623 case ST_OMP_SIMD
: return ST_OMP_END_SIMD
;
5624 case ST_OMP_TARGET_PARALLEL_DO
:
5625 return ST_OMP_END_TARGET_PARALLEL_DO
;
5626 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5627 return ST_OMP_END_TARGET_PARALLEL_DO_SIMD
;
5628 case ST_OMP_TARGET_PARALLEL_LOOP
:
5629 return ST_OMP_END_TARGET_PARALLEL_LOOP
;
5630 case ST_OMP_TARGET_SIMD
: return ST_OMP_END_TARGET_SIMD
;
5631 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5632 return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
5633 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5634 return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5635 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5636 return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5637 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5638 return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
5639 case ST_OMP_TARGET_TEAMS_LOOP
:
5640 return ST_OMP_END_TARGET_TEAMS_LOOP
;
5641 case ST_OMP_TASKLOOP
: return ST_OMP_END_TASKLOOP
;
5642 case ST_OMP_TASKLOOP_SIMD
: return ST_OMP_END_TASKLOOP_SIMD
;
5643 case ST_OMP_MASKED_TASKLOOP
: return ST_OMP_END_MASKED_TASKLOOP
;
5644 case ST_OMP_MASKED_TASKLOOP_SIMD
:
5645 return ST_OMP_END_MASKED_TASKLOOP_SIMD
;
5646 case ST_OMP_MASTER_TASKLOOP
: return ST_OMP_END_MASTER_TASKLOOP
;
5647 case ST_OMP_MASTER_TASKLOOP_SIMD
:
5648 return ST_OMP_END_MASTER_TASKLOOP_SIMD
;
5649 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
5650 return ST_OMP_END_PARALLEL_MASKED_TASKLOOP
;
5651 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
5652 return ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
;
5653 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
5654 return ST_OMP_END_PARALLEL_MASTER_TASKLOOP
;
5655 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
5656 return ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
;
5657 case ST_OMP_TEAMS_DISTRIBUTE
:
5658 return ST_OMP_END_TEAMS_DISTRIBUTE
;
5659 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5660 return ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5661 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5662 return ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5663 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5664 return ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
5665 case ST_OMP_TEAMS_LOOP
:
5666 return ST_OMP_END_TEAMS_LOOP
;
5668 return ST_OMP_END_TILE
;
5670 return ST_OMP_END_UNROLL
;
5676 if (omp_structured_p
)
5680 case ST_OMP_ALLOCATORS
:
5681 return ST_OMP_END_ALLOCATORS
;
5683 return ST_OMP_END_ASSUME
;
5685 return ST_OMP_END_ATOMIC
;
5686 case ST_OMP_DISPATCH
:
5687 return ST_OMP_END_DISPATCH
;
5688 case ST_OMP_PARALLEL
:
5689 return ST_OMP_END_PARALLEL
;
5690 case ST_OMP_PARALLEL_MASKED
:
5691 return ST_OMP_END_PARALLEL_MASKED
;
5692 case ST_OMP_PARALLEL_MASTER
:
5693 return ST_OMP_END_PARALLEL_MASTER
;
5694 case ST_OMP_PARALLEL_SECTIONS
:
5695 return ST_OMP_END_PARALLEL_SECTIONS
;
5697 return ST_OMP_END_SCOPE
;
5698 case ST_OMP_SECTIONS
:
5699 return ST_OMP_END_SECTIONS
;
5700 case ST_OMP_ORDERED
:
5701 return ST_OMP_END_ORDERED
;
5702 case ST_OMP_CRITICAL
:
5703 return ST_OMP_END_CRITICAL
;
5705 return ST_OMP_END_MASKED
;
5707 return ST_OMP_END_MASTER
;
5709 return ST_OMP_END_SINGLE
;
5711 return ST_OMP_END_TARGET
;
5712 case ST_OMP_TARGET_DATA
:
5713 return ST_OMP_END_TARGET_DATA
;
5714 case ST_OMP_TARGET_PARALLEL
:
5715 return ST_OMP_END_TARGET_PARALLEL
;
5716 case ST_OMP_TARGET_TEAMS
:
5717 return ST_OMP_END_TARGET_TEAMS
;
5719 return ST_OMP_END_TASK
;
5720 case ST_OMP_TASKGROUP
:
5721 return ST_OMP_END_TASKGROUP
;
5723 return ST_OMP_END_TEAMS
;
5724 case ST_OMP_TEAMS_DISTRIBUTE
:
5725 return ST_OMP_END_TEAMS_DISTRIBUTE
;
5726 case ST_OMP_DISTRIBUTE
:
5727 return ST_OMP_END_DISTRIBUTE
;
5728 case ST_OMP_WORKSHARE
:
5729 return ST_OMP_END_WORKSHARE
;
5730 case ST_OMP_PARALLEL_WORKSHARE
:
5731 return ST_OMP_END_PARALLEL_WORKSHARE
;
5732 case ST_OMP_BEGIN_METADIRECTIVE
:
5733 return ST_OMP_END_METADIRECTIVE
;
5742 /* Parse the statements of OpenMP do/parallel do. */
5744 static gfc_statement
5745 parse_omp_do (gfc_statement omp_st
, int nested
)
5751 accept_statement (omp_st
);
5753 cp
= gfc_state_stack
->tail
;
5754 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5755 np
= new_level (cp
);
5761 st
= next_statement ();
5764 else if (st
== ST_DO
)
5766 else if (st
== ST_OMP_UNROLL
|| st
== ST_OMP_TILE
)
5768 st
= parse_omp_do (st
, nested
+ 1);
5769 if (st
== ST_IMPLIED_ENDDO
)
5774 unexpected_statement (st
);
5778 for (; nested
; --nested
)
5780 if (gfc_statement_label
!= NULL
5781 && gfc_state_stack
->previous
!= NULL
5782 && gfc_state_stack
->previous
->state
== COMP_DO
5783 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5791 there should be no !$OMP END DO. */
5793 return ST_IMPLIED_ENDDO
;
5796 check_do_closure ();
5799 st
= next_statement ();
5801 gfc_statement omp_end_st
= gfc_omp_end_stmt (omp_st
, true, false);
5802 if (omp_st
== ST_NONE
)
5805 /* If handling a metadirective variant, treat 'omp end metadirective'
5806 as the expected end statement for the current construct. */
5807 if (st
== ST_OMP_END_METADIRECTIVE
5808 && gfc_state_stack
->state
== COMP_OMP_BEGIN_METADIRECTIVE
)
5811 if (st
== omp_end_st
)
5813 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
5815 if (cp
->ext
.omp_clauses
->nowait
&& new_st
.ext
.omp_bool
)
5816 gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
5817 gfc_ascii_statement (omp_st
),
5818 gfc_ascii_statement (omp_end_st
));
5819 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5822 gcc_assert (new_st
.op
== EXEC_NOP
);
5823 gfc_clear_new_st ();
5824 gfc_commit_symbols ();
5825 gfc_warning_check ();
5826 st
= next_statement ();
5832 /* Parse the statements of OpenMP atomic directive. */
5834 static gfc_statement
5835 parse_omp_oacc_atomic (bool omp_p
)
5837 gfc_statement st
, st_atomic
, st_end_atomic
;
5844 st_atomic
= ST_OMP_ATOMIC
;
5845 if (gfc_state_stack
->state
== COMP_OMP_BEGIN_METADIRECTIVE
)
5846 st_end_atomic
= ST_OMP_END_METADIRECTIVE
;
5848 st_end_atomic
= ST_OMP_END_ATOMIC
;
5852 st_atomic
= ST_OACC_ATOMIC
;
5853 st_end_atomic
= ST_OACC_END_ATOMIC
;
5855 accept_statement (st_atomic
);
5857 cp
= gfc_state_stack
->tail
;
5858 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5859 np
= new_level (cp
);
5862 np
->ext
.omp_clauses
= cp
->ext
.omp_clauses
;
5863 cp
->ext
.omp_clauses
= NULL
;
5864 count
= 1 + np
->ext
.omp_clauses
->capture
;
5868 st
= next_statement ();
5871 else if (np
->ext
.omp_clauses
->compare
5872 && (st
== ST_SIMPLE_IF
|| st
== ST_IF_BLOCK
))
5875 if (st
== ST_IF_BLOCK
)
5878 /* With else (or elseif). */
5879 if (gfc_state_stack
->tail
->block
->block
)
5882 accept_statement (st
);
5884 else if (st
== ST_ASSIGNMENT
5885 && (!np
->ext
.omp_clauses
->compare
5886 || np
->ext
.omp_clauses
->capture
))
5888 accept_statement (st
);
5892 unexpected_statement (st
);
5897 st
= next_statement ();
5898 if (st
== st_end_atomic
)
5900 gfc_clear_new_st ();
5901 gfc_commit_symbols ();
5902 gfc_warning_check ();
5903 st
= next_statement ();
5909 /* Parse the statements of an OpenACC structured block. */
5912 parse_oacc_structured_block (gfc_statement acc_st
)
5914 gfc_statement st
, acc_end_st
;
5916 gfc_state_data s
, *sd
;
5918 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5919 if (sd
->state
== COMP_CRITICAL
)
5920 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5922 accept_statement (acc_st
);
5924 cp
= gfc_state_stack
->tail
;
5925 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5926 np
= new_level (cp
);
5931 case ST_OACC_PARALLEL
:
5932 acc_end_st
= ST_OACC_END_PARALLEL
;
5934 case ST_OACC_KERNELS
:
5935 acc_end_st
= ST_OACC_END_KERNELS
;
5937 case ST_OACC_SERIAL
:
5938 acc_end_st
= ST_OACC_END_SERIAL
;
5941 acc_end_st
= ST_OACC_END_DATA
;
5943 case ST_OACC_HOST_DATA
:
5944 acc_end_st
= ST_OACC_END_HOST_DATA
;
5952 st
= parse_executable (ST_NONE
);
5955 else if (st
!= acc_end_st
)
5957 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
5958 reject_statement ();
5961 while (st
!= acc_end_st
);
5963 gcc_assert (new_st
.op
== EXEC_NOP
);
5965 gfc_clear_new_st ();
5966 gfc_commit_symbols ();
5967 gfc_warning_check ();
5971 /* Parse the statements of OpenACC 'loop', or combined compute 'loop'. */
5973 static gfc_statement
5974 parse_oacc_loop (gfc_statement acc_st
)
5978 gfc_state_data s
, *sd
;
5980 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5981 if (sd
->state
== COMP_CRITICAL
)
5982 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5984 accept_statement (acc_st
);
5986 cp
= gfc_state_stack
->tail
;
5987 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5988 np
= new_level (cp
);
5994 st
= next_statement ();
5997 else if (st
== ST_DO
)
6001 gfc_error ("Expected DO loop at %C");
6002 reject_statement ();
6007 if (gfc_statement_label
!= NULL
6008 && gfc_state_stack
->previous
!= NULL
6009 && gfc_state_stack
->previous
->state
== COMP_DO
6010 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
6013 return ST_IMPLIED_ENDDO
;
6016 check_do_closure ();
6019 st
= next_statement ();
6020 if (st
== ST_OACC_END_LOOP
)
6021 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
6022 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
6023 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
6024 (acc_st
== ST_OACC_SERIAL_LOOP
&& st
== ST_OACC_END_SERIAL_LOOP
) ||
6025 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
6027 gcc_assert (new_st
.op
== EXEC_NOP
);
6028 gfc_clear_new_st ();
6029 gfc_commit_symbols ();
6030 gfc_warning_check ();
6031 st
= next_statement ();
6037 /* Parse an OpenMP allocate block, including optional ALLOCATORS
6040 static gfc_statement
6041 parse_openmp_allocate_block (gfc_statement omp_st
)
6046 bool empty_list
= false;
6047 locus empty_list_loc
;
6048 gfc_omp_namelist
*n_first
= new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
];
6050 if (omp_st
== ST_OMP_ALLOCATE_EXEC
6051 && new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]->sym
== NULL
)
6054 empty_list_loc
= new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]->where
;
6057 accept_statement (omp_st
);
6059 cp
= gfc_state_stack
->tail
;
6060 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
6061 np
= new_level (cp
);
6065 st
= next_statement ();
6066 while (omp_st
== ST_OMP_ALLOCATE_EXEC
&& st
== ST_OMP_ALLOCATE_EXEC
)
6068 if (empty_list
&& !new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]->sym
)
6070 locus
*loc
= &new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]->where
;
6071 gfc_error_now ("%s statements at %L and %L have both no list item but"
6072 " only one may", gfc_ascii_statement (st
),
6073 &empty_list_loc
, loc
);
6076 if (!new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]->sym
)
6079 empty_list_loc
= new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
]->where
;
6081 for ( ; n_first
->next
; n_first
= n_first
->next
)
6083 n_first
->next
= new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
];
6084 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_ALLOCATE
] = NULL
;
6085 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
6087 accept_statement (ST_NONE
);
6088 st
= next_statement ();
6090 if (st
!= ST_ALLOCATE
&& omp_st
== ST_OMP_ALLOCATE_EXEC
)
6091 gfc_error_now ("Unexpected %s at %C; expected ALLOCATE or %s statement",
6092 gfc_ascii_statement (st
), gfc_ascii_statement (omp_st
));
6093 else if (st
!= ST_ALLOCATE
)
6094 gfc_error_now ("Unexpected %s at %C; expected ALLOCATE statement after %s",
6095 gfc_ascii_statement (st
), gfc_ascii_statement (omp_st
));
6096 accept_statement (st
);
6098 st
= next_statement ();
6099 if (omp_st
== ST_OMP_ALLOCATORS
6100 && (st
== ST_OMP_END_ALLOCATORS
6101 || (st
== ST_OMP_END_METADIRECTIVE
6102 && gfc_state_stack
->state
== COMP_OMP_BEGIN_METADIRECTIVE
)))
6104 accept_statement (st
);
6105 st
= next_statement ();
6111 /* Parse the statements of an OpenMP structured block. */
6113 static gfc_statement
6114 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
6116 gfc_statement st
, omp_end_st
, first_st
;
6118 gfc_state_data s
, s2
;
6120 accept_statement (omp_st
);
6122 cp
= gfc_state_stack
->tail
;
6123 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
6124 np
= new_level (cp
);
6128 omp_end_st
= gfc_omp_end_stmt (omp_st
, false, true);
6129 if (omp_end_st
== ST_NONE
)
6132 /* If handling a metadirective variant, treat 'omp end metadirective'
6133 as the expected end statement for the current construct. */
6134 if (gfc_state_stack
->previous
!= NULL
6135 && gfc_state_stack
->previous
->state
== COMP_OMP_BEGIN_METADIRECTIVE
)
6136 omp_end_st
= ST_OMP_END_METADIRECTIVE
;
6138 bool block_construct
= false;
6139 gfc_namespace
*my_ns
= NULL
;
6140 gfc_namespace
*my_parent
= NULL
;
6142 first_st
= st
= next_statement ();
6146 /* Adjust state to a strictly-structured block, now that we found that
6147 the body starts with a BLOCK construct. */
6148 s
.state
= COMP_OMP_STRICTLY_STRUCTURED_BLOCK
;
6150 block_construct
= true;
6151 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
6153 my_ns
= gfc_build_block_ns (gfc_current_ns
);
6154 new_st
.op
= EXEC_BLOCK
;
6155 new_st
.ext
.block
.ns
= my_ns
;
6156 new_st
.ext
.block
.assoc
= NULL
;
6157 accept_statement (ST_BLOCK
);
6159 push_state (&s2
, COMP_BLOCK
, my_ns
->proc_name
);
6160 gfc_current_ns
= my_ns
;
6161 my_parent
= my_ns
->parent
;
6162 if (omp_st
== ST_OMP_SECTIONS
6163 || omp_st
== ST_OMP_PARALLEL_SECTIONS
)
6165 np
= new_level (cp
);
6169 first_st
= next_statement ();
6170 st
= parse_spec (first_st
);
6173 if (omp_end_st
== ST_OMP_END_TARGET
)
6177 case ST_OMP_TEAMS_DISTRIBUTE
:
6178 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
6179 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
6180 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
6181 case ST_OMP_TEAMS_LOOP
:
6182 case ST_OMP_METADIRECTIVE
:
6183 case ST_OMP_BEGIN_METADIRECTIVE
:
6185 gfc_state_data
*stk
= gfc_state_stack
->previous
;
6186 if (stk
->state
== COMP_OMP_STRICTLY_STRUCTURED_BLOCK
)
6187 stk
= stk
->previous
;
6188 stk
->tail
->ext
.omp_clauses
->target_first_st_is_teams_or_meta
= true;
6197 if (workshare_stmts_only
)
6199 /* Inside of !$omp workshare, only
6202 where statements and constructs
6203 forall statements and constructs
6207 are allowed. For !$omp critical these
6208 restrictions apply recursively. */
6221 accept_statement (st
);
6224 case ST_WHERE_BLOCK
:
6225 parse_where_block ();
6228 case ST_FORALL_BLOCK
:
6229 parse_forall_block ();
6232 case ST_OMP_ALLOCATE_EXEC
:
6233 case ST_OMP_ALLOCATORS
:
6234 st
= parse_openmp_allocate_block (st
);
6238 case ST_OMP_PARALLEL
:
6239 case ST_OMP_PARALLEL_MASKED
:
6240 case ST_OMP_PARALLEL_MASTER
:
6241 case ST_OMP_PARALLEL_SECTIONS
:
6242 st
= parse_omp_structured_block (st
, false);
6245 case ST_OMP_PARALLEL_WORKSHARE
:
6246 case ST_OMP_CRITICAL
:
6247 st
= parse_omp_structured_block (st
, true);
6250 case ST_OMP_PARALLEL_DO
:
6251 case ST_OMP_PARALLEL_DO_SIMD
:
6252 st
= parse_omp_do (st
, 0);
6256 st
= parse_omp_oacc_atomic (true);
6267 st
= next_statement ();
6271 st
= parse_executable (st
);
6274 else if (st
== ST_OMP_SECTION
6275 && (omp_st
== ST_OMP_SECTIONS
6276 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
6278 np
= new_level (np
);
6281 st
= next_statement ();
6283 else if (block_construct
&& st
== ST_END_BLOCK
)
6285 accept_statement (st
);
6286 gfc_current_ns
->code
= gfc_state_stack
->head
;
6287 gfc_current_ns
= my_parent
;
6288 pop_state (); /* Inner BLOCK */
6289 pop_state (); /* Outer COMP_OMP_STRICTLY_STRUCTURED_BLOCK */
6291 st
= next_statement ();
6292 if (st
== omp_end_st
)
6294 accept_statement (st
);
6295 st
= next_statement ();
6299 else if (st
!= omp_end_st
|| block_construct
)
6301 unexpected_statement (st
);
6302 st
= next_statement ();
6305 while (st
!= omp_end_st
);
6309 case EXEC_OMP_END_NOWAIT
:
6310 if (cp
->ext
.omp_clauses
->nowait
&& new_st
.ext
.omp_bool
)
6311 gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
6312 gfc_ascii_statement (omp_st
),
6313 gfc_ascii_statement (omp_end_st
));
6314 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
6316 case EXEC_OMP_END_CRITICAL
:
6317 if (((cp
->ext
.omp_clauses
->critical_name
== NULL
)
6318 ^ (new_st
.ext
.omp_name
== NULL
))
6319 || (new_st
.ext
.omp_name
!= NULL
6320 && strcmp (cp
->ext
.omp_clauses
->critical_name
,
6321 new_st
.ext
.omp_name
) != 0))
6322 gfc_error ("Name after !$omp critical and !$omp end critical does "
6324 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
6325 new_st
.ext
.omp_name
= NULL
;
6327 case EXEC_OMP_END_SINGLE
:
6328 if (cp
->ext
.omp_clauses
->nowait
&& new_st
.ext
.omp_clauses
->nowait
)
6329 gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
6330 gfc_ascii_statement (omp_st
),
6331 gfc_ascii_statement (omp_end_st
));
6332 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_clauses
->nowait
;
6333 if (cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
])
6335 gfc_omp_namelist
*nl
;
6336 for (nl
= cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
6337 nl
->next
; nl
= nl
->next
)
6339 nl
->next
= new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
6342 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
6343 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
6344 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
6345 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
6353 gfc_clear_new_st ();
6354 gfc_commit_symbols ();
6355 gfc_warning_check ();
6357 st
= next_statement ();
6361 static gfc_statement
6362 parse_omp_dispatch (void)
6368 accept_statement (ST_OMP_DISPATCH
);
6370 cp
= gfc_state_stack
->tail
;
6371 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
6372 np
= new_level (cp
);
6376 st
= next_statement ();
6379 if (st
== ST_CALL
|| st
== ST_ASSIGNMENT
)
6380 accept_statement (st
);
6383 gfc_error ("%<OMP DISPATCH%> directive must be followed by a procedure "
6384 "call with optional assignment at %C");
6385 reject_statement ();
6388 st
= next_statement ();
6389 if (st
== ST_OMP_END_DISPATCH
6390 || (st
== ST_OMP_END_METADIRECTIVE
6391 && gfc_state_stack
->state
== COMP_OMP_BEGIN_METADIRECTIVE
))
6393 if (cp
->ext
.omp_clauses
->nowait
&& new_st
.ext
.omp_bool
)
6394 gfc_error_now ("Duplicated NOWAIT clause on !$OMP DISPATCH and !$OMP "
6395 "END DISPATCH at %C");
6396 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
6397 accept_statement (st
);
6398 st
= next_statement ();
6403 static gfc_statement
6404 parse_omp_metadirective_body (gfc_statement omp_st
)
6406 gfc_omp_variant
*variant
6407 = new_st
.ext
.omp_variants
;
6408 locus body_locus
= gfc_current_locus
;
6410 accept_statement (omp_st
);
6412 gfc_statement next_st
= ST_NONE
;
6416 gfc_current_locus
= body_locus
;
6419 = (variant
->stmt
== ST_OMP_WORKSHARE
6420 || variant
->stmt
== ST_OMP_PARALLEL_WORKSHARE
);
6421 enum gfc_compile_state new_state
6422 = (omp_st
== ST_OMP_METADIRECTIVE
6423 ? COMP_OMP_METADIRECTIVE
: COMP_OMP_BEGIN_METADIRECTIVE
);
6425 new_st
= *variant
->code
;
6426 push_state (&s
, new_state
, NULL
);
6429 bool old_in_metadirective_body
= gfc_in_omp_metadirective_body
;
6430 gfc_in_omp_metadirective_body
= true;
6432 gfc_omp_metadirective_region_count
++;
6433 switch (variant
->stmt
)
6435 case_omp_structured_block
:
6436 st
= parse_omp_structured_block (variant
->stmt
, workshare_p
);
6439 st
= parse_omp_do (variant
->stmt
, 0);
6440 /* TODO: Does st == ST_IMPLIED_ENDDO need special handling? */
6442 case ST_OMP_ALLOCATORS
:
6443 st
= parse_openmp_allocate_block (variant
->stmt
);
6446 st
= parse_omp_oacc_atomic (true);
6448 case ST_OMP_DISPATCH
:
6449 st
= parse_omp_dispatch ();
6452 accept_statement (variant
->stmt
);
6453 st
= parse_executable (next_statement ());
6457 if (gfc_state_stack
->state
== COMP_OMP_METADIRECTIVE
6458 && startswith (gfc_ascii_statement (st
), "!$OMP END "))
6460 for (gfc_state_data
*p
= gfc_state_stack
; p
; p
= p
->previous
)
6461 if (p
->state
== COMP_OMP_STRUCTURED_BLOCK
6462 || p
->state
== COMP_OMP_BEGIN_METADIRECTIVE
)
6464 gfc_error ("Unexpected %s statement in OMP METADIRECTIVE "
6466 gfc_ascii_statement (st
));
6467 reject_statement ();
6468 st
= next_statement ();
6472 gfc_in_omp_metadirective_body
= old_in_metadirective_body
;
6474 if (gfc_state_stack
->head
)
6475 *variant
->code
= *gfc_state_stack
->head
;
6478 gfc_commit_symbols ();
6479 gfc_warning_check ();
6481 gfc_clear_new_st ();
6483 /* Sanity-check that each variant finishes parsing at the same place. */
6484 if (next_st
== ST_NONE
)
6487 gcc_assert (st
== next_st
);
6489 variant
= variant
->next
;
6495 /* Accept a series of executable statements. We return the first
6496 statement that doesn't fit to the caller. Any block statements are
6497 passed on to the correct handler, which usually passes the buck
6500 static gfc_statement
6501 parse_executable (gfc_statement st
)
6504 bool one_stmt_p
= false;
6505 in_exec_part
= true;
6508 st
= next_statement ();
6512 /* Only parse one statement for the form of metadirective without
6513 an explicit begin..end. */
6514 if (gfc_state_stack
->state
== COMP_OMP_METADIRECTIVE
&& one_stmt_p
)
6518 close_flag
= check_do_closure ();
6523 case ST_END_PROGRAM
:
6526 case ST_END_FUNCTION
:
6531 case ST_END_SUBROUTINE
:
6536 case ST_SELECT_CASE
:
6537 gfc_error ("%s statement at %C cannot terminate a non-block "
6538 "DO loop", gfc_ascii_statement (st
));
6551 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
6552 "first executable statement");
6558 accept_statement (st
);
6559 if (close_flag
== 1)
6560 return ST_IMPLIED_ENDDO
;
6564 parse_block_construct ();
6575 case ST_SELECT_CASE
:
6576 parse_select_block ();
6579 case ST_SELECT_TYPE
:
6580 parse_select_type_block ();
6583 case ST_SELECT_RANK
:
6584 parse_select_rank_block ();
6589 if (check_do_closure () == 1)
6590 return ST_IMPLIED_ENDDO
;
6594 parse_critical_block ();
6597 case ST_WHERE_BLOCK
:
6598 parse_where_block ();
6601 case ST_FORALL_BLOCK
:
6602 parse_forall_block ();
6605 case ST_OACC_PARALLEL_LOOP
:
6606 case ST_OACC_KERNELS_LOOP
:
6607 case ST_OACC_SERIAL_LOOP
:
6609 st
= parse_oacc_loop (st
);
6610 if (st
== ST_IMPLIED_ENDDO
)
6614 case ST_OACC_PARALLEL
:
6615 case ST_OACC_KERNELS
:
6616 case ST_OACC_SERIAL
:
6618 case ST_OACC_HOST_DATA
:
6619 parse_oacc_structured_block (st
);
6622 case ST_OMP_ALLOCATE_EXEC
:
6623 case ST_OMP_ALLOCATORS
:
6624 st
= parse_openmp_allocate_block (st
);
6627 case_omp_structured_block
:
6628 st
= parse_omp_structured_block (st
,
6629 st
== ST_OMP_WORKSHARE
6630 || st
== ST_OMP_PARALLEL_WORKSHARE
);
6634 st
= parse_omp_do (st
, 0);
6635 if (st
== ST_IMPLIED_ENDDO
)
6639 case ST_OACC_ATOMIC
:
6640 st
= parse_omp_oacc_atomic (false);
6644 st
= parse_omp_oacc_atomic (true);
6647 case ST_OMP_DISPATCH
:
6648 st
= parse_omp_dispatch ();
6651 case ST_OMP_METADIRECTIVE
:
6652 case ST_OMP_BEGIN_METADIRECTIVE
:
6653 st
= parse_omp_metadirective_body (st
);
6656 case ST_OMP_END_METADIRECTIVE
:
6657 if (gfc_state_stack
->state
== COMP_OMP_BEGIN_METADIRECTIVE
)
6658 return next_statement ();
6666 if (directive_unroll
!= -1)
6667 gfc_error ("%<GCC unroll%> directive not at the start of a loop at %C");
6669 if (directive_ivdep
)
6670 gfc_error ("%<GCC ivdep%> directive not at the start of a loop at %C");
6672 if (directive_vector
)
6673 gfc_error ("%<GCC vector%> directive not at the start of a loop at %C");
6675 if (directive_novector
)
6676 gfc_error ("%<GCC novector%> "
6677 "directive not at the start of a loop at %C");
6679 st
= next_statement ();
6684 /* Fix the symbols for sibling functions. These are incorrectly added to
6685 the child namespace as the parser didn't know about this procedure. */
6688 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
6692 gfc_symbol
*old_sym
;
6694 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
6696 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
6698 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
6699 goto fixup_contained
;
6701 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
6702 && sym
->attr
.generic
&& sym
->attr
.function
)
6703 ||(sym
->attr
.flavor
== FL_DERIVED
6704 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
6705 goto fixup_contained
;
6707 old_sym
= st
->n
.sym
;
6708 if (old_sym
->ns
== ns
6709 && !old_sym
->attr
.contained
6711 /* By 14.6.1.3, host association should be excluded
6712 for the following. */
6713 && !(old_sym
->attr
.external
6714 || (old_sym
->ts
.type
!= BT_UNKNOWN
6715 && !old_sym
->attr
.implicit_type
)
6716 || old_sym
->attr
.flavor
== FL_PARAMETER
6717 || old_sym
->attr
.use_assoc
6718 || old_sym
->attr
.in_common
6719 || old_sym
->attr
.in_equivalence
6720 || old_sym
->attr
.data
6721 || old_sym
->attr
.dummy
6722 || old_sym
->attr
.result
6723 || old_sym
->attr
.dimension
6724 || old_sym
->attr
.allocatable
6725 || old_sym
->attr
.intrinsic
6726 || old_sym
->attr
.generic
6727 || old_sym
->attr
.flavor
== FL_NAMELIST
6728 || old_sym
->attr
.flavor
== FL_LABEL
6729 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
6731 /* Replace it with the symbol from the parent namespace. */
6735 gfc_release_symbol (old_sym
);
6739 /* Do the same for any contained procedures. */
6740 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
6745 parse_contained (int module
)
6747 gfc_namespace
*ns
, *parent_ns
, *tmp
;
6748 gfc_state_data s1
, s2
;
6753 int contains_statements
= 0;
6756 push_state (&s1
, COMP_CONTAINS
, NULL
);
6757 parent_ns
= gfc_current_ns
;
6761 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
6763 gfc_current_ns
->sibling
= parent_ns
->contained
;
6764 parent_ns
->contained
= gfc_current_ns
;
6767 /* Process the next available statement. We come here if we got an error
6768 and rejected the last statement. */
6769 old_loc
= gfc_current_locus
;
6770 st
= next_statement ();
6779 contains_statements
= 1;
6780 accept_statement (st
);
6783 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
6786 /* For internal procedures, create/update the symbol in the
6787 parent namespace. */
6791 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
6792 gfc_error ("Contained procedure %qs at %C is already "
6793 "ambiguous", gfc_new_block
->name
);
6796 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
6798 &gfc_new_block
->declared_at
))
6800 if (st
== ST_FUNCTION
)
6801 gfc_add_function (&sym
->attr
, sym
->name
,
6802 &gfc_new_block
->declared_at
);
6804 gfc_add_subroutine (&sym
->attr
, sym
->name
,
6805 &gfc_new_block
->declared_at
);
6809 gfc_commit_symbols ();
6812 sym
= gfc_new_block
;
6814 /* Mark this as a contained function, so it isn't replaced
6815 by other module functions. */
6816 sym
->attr
.contained
= 1;
6818 /* Set implicit_pure so that it can be reset if any of the
6819 tests for purity fail. This is used for some optimisation
6820 during translation. */
6821 if (!sym
->attr
.pure
)
6822 sym
->attr
.implicit_pure
= 1;
6824 parse_progunit (ST_NONE
);
6826 /* Fix up any sibling functions that refer to this one. */
6827 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
6828 /* Or refer to any of its alternate entry points. */
6829 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
6830 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
6832 gfc_current_ns
->code
= s2
.head
;
6833 gfc_current_ns
= parent_ns
;
6838 /* These statements are associated with the end of the host unit. */
6839 case ST_END_FUNCTION
:
6841 case ST_END_SUBMODULE
:
6842 case ST_END_PROGRAM
:
6843 case ST_END_SUBROUTINE
:
6844 accept_statement (st
);
6845 gfc_current_ns
->code
= s1
.head
;
6849 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
6850 gfc_ascii_statement (st
));
6851 reject_statement ();
6857 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
6858 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
6859 && st
!= ST_END_PROGRAM
);
6861 /* The first namespace in the list is guaranteed to not have
6862 anything (worthwhile) in it. */
6863 tmp
= gfc_current_ns
;
6864 gfc_current_ns
= parent_ns
;
6865 if (seen_error
&& tmp
->refs
> 1)
6866 gfc_free_namespace (tmp
);
6868 ns
= gfc_current_ns
->contained
;
6869 gfc_current_ns
->contained
= ns
->sibling
;
6870 gfc_free_namespace (ns
);
6873 if (!contains_statements
)
6874 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
6875 "FUNCTION or SUBROUTINE statement at %L", &old_loc
);
6879 /* The result variable in a MODULE PROCEDURE needs to be created and
6880 its characteristics copied from the interface since it is neither
6881 declared in the procedure declaration nor in the specification
6885 get_modproc_result (void)
6888 if (gfc_state_stack
->previous
6889 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
6890 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
6892 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
6894 && proc
->attr
.function
6896 && proc
->tlink
->result
6897 && proc
->tlink
->result
!= proc
->tlink
)
6899 gfc_copy_dummy_sym (&proc
->result
, proc
->tlink
->result
, 1);
6900 gfc_set_sym_referenced (proc
->result
);
6901 proc
->result
->attr
.if_source
= IFSRC_DECL
;
6902 gfc_commit_symbol (proc
->result
);
6908 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
6911 parse_progunit (gfc_statement st
)
6916 gfc_adjust_builtins ();
6919 && gfc_new_block
->abr_modproc_decl
6920 && gfc_new_block
->attr
.function
)
6921 get_modproc_result ();
6923 st
= parse_spec (st
);
6930 /* This is not allowed within BLOCK! */
6931 if (gfc_current_state () != COMP_BLOCK
)
6936 accept_statement (st
);
6943 if (gfc_current_state () == COMP_FUNCTION
)
6944 gfc_check_function_type (gfc_current_ns
);
6949 st
= parse_executable (st
);
6957 /* This is not allowed within BLOCK! */
6958 if (gfc_current_state () != COMP_BLOCK
)
6963 accept_statement (st
);
6970 unexpected_statement (st
);
6971 reject_statement ();
6972 st
= next_statement ();
6978 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
6979 if (p
->state
== COMP_CONTAINS
)
6982 if (gfc_find_state (COMP_MODULE
) == true
6983 || gfc_find_state (COMP_SUBMODULE
) == true)
6988 gfc_error ("CONTAINS statement at %C is already in a contained "
6990 reject_statement ();
6991 st
= next_statement ();
6995 parse_contained (0);
6998 gfc_current_ns
->code
= gfc_state_stack
->head
;
7002 /* Come here to complain about a global symbol already in use as
7006 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
7011 where
= &gfc_current_locus
;
7021 case GSYM_SUBROUTINE
:
7022 name
= "SUBROUTINE";
7027 case GSYM_BLOCK_DATA
:
7028 name
= "BLOCK DATA";
7039 if (sym
->binding_label
)
7040 gfc_error ("Global binding name %qs at %L is already being used "
7041 "as a %s at %L", sym
->binding_label
, where
, name
,
7044 gfc_error ("Global name %qs at %L is already being used as "
7045 "a %s at %L", sym
->name
, where
, name
, &sym
->where
);
7049 if (sym
->binding_label
)
7050 gfc_error ("Global binding name %qs at %L is already being used "
7051 "at %L", sym
->binding_label
, where
, &sym
->where
);
7053 gfc_error ("Global name %qs at %L is already being used at %L",
7054 sym
->name
, where
, &sym
->where
);
7059 /* Parse a block data program unit. */
7062 parse_block_data (void)
7065 static locus blank_locus
;
7066 static int blank_block
=0;
7069 gfc_current_ns
->proc_name
= gfc_new_block
;
7070 gfc_current_ns
->is_block_data
= 1;
7072 if (gfc_new_block
== NULL
)
7075 gfc_error ("Blank BLOCK DATA at %C conflicts with "
7076 "prior BLOCK DATA at %L", &blank_locus
);
7080 blank_locus
= gfc_current_locus
;
7085 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
7087 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
7088 gfc_global_used (s
, &gfc_new_block
->declared_at
);
7091 s
->type
= GSYM_BLOCK_DATA
;
7092 s
->where
= gfc_new_block
->declared_at
;
7097 st
= parse_spec (ST_NONE
);
7099 while (st
!= ST_END_BLOCK_DATA
)
7101 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
7102 gfc_ascii_statement (st
));
7103 reject_statement ();
7104 st
= next_statement ();
7109 /* Following the association of the ancestor (sub)module symbols, they
7110 must be set host rather than use associated and all must be public.
7111 They are flagged up by 'used_in_submodule' so that they can be set
7112 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
7113 linker chokes on multiple symbol definitions. */
7116 set_syms_host_assoc (gfc_symbol
*sym
)
7119 const char dot
[2] = ".";
7120 /* Symbols take the form module.submodule_ or module.name_. */
7121 char parent1
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
7122 char parent2
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
7127 if (sym
->attr
.module_procedure
)
7128 sym
->attr
.external
= 0;
7130 sym
->attr
.use_assoc
= 0;
7131 sym
->attr
.host_assoc
= 1;
7132 sym
->attr
.used_in_submodule
=1;
7134 if (sym
->attr
.flavor
== FL_DERIVED
)
7136 /* Derived types with PRIVATE components that are declared in
7137 modules other than the parent module must not be changed to be
7138 PUBLIC. The 'use-assoc' attribute must be reset so that the
7139 test in symbol.cc(gfc_find_component) works correctly. This is
7140 not necessary for PRIVATE symbols since they are not read from
7142 memset(parent1
, '\0', sizeof(parent1
));
7143 memset(parent2
, '\0', sizeof(parent2
));
7144 strcpy (parent1
, gfc_new_block
->name
);
7145 strcpy (parent2
, sym
->module
);
7146 if (strcmp (strtok (parent1
, dot
), strtok (parent2
, dot
)) == 0)
7148 for (c
= sym
->components
; c
; c
= c
->next
)
7149 c
->attr
.access
= ACCESS_PUBLIC
;
7153 sym
->attr
.use_assoc
= 1;
7154 sym
->attr
.host_assoc
= 0;
7159 /* Parse a module subprogram. */
7167 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
7168 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
7169 gfc_global_used (s
, &gfc_new_block
->declared_at
);
7172 s
->type
= GSYM_MODULE
;
7173 s
->where
= gfc_new_block
->declared_at
;
7177 /* Something is nulling the module_list after this point. This is good
7178 since it allows us to 'USE' the parent modules that the submodule
7179 inherits and to set (most) of the symbols as host associated. */
7180 if (gfc_current_state () == COMP_SUBMODULE
)
7183 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
7186 st
= parse_spec (ST_NONE
);
7195 parse_contained (1);
7199 case ST_END_SUBMODULE
:
7200 accept_statement (st
);
7204 gfc_error ("Unexpected %s statement in MODULE at %C",
7205 gfc_ascii_statement (st
));
7206 reject_statement ();
7207 st
= next_statement ();
7210 s
->ns
= gfc_current_ns
;
7214 /* Add a procedure name to the global symbol table. */
7217 add_global_procedure (bool sub
)
7221 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
7222 name is a global identifier. */
7223 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
7225 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
7228 || (s
->type
!= GSYM_UNKNOWN
7229 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
7231 gfc_global_used (s
, &gfc_new_block
->declared_at
);
7232 /* Silence follow-up errors. */
7233 gfc_new_block
->binding_label
= NULL
;
7237 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
7238 s
->sym_name
= gfc_new_block
->name
;
7239 s
->where
= gfc_new_block
->declared_at
;
7241 s
->ns
= gfc_current_ns
;
7245 /* Don't add the symbol multiple times. */
7246 if (gfc_new_block
->binding_label
7247 && (!gfc_notification_std (GFC_STD_F2008
)
7248 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
7250 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
, true);
7253 || (s
->type
!= GSYM_UNKNOWN
7254 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
7256 gfc_global_used (s
, &gfc_new_block
->declared_at
);
7257 /* Silence follow-up errors. */
7258 gfc_new_block
->binding_label
= NULL
;
7262 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
7263 s
->sym_name
= gfc_new_block
->name
;
7264 s
->binding_label
= gfc_new_block
->binding_label
;
7265 s
->where
= gfc_new_block
->declared_at
;
7267 s
->ns
= gfc_current_ns
;
7273 /* Add a program to the global symbol table. */
7276 add_global_program (void)
7280 if (gfc_new_block
== NULL
)
7282 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
7284 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
7285 gfc_global_used (s
, &gfc_new_block
->declared_at
);
7288 s
->type
= GSYM_PROGRAM
;
7289 s
->where
= gfc_new_block
->declared_at
;
7291 s
->ns
= gfc_current_ns
;
7296 /* Resolve all the program units. */
7298 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
7300 gfc_derived_types
= NULL
;
7301 gfc_current_ns
= gfc_global_ns_list
;
7302 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
7304 if (gfc_current_ns
->proc_name
7305 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
7306 continue; /* Already resolved. */
7308 if (gfc_current_ns
->proc_name
)
7309 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
7310 gfc_resolve (gfc_current_ns
);
7311 gfc_current_ns
->derived_types
= gfc_derived_types
;
7312 gfc_derived_types
= NULL
;
7318 clean_up_modules (gfc_gsymbol
*&gsym
)
7323 clean_up_modules (gsym
->left
);
7324 clean_up_modules (gsym
->right
);
7326 if (gsym
->type
!= GSYM_MODULE
)
7331 gfc_current_ns
= gsym
->ns
;
7332 gfc_derived_types
= gfc_current_ns
->derived_types
;
7341 /* Translate all the program units. This could be in a different order
7342 to resolution if there are forward references in the file. */
7344 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
7348 gfc_current_ns
= gfc_global_ns_list
;
7349 gfc_get_errors (NULL
, &errors
);
7351 /* We first translate all modules to make sure that later parts
7352 of the program can use the decl. Then we translate the nonmodules. */
7354 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
7356 if (!gfc_current_ns
->proc_name
7357 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
7360 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
7361 gfc_derived_types
= gfc_current_ns
->derived_types
;
7362 gfc_generate_module_code (gfc_current_ns
);
7363 gfc_current_ns
->translated
= 1;
7366 gfc_current_ns
= gfc_global_ns_list
;
7367 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
7369 if (gfc_current_ns
->proc_name
7370 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
7373 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
7374 gfc_derived_types
= gfc_current_ns
->derived_types
;
7375 gfc_generate_code (gfc_current_ns
);
7376 gfc_current_ns
->translated
= 1;
7379 /* Clean up all the namespaces after translation. */
7380 gfc_current_ns
= gfc_global_ns_list
;
7381 for (;gfc_current_ns
;)
7385 if (gfc_current_ns
->proc_name
7386 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
7388 gfc_current_ns
= gfc_current_ns
->sibling
;
7392 ns
= gfc_current_ns
->sibling
;
7393 gfc_derived_types
= gfc_current_ns
->derived_types
;
7395 gfc_current_ns
= ns
;
7398 clean_up_modules (gfc_gsym_root
);
7402 /* Top level parser. */
7405 gfc_parse_file (void)
7407 int seen_program
, errors_before
, errors
;
7408 gfc_state_data top
, s
;
7411 gfc_namespace
*next
;
7413 gfc_start_source_files ();
7415 top
.state
= COMP_NONE
;
7417 top
.previous
= NULL
;
7418 top
.head
= top
.tail
= NULL
;
7419 top
.do_variable
= NULL
;
7421 gfc_state_stack
= &top
;
7423 gfc_clear_new_st ();
7425 gfc_statement_label
= NULL
;
7427 gfc_omp_metadirective_region_count
= 0;
7428 gfc_in_omp_metadirective_body
= false;
7429 gfc_matching_omp_context_selector
= false;
7431 if (setjmp (eof_buf
))
7432 return false; /* Come here on unexpected EOF */
7434 /* Prepare the global namespace that will contain the
7436 gfc_global_ns_list
= next
= NULL
;
7441 /* Exit early for empty files. */
7445 in_specification_block
= true;
7448 st
= next_statement ();
7457 goto duplicate_main
;
7459 prog_locus
= gfc_current_locus
;
7461 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
7462 main_program_symbol (gfc_current_ns
, gfc_new_block
->name
);
7463 accept_statement (st
);
7464 add_global_program ();
7465 parse_progunit (ST_NONE
);
7469 add_global_procedure (true);
7470 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
7471 accept_statement (st
);
7472 parse_progunit (ST_NONE
);
7476 add_global_procedure (false);
7477 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
7478 accept_statement (st
);
7479 parse_progunit (ST_NONE
);
7483 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
7484 accept_statement (st
);
7485 parse_block_data ();
7489 push_state (&s
, COMP_MODULE
, gfc_new_block
);
7490 accept_statement (st
);
7492 gfc_get_errors (NULL
, &errors_before
);
7497 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
7498 accept_statement (st
);
7500 gfc_get_errors (NULL
, &errors_before
);
7504 /* Anything else starts a nameless main program block. */
7507 goto duplicate_main
;
7509 prog_locus
= gfc_current_locus
;
7511 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
7512 main_program_symbol (gfc_current_ns
, "MAIN__");
7513 parse_progunit (st
);
7517 /* Handle the non-program units. */
7518 gfc_current_ns
->code
= s
.head
;
7520 gfc_resolve (gfc_current_ns
);
7522 /* Fix the implicit_pure attribute for those procedures who should
7524 while (gfc_fix_implicit_pure (gfc_current_ns
))
7527 /* Dump the parse tree if requested. */
7528 if (flag_dump_fortran_original
)
7529 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
7531 gfc_get_errors (NULL
, &errors
);
7532 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
7534 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
7535 gfc_current_ns
->derived_types
= gfc_derived_types
;
7536 gfc_derived_types
= NULL
;
7542 gfc_generate_code (gfc_current_ns
);
7550 /* The main program and non-contained procedures are put
7551 in the global namespace list, so that they can be processed
7552 later and all their interfaces resolved. */
7553 gfc_current_ns
->code
= s
.head
;
7556 for (; next
->sibling
; next
= next
->sibling
)
7558 next
->sibling
= gfc_current_ns
;
7561 gfc_global_ns_list
= gfc_current_ns
;
7563 next
= gfc_current_ns
;
7569 /* Do the resolution. */
7570 resolve_all_program_units (gfc_global_ns_list
);
7572 /* Go through all top-level namespaces and unset the implicit_pure
7573 attribute for any procedures that call something not pure or
7574 implicit_pure. Because the a procedure marked as not implicit_pure
7575 in one sweep may be called by another routine, we repeat this
7576 process until there are no more changes. */
7581 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
7582 gfc_current_ns
= gfc_current_ns
->sibling
)
7584 if (gfc_fix_implicit_pure (gfc_current_ns
))
7590 /* Fixup for external procedures and resolve 'omp requires'. */
7592 bool omp_target_seen
;
7594 omp_target_seen
= false;
7595 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
7596 gfc_current_ns
= gfc_current_ns
->sibling
)
7598 omp_requires
|= gfc_current_ns
->omp_requires
;
7599 omp_target_seen
|= gfc_current_ns
->omp_target_seen
;
7600 gfc_check_externals (gfc_current_ns
);
7602 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
7603 gfc_current_ns
= gfc_current_ns
->sibling
)
7604 gfc_check_omp_requires (gfc_current_ns
, omp_requires
);
7606 /* Populate omp_requires_mask (needed for resolving OpenMP
7607 metadirectives and declare variant). */
7608 switch (omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
7610 case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST
:
7612 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_SEQ_CST
);
7614 case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL
:
7616 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_ACQ_REL
);
7618 case OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE
:
7620 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_ACQUIRE
);
7622 case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED
:
7624 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_RELAXED
);
7626 case OMP_REQ_ATOMIC_MEM_ORDER_RELEASE
:
7628 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_RELEASE
);
7632 if (omp_target_seen
)
7633 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
7634 | OMP_REQUIRES_TARGET_USED
);
7635 if (omp_requires
& OMP_REQ_REVERSE_OFFLOAD
)
7636 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
7637 | OMP_REQUIRES_REVERSE_OFFLOAD
);
7638 if (omp_requires
& OMP_REQ_UNIFIED_ADDRESS
)
7639 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
7640 | OMP_REQUIRES_UNIFIED_ADDRESS
);
7641 if (omp_requires
& OMP_REQ_UNIFIED_SHARED_MEMORY
)
7643 = (enum omp_requires
) (omp_requires_mask
7644 | OMP_REQUIRES_UNIFIED_SHARED_MEMORY
);
7645 if (omp_requires
& OMP_REQ_SELF_MAPS
)
7647 = (enum omp_requires
) (omp_requires_mask
| OMP_REQUIRES_SELF_MAPS
);
7648 if (omp_requires
& OMP_REQ_DYNAMIC_ALLOCATORS
)
7649 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
7650 | OMP_REQUIRES_DYNAMIC_ALLOCATORS
);
7651 /* Do the parse tree dump. */
7652 gfc_current_ns
= flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
7654 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
7655 if (!gfc_current_ns
->proc_name
7656 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
7658 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
7659 fputs ("------------------------------------------\n\n", stdout
);
7662 /* Dump C prototypes. */
7663 if (flag_c_prototypes
|| flag_c_prototypes_external
)
7666 "#include <stddef.h>\n"
7667 "#ifdef __cplusplus\n"
7668 "#include <complex>\n"
7669 "#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n"
7670 "#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n"
7671 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n"
7674 "#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n"
7675 "#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n"
7676 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n"
7680 /* First dump BIND(C) prototypes. */
7681 if (flag_c_prototypes
)
7682 gfc_dump_c_prototypes (stdout
);
7684 /* Dump external prototypes. */
7685 if (flag_c_prototypes_external
)
7686 gfc_dump_external_c_prototypes (stdout
);
7688 if (flag_c_prototypes
|| flag_c_prototypes_external
)
7689 fprintf (stdout
, "\n#ifdef __cplusplus\n}\n#endif\n");
7691 /* Do the translation. */
7692 translate_all_program_units (gfc_global_ns_list
);
7694 /* Dump the global symbol ist. We only do this here because part
7695 of it is generated after mangling the identifiers in
7698 if (flag_dump_fortran_global
)
7699 gfc_dump_global_symbols (stdout
);
7701 gfc_end_source_files ();
7705 /* If we see a duplicate main program, shut down. If the second
7706 instance is an implied main program, i.e. data decls or executable
7707 statements, we're in for lots of errors. */
7708 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
7709 reject_statement ();
7714 /* Return true if this state data represents an OpenACC region. */
7716 is_oacc (gfc_state_data
*sd
)
7718 switch (sd
->construct
->op
)
7720 case EXEC_OACC_PARALLEL_LOOP
:
7721 case EXEC_OACC_PARALLEL
:
7722 case EXEC_OACC_KERNELS_LOOP
:
7723 case EXEC_OACC_KERNELS
:
7724 case EXEC_OACC_SERIAL_LOOP
:
7725 case EXEC_OACC_SERIAL
:
7726 case EXEC_OACC_DATA
:
7727 case EXEC_OACC_HOST_DATA
:
7728 case EXEC_OACC_LOOP
:
7729 case EXEC_OACC_UPDATE
:
7730 case EXEC_OACC_WAIT
:
7731 case EXEC_OACC_CACHE
:
7732 case EXEC_OACC_ENTER_DATA
:
7733 case EXEC_OACC_EXIT_DATA
:
7734 case EXEC_OACC_ATOMIC
:
7735 case EXEC_OACC_ROUTINE
:
7743 /* Return true if ST is a declarative OpenMP statement. */
7745 is_omp_declarative_stmt (gfc_statement st
)