2 Copyright (C) 2000-2022 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 gfc_state_data
*gfc_state_stack
;
41 static bool last_was_use_stmt
= false;
43 /* TODO: Re-order functions to kill these forward decls. */
44 static void check_statement_label (gfc_statement
);
45 static void undo_new_statement (void);
46 static void reject_statement (void);
49 /* A sort of half-matching function. We try to match the word on the
50 input with the passed string. If this succeeds, we call the
51 keyword-dependent matching function that will match the rest of the
52 statement. For single keywords, the matching subroutine is
56 match_word (const char *str
, match (*subr
) (void), locus
*old_locus
)
71 gfc_current_locus
= *old_locus
;
79 /* Like match_word, but if str is matched, set a flag that it
82 match_word_omp_simd (const char *str
, match (*subr
) (void), locus
*old_locus
,
99 gfc_current_locus
= *old_locus
;
107 /* Load symbols from all USE statements encountered in this scoping unit. */
112 gfc_error_buffer old_error
;
114 gfc_push_error (&old_error
);
115 gfc_buffer_error (false);
117 gfc_buffer_error (true);
118 gfc_pop_error (&old_error
);
119 gfc_commit_symbols ();
120 gfc_warning_check ();
121 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
122 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
123 last_was_use_stmt
= false;
127 /* Figure out what the next statement is, (mostly) regardless of
128 proper ordering. The do...while(0) is there to prevent if/else
131 #define match(keyword, subr, st) \
133 if (match_word (keyword, subr, &old_locus) == MATCH_YES) \
136 undo_new_statement (); \
140 /* This is a specialist version of decode_statement that is used
141 for the specification statements in a function, whose
142 characteristics are deferred into the specification statements.
143 eg.: INTEGER (king = mykind) foo ()
144 USE mymodule, ONLY mykind.....
145 The KIND parameter needs a return after USE or IMPORT, whereas
146 derived type declarations can occur anywhere, up the executable
147 block. ST_GET_FCN_CHARACTERISTICS is returned when we have run
148 out of the correct kind of specification statements. */
150 decode_specification_statement (void)
156 if (gfc_match_eos () == MATCH_YES
)
159 old_locus
= gfc_current_locus
;
161 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
163 last_was_use_stmt
= true;
168 undo_new_statement ();
169 if (last_was_use_stmt
)
173 match ("import", gfc_match_import
, ST_IMPORT
);
175 if (gfc_current_block ()->result
->ts
.type
!= BT_DERIVED
)
178 match (NULL
, gfc_match_st_function
, ST_STATEMENT_FUNCTION
);
179 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
180 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
182 /* General statement matching: Instead of testing every possible
183 statement, we eliminate most possibilities by peeking at the
186 c
= gfc_peek_ascii_char ();
191 match ("abstract% interface", gfc_match_abstract_interface
,
193 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
194 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
195 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
199 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
203 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
204 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
208 match ("data", gfc_match_data
, ST_DATA
);
209 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
213 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
214 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
215 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
216 match ("external", gfc_match_external
, ST_ATTR_DECL
);
220 match ("format", gfc_match_format
, ST_FORMAT
);
227 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
228 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
229 match ("interface", gfc_match_interface
, ST_INTERFACE
);
230 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
231 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
238 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
242 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
246 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
247 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
248 if (gfc_match_private (&st
) == MATCH_YES
)
250 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
251 if (gfc_match_public (&st
) == MATCH_YES
)
253 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
260 match ("save", gfc_match_save
, ST_ATTR_DECL
);
261 match ("static", gfc_match_static
, ST_ATTR_DECL
);
262 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
266 match ("target", gfc_match_target
, ST_ATTR_DECL
);
267 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
274 match ("value", gfc_match_value
, ST_ATTR_DECL
);
275 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
282 /* This is not a specification statement. See if any of the matchers
283 has stored an error message of some sort. */
287 gfc_buffer_error (false);
288 gfc_current_locus
= old_locus
;
290 return ST_GET_FCN_CHARACTERISTICS
;
293 static bool in_specification_block
;
295 /* This is the primary 'decode_statement'. */
297 decode_statement (void)
304 gfc_enforce_clean_symbol_state ();
306 gfc_clear_error (); /* Clear any pending errors. */
307 gfc_clear_warning (); /* Clear any pending warnings. */
309 gfc_matching_function
= false;
311 if (gfc_match_eos () == MATCH_YES
)
314 if (gfc_current_state () == COMP_FUNCTION
315 && gfc_current_block ()->result
->ts
.kind
== -1)
316 return decode_specification_statement ();
318 old_locus
= gfc_current_locus
;
320 c
= gfc_peek_ascii_char ();
324 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
326 last_was_use_stmt
= true;
330 undo_new_statement ();
333 if (last_was_use_stmt
)
336 /* Try matching a data declaration or function declaration. The
337 input "REALFUNCTIONA(N)" can mean several things in different
338 contexts, so it (and its relatives) get special treatment. */
340 if (gfc_current_state () == COMP_NONE
341 || gfc_current_state () == COMP_INTERFACE
342 || gfc_current_state () == COMP_CONTAINS
)
344 gfc_matching_function
= true;
345 m
= gfc_match_function_decl ();
348 else if (m
== MATCH_ERROR
)
352 gfc_current_locus
= old_locus
;
354 gfc_matching_function
= false;
356 /* Legacy parameter statements are ambiguous with assignments so try parameter
358 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
360 /* Match statements whose error messages are meant to be overwritten
361 by something better. */
363 match (NULL
, gfc_match_assignment
, ST_ASSIGNMENT
);
364 match (NULL
, gfc_match_pointer_assignment
, ST_POINTER_ASSIGNMENT
);
366 if (in_specification_block
)
368 m
= match_word (NULL
, gfc_match_st_function
, &old_locus
);
370 return ST_STATEMENT_FUNCTION
;
373 if (!(in_specification_block
&& m
== MATCH_ERROR
))
375 match (NULL
, gfc_match_ptr_fcn_assign
, ST_ASSIGNMENT
);
378 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
379 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
381 /* Try to match a subroutine statement, which has the same optional
382 prefixes that functions can have. */
384 if (gfc_match_subroutine () == MATCH_YES
)
385 return ST_SUBROUTINE
;
387 gfc_current_locus
= old_locus
;
389 if (gfc_match_submod_proc () == MATCH_YES
)
391 if (gfc_new_block
->attr
.subroutine
)
392 return ST_SUBROUTINE
;
393 else if (gfc_new_block
->attr
.function
)
397 gfc_current_locus
= old_locus
;
399 /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
400 statements, which might begin with a block label. The match functions for
401 these statements are unusual in that their keyword is not seen before
402 the matcher is called. */
404 if (gfc_match_if (&st
) == MATCH_YES
)
407 gfc_current_locus
= old_locus
;
409 if (gfc_match_where (&st
) == MATCH_YES
)
412 gfc_current_locus
= old_locus
;
414 if (gfc_match_forall (&st
) == MATCH_YES
)
417 gfc_current_locus
= old_locus
;
419 /* Try to match TYPE as an alias for PRINT. */
420 if (gfc_match_type (&st
) == MATCH_YES
)
423 gfc_current_locus
= old_locus
;
425 match (NULL
, gfc_match_do
, ST_DO
);
426 match (NULL
, gfc_match_block
, ST_BLOCK
);
427 match (NULL
, gfc_match_associate
, ST_ASSOCIATE
);
428 match (NULL
, gfc_match_critical
, ST_CRITICAL
);
429 match (NULL
, gfc_match_select
, ST_SELECT_CASE
);
430 match (NULL
, gfc_match_select_type
, ST_SELECT_TYPE
);
431 match (NULL
, gfc_match_select_rank
, ST_SELECT_RANK
);
433 /* General statement matching: Instead of testing every possible
434 statement, we eliminate most possibilities by peeking at the
440 match ("abstract% interface", gfc_match_abstract_interface
,
442 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
);
443 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
444 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
);
445 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
446 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
450 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
);
451 match ("block data", gfc_match_block_data
, ST_BLOCK_DATA
);
452 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
456 match ("call", gfc_match_call
, ST_CALL
);
457 match ("change% team", gfc_match_change_team
, ST_CHANGE_TEAM
);
458 match ("close", gfc_match_close
, ST_CLOSE
);
459 match ("continue", gfc_match_continue
, ST_CONTINUE
);
460 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
461 match ("cycle", gfc_match_cycle
, ST_CYCLE
);
462 match ("case", gfc_match_case
, ST_CASE
);
463 match ("common", gfc_match_common
, ST_COMMON
);
464 match ("contains", gfc_match_eos
, ST_CONTAINS
);
465 match ("class", gfc_match_class_is
, ST_CLASS_IS
);
466 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
470 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
);
471 match ("data", gfc_match_data
, ST_DATA
);
472 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
476 match ("end file", gfc_match_endfile
, ST_END_FILE
);
477 match ("end team", gfc_match_end_team
, ST_END_TEAM
);
478 match ("exit", gfc_match_exit
, ST_EXIT
);
479 match ("else", gfc_match_else
, ST_ELSE
);
480 match ("else where", gfc_match_elsewhere
, ST_ELSEWHERE
);
481 match ("else if", gfc_match_elseif
, ST_ELSEIF
);
482 match ("error% stop", gfc_match_error_stop
, ST_ERROR_STOP
);
483 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
485 if (gfc_match_end (&st
) == MATCH_YES
)
488 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
489 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
490 match ("external", gfc_match_external
, ST_ATTR_DECL
);
491 match ("event% post", gfc_match_event_post
, ST_EVENT_POST
);
492 match ("event% wait", gfc_match_event_wait
, ST_EVENT_WAIT
);
496 match ("fail% image", gfc_match_fail_image
, ST_FAIL_IMAGE
);
497 match ("final", gfc_match_final_decl
, ST_FINAL
);
498 match ("flush", gfc_match_flush
, ST_FLUSH
);
499 match ("form% team", gfc_match_form_team
, ST_FORM_TEAM
);
500 match ("format", gfc_match_format
, ST_FORMAT
);
504 match ("generic", gfc_match_generic
, ST_GENERIC
);
505 match ("go to", gfc_match_goto
, ST_GOTO
);
509 match ("inquire", gfc_match_inquire
, ST_INQUIRE
);
510 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
511 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
512 match ("import", gfc_match_import
, ST_IMPORT
);
513 match ("interface", gfc_match_interface
, ST_INTERFACE
);
514 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
515 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
519 match ("lock", gfc_match_lock
, ST_LOCK
);
523 match ("map", gfc_match_map
, ST_MAP
);
524 match ("module% procedure", gfc_match_modproc
, ST_MODULE_PROC
);
525 match ("module", gfc_match_module
, ST_MODULE
);
529 match ("nullify", gfc_match_nullify
, ST_NULLIFY
);
530 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
534 match ("open", gfc_match_open
, ST_OPEN
);
535 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
539 match ("print", gfc_match_print
, ST_WRITE
);
540 match ("pause", gfc_match_pause
, ST_PAUSE
);
541 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
542 if (gfc_match_private (&st
) == MATCH_YES
)
544 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
545 match ("program", gfc_match_program
, ST_PROGRAM
);
546 if (gfc_match_public (&st
) == MATCH_YES
)
548 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
552 match ("rank", gfc_match_rank_is
, ST_RANK
);
553 match ("read", gfc_match_read
, ST_READ
);
554 match ("return", gfc_match_return
, ST_RETURN
);
555 match ("rewind", gfc_match_rewind
, ST_REWIND
);
559 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
560 match ("sequence", gfc_match_eos
, ST_SEQUENCE
);
561 match ("stop", gfc_match_stop
, ST_STOP
);
562 match ("save", gfc_match_save
, ST_ATTR_DECL
);
563 match ("static", gfc_match_static
, ST_ATTR_DECL
);
564 match ("submodule", gfc_match_submodule
, ST_SUBMODULE
);
565 match ("sync% all", gfc_match_sync_all
, ST_SYNC_ALL
);
566 match ("sync% images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
567 match ("sync% memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
568 match ("sync% team", gfc_match_sync_team
, ST_SYNC_TEAM
);
572 match ("target", gfc_match_target
, ST_ATTR_DECL
);
573 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
574 match ("type% is", gfc_match_type_is
, ST_TYPE_IS
);
578 match ("union", gfc_match_union
, ST_UNION
);
579 match ("unlock", gfc_match_unlock
, ST_UNLOCK
);
583 match ("value", gfc_match_value
, ST_ATTR_DECL
);
584 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
588 match ("wait", gfc_match_wait
, ST_WAIT
);
589 match ("write", gfc_match_write
, ST_WRITE
);
593 /* All else has failed, so give up. See if any of the matchers has
594 stored an error message of some sort. Suppress the "Unclassifiable
595 statement" if a previous error message was emitted, e.g., by
597 if (!gfc_error_check ())
600 gfc_get_errors (NULL
, &ecnt
);
602 gfc_error_now ("Unclassifiable statement at %C");
607 gfc_error_recovery ();
612 /* Like match and if spec_only, goto do_spec_only without actually
614 /* If the directive matched but the clauses failed, do not start
615 matching the next directive in the same switch statement. */
616 #define matcha(keyword, subr, st) \
619 if (spec_only && gfc_match (keyword) == MATCH_YES) \
621 else if ((m2 = match_word (keyword, subr, &old_locus)) \
624 else if (m2 == MATCH_ERROR) \
625 goto error_handling; \
627 undo_new_statement (); \
631 decode_oacc_directive (void)
635 bool spec_only
= false;
637 gfc_enforce_clean_symbol_state ();
639 gfc_clear_error (); /* Clear any pending errors. */
640 gfc_clear_warning (); /* Clear any pending warnings. */
642 gfc_matching_function
= false;
644 if (gfc_current_state () == COMP_FUNCTION
645 && gfc_current_block ()->result
->ts
.kind
== -1)
648 old_locus
= gfc_current_locus
;
650 /* General OpenACC directive matching: Instead of testing every possible
651 statement, we eliminate most possibilities by peeking at the
654 c
= gfc_peek_ascii_char ();
659 matcha ("routine", gfc_match_oacc_routine
, ST_OACC_ROUTINE
);
663 gfc_unset_implicit_pure (NULL
);
666 gfc_error_now ("OpenACC directives other than ROUTINE may not appear in PURE "
674 matcha ("atomic", gfc_match_oacc_atomic
, ST_OACC_ATOMIC
);
677 matcha ("cache", gfc_match_oacc_cache
, ST_OACC_CACHE
);
680 matcha ("data", gfc_match_oacc_data
, ST_OACC_DATA
);
681 match ("declare", gfc_match_oacc_declare
, ST_OACC_DECLARE
);
684 matcha ("end atomic", gfc_match_omp_eos_error
, ST_OACC_END_ATOMIC
);
685 matcha ("end data", gfc_match_omp_eos_error
, ST_OACC_END_DATA
);
686 matcha ("end host_data", gfc_match_omp_eos_error
, ST_OACC_END_HOST_DATA
);
687 matcha ("end kernels loop", gfc_match_omp_eos_error
, ST_OACC_END_KERNELS_LOOP
);
688 matcha ("end kernels", gfc_match_omp_eos_error
, ST_OACC_END_KERNELS
);
689 matcha ("end loop", gfc_match_omp_eos_error
, ST_OACC_END_LOOP
);
690 matcha ("end parallel loop", gfc_match_omp_eos_error
,
691 ST_OACC_END_PARALLEL_LOOP
);
692 matcha ("end parallel", gfc_match_omp_eos_error
, ST_OACC_END_PARALLEL
);
693 matcha ("end serial loop", gfc_match_omp_eos_error
,
694 ST_OACC_END_SERIAL_LOOP
);
695 matcha ("end serial", gfc_match_omp_eos_error
, ST_OACC_END_SERIAL
);
696 matcha ("enter data", gfc_match_oacc_enter_data
, ST_OACC_ENTER_DATA
);
697 matcha ("exit data", gfc_match_oacc_exit_data
, ST_OACC_EXIT_DATA
);
700 matcha ("host_data", gfc_match_oacc_host_data
, ST_OACC_HOST_DATA
);
703 matcha ("parallel loop", gfc_match_oacc_parallel_loop
,
704 ST_OACC_PARALLEL_LOOP
);
705 matcha ("parallel", gfc_match_oacc_parallel
, ST_OACC_PARALLEL
);
708 matcha ("kernels loop", gfc_match_oacc_kernels_loop
,
709 ST_OACC_KERNELS_LOOP
);
710 matcha ("kernels", gfc_match_oacc_kernels
, ST_OACC_KERNELS
);
713 matcha ("loop", gfc_match_oacc_loop
, ST_OACC_LOOP
);
716 matcha ("serial loop", gfc_match_oacc_serial_loop
, ST_OACC_SERIAL_LOOP
);
717 matcha ("serial", gfc_match_oacc_serial
, ST_OACC_SERIAL
);
720 matcha ("update", gfc_match_oacc_update
, ST_OACC_UPDATE
);
723 matcha ("wait", gfc_match_oacc_wait
, ST_OACC_WAIT
);
727 /* Directive not found or stored an error message.
728 Check and give up. */
731 if (gfc_error_check () == 0)
732 gfc_error_now ("Unclassifiable OpenACC directive at %C");
736 gfc_error_recovery ();
743 gfc_buffer_error (false);
744 gfc_current_locus
= old_locus
;
745 return ST_GET_FCN_CHARACTERISTICS
;
748 /* Like match, but set a flag simd_matched if keyword matched
749 and if spec_only, goto do_spec_only without actually matching. */
750 #define matchs(keyword, subr, st) \
753 if (spec_only && gfc_match (keyword) == MATCH_YES) \
755 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
756 &simd_matched)) == MATCH_YES) \
761 else if (m2 == MATCH_ERROR) \
762 goto error_handling; \
764 undo_new_statement (); \
767 /* Like match, but don't match anything if not -fopenmp
768 and if spec_only, goto do_spec_only without actually matching. */
769 /* If the directive matched but the clauses failed, do not start
770 matching the next directive in the same switch statement. */
771 #define matcho(keyword, subr, st) \
776 else if (spec_only && gfc_match (keyword) == MATCH_YES) \
778 else if ((m2 = match_word (keyword, subr, &old_locus)) \
784 else if (m2 == MATCH_ERROR) \
785 goto error_handling; \
787 undo_new_statement (); \
790 /* Like match, but set a flag simd_matched if keyword matched. */
791 #define matchds(keyword, subr, st) \
794 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
795 &simd_matched)) == MATCH_YES) \
800 else if (m2 == MATCH_ERROR) \
801 goto error_handling; \
803 undo_new_statement (); \
806 /* Like match, but don't match anything if not -fopenmp. */
807 #define matchdo(keyword, subr, st) \
812 else if ((m2 = match_word (keyword, subr, &old_locus)) \
818 else if (m2 == MATCH_ERROR) \
819 goto error_handling; \
821 undo_new_statement (); \
825 decode_omp_directive (void)
829 bool simd_matched
= false;
830 bool spec_only
= false;
831 gfc_statement ret
= ST_NONE
;
834 gfc_enforce_clean_symbol_state ();
836 gfc_clear_error (); /* Clear any pending errors. */
837 gfc_clear_warning (); /* Clear any pending warnings. */
839 gfc_matching_function
= false;
841 if (gfc_current_state () == COMP_FUNCTION
842 && gfc_current_block ()->result
->ts
.kind
== -1)
845 old_locus
= gfc_current_locus
;
847 /* General OpenMP directive matching: Instead of testing every possible
848 statement, we eliminate most possibilities by peeking at the
851 c
= gfc_peek_ascii_char ();
853 /* match is for directives that should be recognized only if
854 -fopenmp, matchs for directives that should be recognized
855 if either -fopenmp or -fopenmp-simd.
856 Handle only the directives allowed in PURE procedures
857 first (those also shall not turn off implicit pure). */
861 matchds ("declare simd", gfc_match_omp_declare_simd
,
862 ST_OMP_DECLARE_SIMD
);
863 matchdo ("declare target", gfc_match_omp_declare_target
,
864 ST_OMP_DECLARE_TARGET
);
865 matchdo ("declare variant", gfc_match_omp_declare_variant
,
866 ST_OMP_DECLARE_VARIANT
);
869 matchs ("simd", gfc_match_omp_simd
, ST_OMP_SIMD
);
874 if (flag_openmp
&& gfc_pure (NULL
))
876 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
877 "at %C may not appear in PURE procedures");
878 gfc_error_recovery ();
882 /* match is for directives that should be recognized only if
883 -fopenmp, matchs for directives that should be recognized
884 if either -fopenmp or -fopenmp-simd. */
888 matcho ("atomic", gfc_match_omp_atomic
, ST_OMP_ATOMIC
);
891 matcho ("barrier", gfc_match_omp_barrier
, ST_OMP_BARRIER
);
894 matcho ("cancellation% point", gfc_match_omp_cancellation_point
,
895 ST_OMP_CANCELLATION_POINT
);
896 matcho ("cancel", gfc_match_omp_cancel
, ST_OMP_CANCEL
);
897 matcho ("critical", gfc_match_omp_critical
, ST_OMP_CRITICAL
);
900 matchds ("declare reduction", gfc_match_omp_declare_reduction
,
901 ST_OMP_DECLARE_REDUCTION
);
902 matcho ("depobj", gfc_match_omp_depobj
, ST_OMP_DEPOBJ
);
903 matchs ("distribute parallel do simd",
904 gfc_match_omp_distribute_parallel_do_simd
,
905 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
);
906 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do
,
907 ST_OMP_DISTRIBUTE_PARALLEL_DO
);
908 matchs ("distribute simd", gfc_match_omp_distribute_simd
,
909 ST_OMP_DISTRIBUTE_SIMD
);
910 matcho ("distribute", gfc_match_omp_distribute
, ST_OMP_DISTRIBUTE
);
911 matchs ("do simd", gfc_match_omp_do_simd
, ST_OMP_DO_SIMD
);
912 matcho ("do", gfc_match_omp_do
, ST_OMP_DO
);
915 matcho ("error", gfc_match_omp_error
, ST_OMP_ERROR
);
916 matcho ("end atomic", gfc_match_omp_eos_error
, ST_OMP_END_ATOMIC
);
917 matcho ("end critical", gfc_match_omp_end_critical
, ST_OMP_END_CRITICAL
);
918 matchs ("end distribute parallel do simd", gfc_match_omp_eos_error
,
919 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
);
920 matcho ("end distribute parallel do", gfc_match_omp_eos_error
,
921 ST_OMP_END_DISTRIBUTE_PARALLEL_DO
);
922 matchs ("end distribute simd", gfc_match_omp_eos_error
,
923 ST_OMP_END_DISTRIBUTE_SIMD
);
924 matcho ("end distribute", gfc_match_omp_eos_error
, ST_OMP_END_DISTRIBUTE
);
925 matchs ("end do simd", gfc_match_omp_end_nowait
, ST_OMP_END_DO_SIMD
);
926 matcho ("end do", gfc_match_omp_end_nowait
, ST_OMP_END_DO
);
927 matcho ("end loop", gfc_match_omp_eos_error
, ST_OMP_END_LOOP
);
928 matchs ("end simd", gfc_match_omp_eos_error
, ST_OMP_END_SIMD
);
929 matcho ("end masked taskloop simd", gfc_match_omp_eos_error
,
930 ST_OMP_END_MASKED_TASKLOOP_SIMD
);
931 matcho ("end masked taskloop", gfc_match_omp_eos_error
,
932 ST_OMP_END_MASKED_TASKLOOP
);
933 matcho ("end masked", gfc_match_omp_eos_error
, ST_OMP_END_MASKED
);
934 matcho ("end master taskloop simd", gfc_match_omp_eos_error
,
935 ST_OMP_END_MASTER_TASKLOOP_SIMD
);
936 matcho ("end master taskloop", gfc_match_omp_eos_error
,
937 ST_OMP_END_MASTER_TASKLOOP
);
938 matcho ("end master", gfc_match_omp_eos_error
, ST_OMP_END_MASTER
);
939 matchs ("end ordered", gfc_match_omp_eos_error
, ST_OMP_END_ORDERED
);
940 matchs ("end parallel do simd", gfc_match_omp_eos_error
,
941 ST_OMP_END_PARALLEL_DO_SIMD
);
942 matcho ("end parallel do", gfc_match_omp_eos_error
, ST_OMP_END_PARALLEL_DO
);
943 matcho ("end parallel loop", gfc_match_omp_eos_error
,
944 ST_OMP_END_PARALLEL_LOOP
);
945 matcho ("end parallel masked taskloop simd", gfc_match_omp_eos_error
,
946 ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
);
947 matcho ("end parallel masked taskloop", gfc_match_omp_eos_error
,
948 ST_OMP_END_PARALLEL_MASKED_TASKLOOP
);
949 matcho ("end parallel masked", gfc_match_omp_eos_error
,
950 ST_OMP_END_PARALLEL_MASKED
);
951 matcho ("end parallel master taskloop simd", gfc_match_omp_eos_error
,
952 ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
);
953 matcho ("end parallel master taskloop", gfc_match_omp_eos_error
,
954 ST_OMP_END_PARALLEL_MASTER_TASKLOOP
);
955 matcho ("end parallel master", gfc_match_omp_eos_error
,
956 ST_OMP_END_PARALLEL_MASTER
);
957 matcho ("end parallel sections", gfc_match_omp_eos_error
,
958 ST_OMP_END_PARALLEL_SECTIONS
);
959 matcho ("end parallel workshare", gfc_match_omp_eos_error
,
960 ST_OMP_END_PARALLEL_WORKSHARE
);
961 matcho ("end parallel", gfc_match_omp_eos_error
, ST_OMP_END_PARALLEL
);
962 matcho ("end scope", gfc_match_omp_end_nowait
, ST_OMP_END_SCOPE
);
963 matcho ("end sections", gfc_match_omp_end_nowait
, ST_OMP_END_SECTIONS
);
964 matcho ("end single", gfc_match_omp_end_single
, ST_OMP_END_SINGLE
);
965 matcho ("end target data", gfc_match_omp_eos_error
, ST_OMP_END_TARGET_DATA
);
966 matchs ("end target parallel do simd", gfc_match_omp_end_nowait
,
967 ST_OMP_END_TARGET_PARALLEL_DO_SIMD
);
968 matcho ("end target parallel do", gfc_match_omp_end_nowait
,
969 ST_OMP_END_TARGET_PARALLEL_DO
);
970 matcho ("end target parallel loop", gfc_match_omp_end_nowait
,
971 ST_OMP_END_TARGET_PARALLEL_LOOP
);
972 matcho ("end target parallel", gfc_match_omp_end_nowait
,
973 ST_OMP_END_TARGET_PARALLEL
);
974 matchs ("end target simd", gfc_match_omp_end_nowait
, ST_OMP_END_TARGET_SIMD
);
975 matchs ("end target teams distribute parallel do simd",
976 gfc_match_omp_end_nowait
,
977 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
978 matcho ("end target teams distribute parallel do", gfc_match_omp_end_nowait
,
979 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
980 matchs ("end target teams distribute simd", gfc_match_omp_end_nowait
,
981 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
);
982 matcho ("end target teams distribute", gfc_match_omp_end_nowait
,
983 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
);
984 matcho ("end target teams loop", gfc_match_omp_end_nowait
,
985 ST_OMP_END_TARGET_TEAMS_LOOP
);
986 matcho ("end target teams", gfc_match_omp_end_nowait
,
987 ST_OMP_END_TARGET_TEAMS
);
988 matcho ("end target", gfc_match_omp_end_nowait
, ST_OMP_END_TARGET
);
989 matcho ("end taskgroup", gfc_match_omp_eos_error
, ST_OMP_END_TASKGROUP
);
990 matchs ("end taskloop simd", gfc_match_omp_eos_error
,
991 ST_OMP_END_TASKLOOP_SIMD
);
992 matcho ("end taskloop", gfc_match_omp_eos_error
, ST_OMP_END_TASKLOOP
);
993 matcho ("end task", gfc_match_omp_eos_error
, ST_OMP_END_TASK
);
994 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos_error
,
995 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
996 matcho ("end teams distribute parallel do", gfc_match_omp_eos_error
,
997 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
);
998 matchs ("end teams distribute simd", gfc_match_omp_eos_error
,
999 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
);
1000 matcho ("end teams distribute", gfc_match_omp_eos_error
,
1001 ST_OMP_END_TEAMS_DISTRIBUTE
);
1002 matcho ("end teams loop", gfc_match_omp_eos_error
, ST_OMP_END_TEAMS_LOOP
);
1003 matcho ("end teams", gfc_match_omp_eos_error
, ST_OMP_END_TEAMS
);
1004 matcho ("end workshare", gfc_match_omp_end_nowait
,
1005 ST_OMP_END_WORKSHARE
);
1008 matcho ("flush", gfc_match_omp_flush
, ST_OMP_FLUSH
);
1011 matcho ("masked taskloop simd", gfc_match_omp_masked_taskloop_simd
,
1012 ST_OMP_MASKED_TASKLOOP_SIMD
);
1013 matcho ("masked taskloop", gfc_match_omp_masked_taskloop
,
1014 ST_OMP_MASKED_TASKLOOP
);
1015 matcho ("masked", gfc_match_omp_masked
, ST_OMP_MASKED
);
1016 matcho ("master taskloop simd", gfc_match_omp_master_taskloop_simd
,
1017 ST_OMP_MASTER_TASKLOOP_SIMD
);
1018 matcho ("master taskloop", gfc_match_omp_master_taskloop
,
1019 ST_OMP_MASTER_TASKLOOP
);
1020 matcho ("master", gfc_match_omp_master
, ST_OMP_MASTER
);
1023 matcho ("nothing", gfc_match_omp_nothing
, ST_NONE
);
1026 matcho ("loop", gfc_match_omp_loop
, ST_OMP_LOOP
);
1029 if (gfc_match ("ordered depend (") == MATCH_YES
)
1031 gfc_current_locus
= old_locus
;
1034 matcho ("ordered", gfc_match_omp_ordered_depend
,
1035 ST_OMP_ORDERED_DEPEND
);
1038 matchs ("ordered", gfc_match_omp_ordered
, ST_OMP_ORDERED
);
1041 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd
,
1042 ST_OMP_PARALLEL_DO_SIMD
);
1043 matcho ("parallel do", gfc_match_omp_parallel_do
, ST_OMP_PARALLEL_DO
);
1044 matcho ("parallel loop", gfc_match_omp_parallel_loop
,
1045 ST_OMP_PARALLEL_LOOP
);
1046 matcho ("parallel masked taskloop simd",
1047 gfc_match_omp_parallel_masked_taskloop_simd
,
1048 ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
);
1049 matcho ("parallel masked taskloop",
1050 gfc_match_omp_parallel_masked_taskloop
,
1051 ST_OMP_PARALLEL_MASKED_TASKLOOP
);
1052 matcho ("parallel masked", gfc_match_omp_parallel_masked
,
1053 ST_OMP_PARALLEL_MASKED
);
1054 matcho ("parallel master taskloop simd",
1055 gfc_match_omp_parallel_master_taskloop_simd
,
1056 ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
);
1057 matcho ("parallel master taskloop",
1058 gfc_match_omp_parallel_master_taskloop
,
1059 ST_OMP_PARALLEL_MASTER_TASKLOOP
);
1060 matcho ("parallel master", gfc_match_omp_parallel_master
,
1061 ST_OMP_PARALLEL_MASTER
);
1062 matcho ("parallel sections", gfc_match_omp_parallel_sections
,
1063 ST_OMP_PARALLEL_SECTIONS
);
1064 matcho ("parallel workshare", gfc_match_omp_parallel_workshare
,
1065 ST_OMP_PARALLEL_WORKSHARE
);
1066 matcho ("parallel", gfc_match_omp_parallel
, ST_OMP_PARALLEL
);
1069 matcho ("requires", gfc_match_omp_requires
, ST_OMP_REQUIRES
);
1072 matcho ("scan", gfc_match_omp_scan
, ST_OMP_SCAN
);
1073 matcho ("scope", gfc_match_omp_scope
, ST_OMP_SCOPE
);
1074 matcho ("sections", gfc_match_omp_sections
, ST_OMP_SECTIONS
);
1075 matcho ("section", gfc_match_omp_eos_error
, ST_OMP_SECTION
);
1076 matcho ("single", gfc_match_omp_single
, ST_OMP_SINGLE
);
1079 matcho ("target data", gfc_match_omp_target_data
, ST_OMP_TARGET_DATA
);
1080 matcho ("target enter data", gfc_match_omp_target_enter_data
,
1081 ST_OMP_TARGET_ENTER_DATA
);
1082 matcho ("target exit data", gfc_match_omp_target_exit_data
,
1083 ST_OMP_TARGET_EXIT_DATA
);
1084 matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd
,
1085 ST_OMP_TARGET_PARALLEL_DO_SIMD
);
1086 matcho ("target parallel do", gfc_match_omp_target_parallel_do
,
1087 ST_OMP_TARGET_PARALLEL_DO
);
1088 matcho ("target parallel loop", gfc_match_omp_target_parallel_loop
,
1089 ST_OMP_TARGET_PARALLEL_LOOP
);
1090 matcho ("target parallel", gfc_match_omp_target_parallel
,
1091 ST_OMP_TARGET_PARALLEL
);
1092 matchs ("target simd", gfc_match_omp_target_simd
, ST_OMP_TARGET_SIMD
);
1093 matchs ("target teams distribute parallel do simd",
1094 gfc_match_omp_target_teams_distribute_parallel_do_simd
,
1095 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1096 matcho ("target teams distribute parallel do",
1097 gfc_match_omp_target_teams_distribute_parallel_do
,
1098 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1099 matchs ("target teams distribute simd",
1100 gfc_match_omp_target_teams_distribute_simd
,
1101 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
);
1102 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute
,
1103 ST_OMP_TARGET_TEAMS_DISTRIBUTE
);
1104 matcho ("target teams loop", gfc_match_omp_target_teams_loop
,
1105 ST_OMP_TARGET_TEAMS_LOOP
);
1106 matcho ("target teams", gfc_match_omp_target_teams
, ST_OMP_TARGET_TEAMS
);
1107 matcho ("target update", gfc_match_omp_target_update
,
1108 ST_OMP_TARGET_UPDATE
);
1109 matcho ("target", gfc_match_omp_target
, ST_OMP_TARGET
);
1110 matcho ("taskgroup", gfc_match_omp_taskgroup
, ST_OMP_TASKGROUP
);
1111 matchs ("taskloop simd", gfc_match_omp_taskloop_simd
,
1112 ST_OMP_TASKLOOP_SIMD
);
1113 matcho ("taskloop", gfc_match_omp_taskloop
, ST_OMP_TASKLOOP
);
1114 matcho ("taskwait", gfc_match_omp_taskwait
, ST_OMP_TASKWAIT
);
1115 matcho ("taskyield", gfc_match_omp_taskyield
, ST_OMP_TASKYIELD
);
1116 matcho ("task", gfc_match_omp_task
, ST_OMP_TASK
);
1117 matchs ("teams distribute parallel do simd",
1118 gfc_match_omp_teams_distribute_parallel_do_simd
,
1119 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1120 matcho ("teams distribute parallel do",
1121 gfc_match_omp_teams_distribute_parallel_do
,
1122 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1123 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd
,
1124 ST_OMP_TEAMS_DISTRIBUTE_SIMD
);
1125 matcho ("teams distribute", gfc_match_omp_teams_distribute
,
1126 ST_OMP_TEAMS_DISTRIBUTE
);
1127 matcho ("teams loop", gfc_match_omp_teams_loop
, ST_OMP_TEAMS_LOOP
);
1128 matcho ("teams", gfc_match_omp_teams
, ST_OMP_TEAMS
);
1129 matchdo ("threadprivate", gfc_match_omp_threadprivate
,
1130 ST_OMP_THREADPRIVATE
);
1133 matcho ("workshare", gfc_match_omp_workshare
, ST_OMP_WORKSHARE
);
1137 /* All else has failed, so give up. See if any of the matchers has
1138 stored an error message of some sort. Don't error out if
1139 not -fopenmp and simd_matched is false, i.e. if a directive other
1140 than one marked with match has been seen. */
1143 if (flag_openmp
|| simd_matched
)
1145 if (!gfc_error_check ())
1146 gfc_error_now ("Unclassifiable OpenMP directive at %C");
1149 reject_statement ();
1151 gfc_error_recovery ();
1158 gfc_unset_implicit_pure (NULL
);
1160 if (!flag_openmp
&& gfc_pure (NULL
))
1162 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
1163 "at %C may not appear in PURE procedures");
1164 reject_statement ();
1165 gfc_error_recovery ();
1171 /* Set omp_target_seen; exclude ST_OMP_DECLARE_TARGET.
1172 FIXME: Get clarification, cf. OpenMP Spec Issue #3240. */
1174 case ST_OMP_TARGET_DATA
:
1175 case ST_OMP_TARGET_ENTER_DATA
:
1176 case ST_OMP_TARGET_EXIT_DATA
:
1177 case ST_OMP_TARGET_TEAMS
:
1178 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
1179 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
1180 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
1181 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
1182 case ST_OMP_TARGET_TEAMS_LOOP
:
1183 case ST_OMP_TARGET_PARALLEL
:
1184 case ST_OMP_TARGET_PARALLEL_DO
:
1185 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
1186 case ST_OMP_TARGET_PARALLEL_LOOP
:
1187 case ST_OMP_TARGET_SIMD
:
1188 case ST_OMP_TARGET_UPDATE
:
1190 gfc_namespace
*prog_unit
= gfc_current_ns
;
1191 while (prog_unit
->parent
)
1193 if (gfc_state_stack
->previous
1194 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
1196 prog_unit
= prog_unit
->parent
;
1198 prog_unit
->omp_target_seen
= true;
1202 if (new_st
.ext
.omp_clauses
->at
!= OMP_AT_EXECUTION
)
1210 reject_statement ();
1212 gfc_buffer_error (false);
1213 gfc_current_locus
= old_locus
;
1214 return ST_GET_FCN_CHARACTERISTICS
;
1217 static gfc_statement
1218 decode_gcc_attribute (void)
1222 gfc_enforce_clean_symbol_state ();
1224 gfc_clear_error (); /* Clear any pending errors. */
1225 gfc_clear_warning (); /* Clear any pending warnings. */
1226 old_locus
= gfc_current_locus
;
1228 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
1229 match ("unroll", gfc_match_gcc_unroll
, ST_NONE
);
1230 match ("builtin", gfc_match_gcc_builtin
, ST_NONE
);
1231 match ("ivdep", gfc_match_gcc_ivdep
, ST_NONE
);
1232 match ("vector", gfc_match_gcc_vector
, ST_NONE
);
1233 match ("novector", gfc_match_gcc_novector
, ST_NONE
);
1235 /* All else has failed, so give up. See if any of the matchers has
1236 stored an error message of some sort. */
1238 if (!gfc_error_check ())
1241 gfc_error_now ("Unclassifiable GCC directive at %C");
1243 gfc_warning_now (0, "Unclassifiable GCC directive at %C, ignored");
1246 reject_statement ();
1248 gfc_error_recovery ();
1255 /* Assert next length characters to be equal to token in free form. */
1258 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
1263 c
= gfc_next_ascii_char ();
1264 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
1265 gcc_assert (c
== token
[i
]);
1267 gcc_assert (gfc_is_whitespace(c
));
1268 gfc_gobble_whitespace ();
1269 if (last_was_use_stmt
)
1273 /* Get the next statement in free form source. */
1275 static gfc_statement
1282 at_bol
= gfc_at_bol ();
1283 gfc_gobble_whitespace ();
1285 c
= gfc_peek_ascii_char ();
1291 /* Found a statement label? */
1292 m
= gfc_match_st_label (&gfc_statement_label
);
1294 d
= gfc_peek_ascii_char ();
1295 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
1297 gfc_match_small_literal_int (&i
, &cnt
);
1300 gfc_error_now ("Too many digits in statement label at %C");
1303 gfc_error_now ("Zero is not a valid statement label at %C");
1306 c
= gfc_next_ascii_char ();
1309 if (!gfc_is_whitespace (c
))
1310 gfc_error_now ("Non-numeric character in statement label at %C");
1316 label_locus
= gfc_current_locus
;
1318 gfc_gobble_whitespace ();
1320 if (at_bol
&& gfc_peek_ascii_char () == ';')
1322 gfc_error_now ("Semicolon at %C needs to be preceded by "
1324 gfc_next_ascii_char (); /* Eat up the semicolon. */
1328 if (gfc_match_eos () == MATCH_YES
)
1329 gfc_error_now ("Statement label without statement at %L",
1335 /* Comments have already been skipped by the time we get here,
1336 except for GCC attributes and OpenMP/OpenACC directives. */
1338 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1339 c
= gfc_peek_ascii_char ();
1345 c
= gfc_next_ascii_char ();
1346 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1347 gcc_assert (c
== "gcc$"[i
]);
1349 gfc_gobble_whitespace ();
1350 return decode_gcc_attribute ();
1355 /* Since both OpenMP and OpenACC directives starts with
1356 !$ character sequence, we must check all flags combinations */
1357 if ((flag_openmp
|| flag_openmp_simd
)
1360 verify_token_free ("$omp", 4, last_was_use_stmt
);
1361 return decode_omp_directive ();
1363 else if ((flag_openmp
|| flag_openmp_simd
)
1366 gfc_next_ascii_char (); /* Eat up dollar character */
1367 c
= gfc_peek_ascii_char ();
1371 verify_token_free ("omp", 3, last_was_use_stmt
);
1372 return decode_omp_directive ();
1376 verify_token_free ("acc", 3, last_was_use_stmt
);
1377 return decode_oacc_directive ();
1380 else if (flag_openacc
)
1382 verify_token_free ("$acc", 4, last_was_use_stmt
);
1383 return decode_oacc_directive ();
1389 if (at_bol
&& c
== ';')
1391 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1392 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1394 gfc_next_ascii_char (); /* Eat up the semicolon. */
1398 return decode_statement ();
1401 /* Assert next length characters to be equal to token in fixed form. */
1404 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1407 char c
= gfc_next_char_literal (NONSTRING
);
1409 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1410 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1412 if (c
!= ' ' && c
!= '0')
1414 gfc_buffer_error (false);
1415 gfc_error ("Bad continuation line at %C");
1418 if (last_was_use_stmt
)
1424 /* Get the next statement in fixed-form source. */
1426 static gfc_statement
1429 int label
, digit_flag
, i
;
1434 return decode_statement ();
1436 /* Skip past the current label field, parsing a statement label if
1437 one is there. This is a weird number parser, since the number is
1438 contained within five columns and can have any kind of embedded
1439 spaces. We also check for characters that make the rest of the
1445 for (i
= 0; i
< 5; i
++)
1447 c
= gfc_next_char_literal (NONSTRING
);
1464 label
= label
* 10 + ((unsigned char) c
- '0');
1465 label_locus
= gfc_current_locus
;
1469 /* Comments have already been skipped by the time we get
1470 here, except for GCC attributes and OpenMP directives. */
1473 c
= gfc_next_char_literal (NONSTRING
);
1475 if (TOLOWER (c
) == 'g')
1477 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1478 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1480 return decode_gcc_attribute ();
1484 if ((flag_openmp
|| flag_openmp_simd
)
1487 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1489 return decode_omp_directive ();
1491 else if ((flag_openmp
|| flag_openmp_simd
)
1494 c
= gfc_next_char_literal(NONSTRING
);
1495 if (c
== 'o' || c
== 'O')
1497 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1499 return decode_omp_directive ();
1501 else if (c
== 'a' || c
== 'A')
1503 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1505 return decode_oacc_directive ();
1508 else if (flag_openacc
)
1510 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1512 return decode_oacc_directive ();
1517 /* Comments have already been skipped by the time we get
1518 here so don't bother checking for them. */
1521 gfc_buffer_error (false);
1522 gfc_error ("Non-numeric character in statement label at %C");
1530 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1533 /* We've found a valid statement label. */
1534 gfc_statement_label
= gfc_get_st_label (label
);
1538 /* Since this line starts a statement, it cannot be a continuation
1539 of a previous statement. If we see something here besides a
1540 space or zero, it must be a bad continuation line. */
1542 c
= gfc_next_char_literal (NONSTRING
);
1546 if (c
!= ' ' && c
!= '0')
1548 gfc_buffer_error (false);
1549 gfc_error ("Bad continuation line at %C");
1553 /* Now that we've taken care of the statement label columns, we have
1554 to make sure that the first nonblank character is not a '!'. If
1555 it is, the rest of the line is a comment. */
1559 loc
= gfc_current_locus
;
1560 c
= gfc_next_char_literal (NONSTRING
);
1562 while (gfc_is_whitespace (c
));
1566 gfc_current_locus
= loc
;
1571 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1572 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1573 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1578 if (gfc_match_eos () == MATCH_YES
)
1581 /* At this point, we've got a nonblank statement to parse. */
1582 return decode_statement ();
1586 gfc_error_now ("Statement label without statement at %L", &label_locus
);
1588 gfc_current_locus
.lb
->truncated
= 0;
1589 gfc_advance_line ();
1594 /* Return the next non-ST_NONE statement to the caller. We also worry
1595 about including files and the ends of include files at this stage. */
1597 static gfc_statement
1598 next_statement (void)
1603 gfc_enforce_clean_symbol_state ();
1605 gfc_new_block
= NULL
;
1607 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1608 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1611 gfc_statement_label
= NULL
;
1612 gfc_buffer_error (true);
1615 gfc_advance_line ();
1617 gfc_skip_comments ();
1625 if (gfc_define_undef_line ())
1628 old_locus
= gfc_current_locus
;
1630 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1636 gfc_buffer_error (false);
1638 if (st
== ST_GET_FCN_CHARACTERISTICS
)
1640 if (gfc_statement_label
!= NULL
)
1642 gfc_free_st_label (gfc_statement_label
);
1643 gfc_statement_label
= NULL
;
1645 gfc_current_locus
= old_locus
;
1649 check_statement_label (st
);
1655 /****************************** Parser ***********************************/
1657 /* The parser subroutines are of type 'try' that fail if the file ends
1660 /* Macros that expand to case-labels for various classes of
1661 statements. Start with executable statements that directly do
1664 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1665 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1666 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1667 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1668 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1669 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1670 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1671 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1672 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1673 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: case ST_OMP_DEPOBJ: \
1674 case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
1675 case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: case ST_OMP_ERROR: \
1676 case ST_ERROR_STOP: case ST_OMP_SCAN: case ST_SYNC_ALL: \
1677 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1678 case ST_FORM_TEAM: case ST_CHANGE_TEAM: \
1679 case ST_END_TEAM: case ST_SYNC_TEAM: \
1680 case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \
1681 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1682 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1684 /* Statements that mark other executable statements. */
1686 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1687 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1688 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1689 case ST_SELECT_RANK: case ST_OMP_PARALLEL: case ST_OMP_PARALLEL_MASKED: \
1690 case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
1691 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case ST_OMP_PARALLEL_MASTER: \
1692 case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
1693 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
1694 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1695 case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASKED_TASKLOOP: \
1696 case ST_OMP_MASKED_TASKLOOP_SIMD: \
1697 case ST_OMP_MASTER: case ST_OMP_MASTER_TASKLOOP: \
1698 case ST_OMP_MASTER_TASKLOOP_SIMD: case ST_OMP_SCOPE: case ST_OMP_SINGLE: \
1699 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1700 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1701 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1702 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1703 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1704 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1705 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1706 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1707 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1708 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1709 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1710 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1711 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1712 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1713 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
1714 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
1715 case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
1716 case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \
1717 case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \
1719 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1720 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1721 case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \
1724 /* Declaration statements */
1726 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1727 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1728 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE
1730 /* OpenMP and OpenACC declaration statements, which may appear anywhere in
1731 the specification part. */
1733 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1734 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \
1735 case ST_OMP_DECLARE_VARIANT: \
1736 case ST_OMP_REQUIRES: case ST_OACC_ROUTINE: case ST_OACC_DECLARE
1738 /* Block end statements. Errors associated with interchanging these
1739 are detected in gfc_match_end(). */
1741 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1742 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1743 case ST_END_BLOCK: case ST_END_ASSOCIATE
1746 /* Push a new state onto the stack. */
1749 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
1751 p
->state
= new_state
;
1752 p
->previous
= gfc_state_stack
;
1754 p
->head
= p
->tail
= NULL
;
1755 p
->do_variable
= NULL
;
1756 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
1757 p
->ext
.oacc_declare_clauses
= NULL
;
1759 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1760 construct statement was accepted right before pushing the state. Thus,
1761 the construct's gfc_code is available as tail of the parent state. */
1762 gcc_assert (gfc_state_stack
);
1763 p
->construct
= gfc_state_stack
->tail
;
1765 gfc_state_stack
= p
;
1769 /* Pop the current state. */
1773 gfc_state_stack
= gfc_state_stack
->previous
;
1777 /* Try to find the given state in the state stack. */
1780 gfc_find_state (gfc_compile_state state
)
1784 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1785 if (p
->state
== state
)
1788 return (p
== NULL
) ? false : true;
1792 /* Starts a new level in the statement list. */
1795 new_level (gfc_code
*q
)
1799 p
= q
->block
= gfc_get_code (EXEC_NOP
);
1801 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
1807 /* Add the current new_st code structure and adds it to the current
1808 program unit. As a side-effect, it zeroes the new_st. */
1811 add_statement (void)
1815 p
= XCNEW (gfc_code
);
1818 p
->loc
= gfc_current_locus
;
1820 if (gfc_state_stack
->head
== NULL
)
1821 gfc_state_stack
->head
= p
;
1823 gfc_state_stack
->tail
->next
= p
;
1825 while (p
->next
!= NULL
)
1828 gfc_state_stack
->tail
= p
;
1830 gfc_clear_new_st ();
1836 /* Frees everything associated with the current statement. */
1839 undo_new_statement (void)
1841 gfc_free_statements (new_st
.block
);
1842 gfc_free_statements (new_st
.next
);
1843 gfc_free_statement (&new_st
);
1844 gfc_clear_new_st ();
1848 /* If the current statement has a statement label, make sure that it
1849 is allowed to, or should have one. */
1852 check_statement_label (gfc_statement st
)
1856 if (gfc_statement_label
== NULL
)
1858 if (st
== ST_FORMAT
)
1859 gfc_error ("FORMAT statement at %L does not have a statement label",
1866 case ST_END_PROGRAM
:
1867 case ST_END_FUNCTION
:
1868 case ST_END_SUBROUTINE
:
1872 case ST_END_CRITICAL
:
1874 case ST_END_ASSOCIATE
:
1877 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
1878 type
= ST_LABEL_DO_TARGET
;
1880 type
= ST_LABEL_TARGET
;
1884 type
= ST_LABEL_FORMAT
;
1887 /* Statement labels are not restricted from appearing on a
1888 particular line. However, there are plenty of situations
1889 where the resulting label can't be referenced. */
1892 type
= ST_LABEL_BAD_TARGET
;
1896 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
1898 new_st
.here
= gfc_statement_label
;
1902 /* Figures out what the enclosing program unit is. This will be a
1903 function, subroutine, program, block data or module. */
1906 gfc_enclosing_unit (gfc_compile_state
* result
)
1910 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1911 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
1912 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
1913 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
1922 *result
= COMP_PROGRAM
;
1927 /* Translate a statement enum to a string. */
1930 gfc_ascii_statement (gfc_statement st
)
1936 case ST_ARITHMETIC_IF
:
1937 p
= _("arithmetic IF");
1946 p
= _("attribute declaration");
1982 p
= _("data declaration");
1996 case ST_STRUCTURE_DECL
:
1999 case ST_DERIVED_DECL
:
2000 p
= _("derived type declaration");
2023 case ST_CHANGE_TEAM
:
2035 case ST_END_ASSOCIATE
:
2036 p
= "END ASSOCIATE";
2041 case ST_END_BLOCK_DATA
:
2042 p
= "END BLOCK DATA";
2044 case ST_END_CRITICAL
:
2056 case ST_END_FUNCTION
:
2062 case ST_END_INTERFACE
:
2063 p
= "END INTERFACE";
2068 case ST_END_SUBMODULE
:
2069 p
= "END SUBMODULE";
2071 case ST_END_PROGRAM
:
2077 case ST_END_SUBROUTINE
:
2078 p
= "END SUBROUTINE";
2083 case ST_END_STRUCTURE
:
2084 p
= "END STRUCTURE";
2098 case ST_EQUIVALENCE
:
2110 case ST_FORALL_BLOCK
: /* Fall through */
2132 case ST_IMPLICIT_NONE
:
2133 p
= "IMPLICIT NONE";
2135 case ST_IMPLIED_ENDDO
:
2136 p
= _("implied END DO");
2168 case ST_MODULE_PROC
:
2169 p
= "MODULE PROCEDURE";
2201 case ST_SYNC_IMAGES
:
2204 case ST_SYNC_MEMORY
:
2219 case ST_WHERE_BLOCK
: /* Fall through */
2230 p
= _("assignment");
2232 case ST_POINTER_ASSIGNMENT
:
2233 p
= _("pointer assignment");
2235 case ST_SELECT_CASE
:
2238 case ST_SELECT_TYPE
:
2241 case ST_SELECT_RANK
:
2259 case ST_STATEMENT_FUNCTION
:
2260 p
= "STATEMENT FUNCTION";
2262 case ST_LABEL_ASSIGNMENT
:
2263 p
= "LABEL ASSIGNMENT";
2266 p
= "ENUM DEFINITION";
2269 p
= "ENUMERATOR DEFINITION";
2274 case ST_OACC_PARALLEL_LOOP
:
2275 p
= "!$ACC PARALLEL LOOP";
2277 case ST_OACC_END_PARALLEL_LOOP
:
2278 p
= "!$ACC END PARALLEL LOOP";
2280 case ST_OACC_PARALLEL
:
2281 p
= "!$ACC PARALLEL";
2283 case ST_OACC_END_PARALLEL
:
2284 p
= "!$ACC END PARALLEL";
2286 case ST_OACC_KERNELS
:
2287 p
= "!$ACC KERNELS";
2289 case ST_OACC_END_KERNELS
:
2290 p
= "!$ACC END KERNELS";
2292 case ST_OACC_KERNELS_LOOP
:
2293 p
= "!$ACC KERNELS LOOP";
2295 case ST_OACC_END_KERNELS_LOOP
:
2296 p
= "!$ACC END KERNELS LOOP";
2298 case ST_OACC_SERIAL_LOOP
:
2299 p
= "!$ACC SERIAL LOOP";
2301 case ST_OACC_END_SERIAL_LOOP
:
2302 p
= "!$ACC END SERIAL LOOP";
2304 case ST_OACC_SERIAL
:
2307 case ST_OACC_END_SERIAL
:
2308 p
= "!$ACC END SERIAL";
2313 case ST_OACC_END_DATA
:
2314 p
= "!$ACC END DATA";
2316 case ST_OACC_HOST_DATA
:
2317 p
= "!$ACC HOST_DATA";
2319 case ST_OACC_END_HOST_DATA
:
2320 p
= "!$ACC END HOST_DATA";
2325 case ST_OACC_END_LOOP
:
2326 p
= "!$ACC END LOOP";
2328 case ST_OACC_DECLARE
:
2329 p
= "!$ACC DECLARE";
2331 case ST_OACC_UPDATE
:
2340 case ST_OACC_ENTER_DATA
:
2341 p
= "!$ACC ENTER DATA";
2343 case ST_OACC_EXIT_DATA
:
2344 p
= "!$ACC EXIT DATA";
2346 case ST_OACC_ROUTINE
:
2347 p
= "!$ACC ROUTINE";
2349 case ST_OACC_ATOMIC
:
2352 case ST_OACC_END_ATOMIC
:
2353 p
= "!$ACC END ATOMIC";
2358 case ST_OMP_BARRIER
:
2359 p
= "!$OMP BARRIER";
2364 case ST_OMP_CANCELLATION_POINT
:
2365 p
= "!$OMP CANCELLATION POINT";
2367 case ST_OMP_CRITICAL
:
2368 p
= "!$OMP CRITICAL";
2370 case ST_OMP_DECLARE_REDUCTION
:
2371 p
= "!$OMP DECLARE REDUCTION";
2373 case ST_OMP_DECLARE_SIMD
:
2374 p
= "!$OMP DECLARE SIMD";
2376 case ST_OMP_DECLARE_TARGET
:
2377 p
= "!$OMP DECLARE TARGET";
2379 case ST_OMP_DECLARE_VARIANT
:
2380 p
= "!$OMP DECLARE VARIANT";
2385 case ST_OMP_DISTRIBUTE
:
2386 p
= "!$OMP DISTRIBUTE";
2388 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
2389 p
= "!$OMP DISTRIBUTE PARALLEL DO";
2391 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
2392 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2394 case ST_OMP_DISTRIBUTE_SIMD
:
2395 p
= "!$OMP DISTRIBUTE SIMD";
2400 case ST_OMP_DO_SIMD
:
2401 p
= "!$OMP DO SIMD";
2403 case ST_OMP_END_ATOMIC
:
2404 p
= "!$OMP END ATOMIC";
2406 case ST_OMP_END_CRITICAL
:
2407 p
= "!$OMP END CRITICAL";
2409 case ST_OMP_END_DISTRIBUTE
:
2410 p
= "!$OMP END DISTRIBUTE";
2412 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2413 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2415 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2416 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2418 case ST_OMP_END_DISTRIBUTE_SIMD
:
2419 p
= "!$OMP END DISTRIBUTE SIMD";
2424 case ST_OMP_END_DO_SIMD
:
2425 p
= "!$OMP END DO SIMD";
2427 case ST_OMP_END_SCOPE
:
2428 p
= "!$OMP END SCOPE";
2430 case ST_OMP_END_SIMD
:
2431 p
= "!$OMP END SIMD";
2433 case ST_OMP_END_LOOP
:
2434 p
= "!$OMP END LOOP";
2436 case ST_OMP_END_MASKED
:
2437 p
= "!$OMP END MASKED";
2439 case ST_OMP_END_MASKED_TASKLOOP
:
2440 p
= "!$OMP END MASKED TASKLOOP";
2442 case ST_OMP_END_MASKED_TASKLOOP_SIMD
:
2443 p
= "!$OMP END MASKED TASKLOOP SIMD";
2445 case ST_OMP_END_MASTER
:
2446 p
= "!$OMP END MASTER";
2448 case ST_OMP_END_MASTER_TASKLOOP
:
2449 p
= "!$OMP END MASTER TASKLOOP";
2451 case ST_OMP_END_MASTER_TASKLOOP_SIMD
:
2452 p
= "!$OMP END MASTER TASKLOOP SIMD";
2454 case ST_OMP_END_ORDERED
:
2455 p
= "!$OMP END ORDERED";
2457 case ST_OMP_END_PARALLEL
:
2458 p
= "!$OMP END PARALLEL";
2460 case ST_OMP_END_PARALLEL_DO
:
2461 p
= "!$OMP END PARALLEL DO";
2463 case ST_OMP_END_PARALLEL_DO_SIMD
:
2464 p
= "!$OMP END PARALLEL DO SIMD";
2466 case ST_OMP_END_PARALLEL_LOOP
:
2467 p
= "!$OMP END PARALLEL LOOP";
2469 case ST_OMP_END_PARALLEL_MASKED
:
2470 p
= "!$OMP END PARALLEL MASKED";
2472 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP
:
2473 p
= "!$OMP END PARALLEL MASKED TASKLOOP";
2475 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
:
2476 p
= "!$OMP END PARALLEL MASKED TASKLOOP SIMD";
2478 case ST_OMP_END_PARALLEL_MASTER
:
2479 p
= "!$OMP END PARALLEL MASTER";
2481 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP
:
2482 p
= "!$OMP END PARALLEL MASTER TASKLOOP";
2484 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
:
2485 p
= "!$OMP END PARALLEL MASTER TASKLOOP SIMD";
2487 case ST_OMP_END_PARALLEL_SECTIONS
:
2488 p
= "!$OMP END PARALLEL SECTIONS";
2490 case ST_OMP_END_PARALLEL_WORKSHARE
:
2491 p
= "!$OMP END PARALLEL WORKSHARE";
2493 case ST_OMP_END_SECTIONS
:
2494 p
= "!$OMP END SECTIONS";
2496 case ST_OMP_END_SINGLE
:
2497 p
= "!$OMP END SINGLE";
2499 case ST_OMP_END_TASK
:
2500 p
= "!$OMP END TASK";
2502 case ST_OMP_END_TARGET
:
2503 p
= "!$OMP END TARGET";
2505 case ST_OMP_END_TARGET_DATA
:
2506 p
= "!$OMP END TARGET DATA";
2508 case ST_OMP_END_TARGET_PARALLEL
:
2509 p
= "!$OMP END TARGET PARALLEL";
2511 case ST_OMP_END_TARGET_PARALLEL_DO
:
2512 p
= "!$OMP END TARGET PARALLEL DO";
2514 case ST_OMP_END_TARGET_PARALLEL_DO_SIMD
:
2515 p
= "!$OMP END TARGET PARALLEL DO SIMD";
2517 case ST_OMP_END_TARGET_PARALLEL_LOOP
:
2518 p
= "!$OMP END TARGET PARALLEL LOOP";
2520 case ST_OMP_END_TARGET_SIMD
:
2521 p
= "!$OMP END TARGET SIMD";
2523 case ST_OMP_END_TARGET_TEAMS
:
2524 p
= "!$OMP END TARGET TEAMS";
2526 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2527 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2529 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2530 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2532 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2533 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2535 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2536 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2538 case ST_OMP_END_TARGET_TEAMS_LOOP
:
2539 p
= "!$OMP END TARGET TEAMS LOOP";
2541 case ST_OMP_END_TASKGROUP
:
2542 p
= "!$OMP END TASKGROUP";
2544 case ST_OMP_END_TASKLOOP
:
2545 p
= "!$OMP END TASKLOOP";
2547 case ST_OMP_END_TASKLOOP_SIMD
:
2548 p
= "!$OMP END TASKLOOP SIMD";
2550 case ST_OMP_END_TEAMS
:
2551 p
= "!$OMP END TEAMS";
2553 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2554 p
= "!$OMP END TEAMS DISTRIBUTE";
2556 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2557 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2559 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2560 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2562 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2563 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2565 case ST_OMP_END_TEAMS_LOOP
:
2566 p
= "!$OMP END TEAMS LOOP";
2568 case ST_OMP_END_WORKSHARE
:
2569 p
= "!$OMP END WORKSHARE";
2583 case ST_OMP_MASKED_TASKLOOP
:
2584 p
= "!$OMP MASKED TASKLOOP";
2586 case ST_OMP_MASKED_TASKLOOP_SIMD
:
2587 p
= "!$OMP MASKED TASKLOOP SIMD";
2592 case ST_OMP_MASTER_TASKLOOP
:
2593 p
= "!$OMP MASTER TASKLOOP";
2595 case ST_OMP_MASTER_TASKLOOP_SIMD
:
2596 p
= "!$OMP MASTER TASKLOOP SIMD";
2598 case ST_OMP_ORDERED
:
2599 case ST_OMP_ORDERED_DEPEND
:
2600 p
= "!$OMP ORDERED";
2602 case ST_OMP_PARALLEL
:
2603 p
= "!$OMP PARALLEL";
2605 case ST_OMP_PARALLEL_DO
:
2606 p
= "!$OMP PARALLEL DO";
2608 case ST_OMP_PARALLEL_LOOP
:
2609 p
= "!$OMP PARALLEL LOOP";
2611 case ST_OMP_PARALLEL_DO_SIMD
:
2612 p
= "!$OMP PARALLEL DO SIMD";
2614 case ST_OMP_PARALLEL_MASKED
:
2615 p
= "!$OMP PARALLEL MASKED";
2617 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
2618 p
= "!$OMP PARALLEL MASKED TASKLOOP";
2620 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
2621 p
= "!$OMP PARALLEL MASKED TASKLOOP SIMD";
2623 case ST_OMP_PARALLEL_MASTER
:
2624 p
= "!$OMP PARALLEL MASTER";
2626 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
2627 p
= "!$OMP PARALLEL MASTER TASKLOOP";
2629 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
2630 p
= "!$OMP PARALLEL MASTER TASKLOOP SIMD";
2632 case ST_OMP_PARALLEL_SECTIONS
:
2633 p
= "!$OMP PARALLEL SECTIONS";
2635 case ST_OMP_PARALLEL_WORKSHARE
:
2636 p
= "!$OMP PARALLEL WORKSHARE";
2638 case ST_OMP_REQUIRES
:
2639 p
= "!$OMP REQUIRES";
2647 case ST_OMP_SECTIONS
:
2648 p
= "!$OMP SECTIONS";
2650 case ST_OMP_SECTION
:
2651 p
= "!$OMP SECTION";
2662 case ST_OMP_TARGET_DATA
:
2663 p
= "!$OMP TARGET DATA";
2665 case ST_OMP_TARGET_ENTER_DATA
:
2666 p
= "!$OMP TARGET ENTER DATA";
2668 case ST_OMP_TARGET_EXIT_DATA
:
2669 p
= "!$OMP TARGET EXIT DATA";
2671 case ST_OMP_TARGET_PARALLEL
:
2672 p
= "!$OMP TARGET PARALLEL";
2674 case ST_OMP_TARGET_PARALLEL_DO
:
2675 p
= "!$OMP TARGET PARALLEL DO";
2677 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
2678 p
= "!$OMP TARGET PARALLEL DO SIMD";
2680 case ST_OMP_TARGET_PARALLEL_LOOP
:
2681 p
= "!$OMP TARGET PARALLEL LOOP";
2683 case ST_OMP_TARGET_SIMD
:
2684 p
= "!$OMP TARGET SIMD";
2686 case ST_OMP_TARGET_TEAMS
:
2687 p
= "!$OMP TARGET TEAMS";
2689 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
2690 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
2692 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2693 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2695 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2696 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2698 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2699 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2701 case ST_OMP_TARGET_TEAMS_LOOP
:
2702 p
= "!$OMP TARGET TEAMS LOOP";
2704 case ST_OMP_TARGET_UPDATE
:
2705 p
= "!$OMP TARGET UPDATE";
2710 case ST_OMP_TASKGROUP
:
2711 p
= "!$OMP TASKGROUP";
2713 case ST_OMP_TASKLOOP
:
2714 p
= "!$OMP TASKLOOP";
2716 case ST_OMP_TASKLOOP_SIMD
:
2717 p
= "!$OMP TASKLOOP SIMD";
2719 case ST_OMP_TASKWAIT
:
2720 p
= "!$OMP TASKWAIT";
2722 case ST_OMP_TASKYIELD
:
2723 p
= "!$OMP TASKYIELD";
2728 case ST_OMP_TEAMS_DISTRIBUTE
:
2729 p
= "!$OMP TEAMS DISTRIBUTE";
2731 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2732 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2734 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2735 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2737 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
2738 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
2740 case ST_OMP_TEAMS_LOOP
:
2741 p
= "!$OMP TEAMS LOOP";
2743 case ST_OMP_THREADPRIVATE
:
2744 p
= "!$OMP THREADPRIVATE";
2746 case ST_OMP_WORKSHARE
:
2747 p
= "!$OMP WORKSHARE";
2750 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2757 /* Create a symbol for the main program and assign it to ns->proc_name. */
2760 main_program_symbol (gfc_namespace
*ns
, const char *name
)
2762 gfc_symbol
*main_program
;
2763 symbol_attribute attr
;
2765 gfc_get_symbol (name
, ns
, &main_program
);
2766 gfc_clear_attr (&attr
);
2767 attr
.flavor
= FL_PROGRAM
;
2768 attr
.proc
= PROC_UNKNOWN
;
2769 attr
.subroutine
= 1;
2770 attr
.access
= ACCESS_PUBLIC
;
2771 attr
.is_main_program
= 1;
2772 main_program
->attr
= attr
;
2773 main_program
->declared_at
= gfc_current_locus
;
2774 ns
->proc_name
= main_program
;
2775 gfc_commit_symbols ();
2779 /* Do whatever is necessary to accept the last statement. */
2782 accept_statement (gfc_statement st
)
2786 case ST_IMPLICIT_NONE
:
2794 gfc_current_ns
->proc_name
= gfc_new_block
;
2797 /* If the statement is the end of a block, lay down a special code
2798 that allows a branch to the end of the block from within the
2799 construct. IF and SELECT are treated differently from DO
2800 (where EXEC_NOP is added inside the loop) for two
2802 1. END DO has a meaning in the sense that after a GOTO to
2803 it, the loop counter must be increased.
2804 2. IF blocks and SELECT blocks can consist of multiple
2805 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
2806 Putting the label before the END IF would make the jump
2807 from, say, the ELSE IF block to the END IF illegal. */
2811 case ST_END_CRITICAL
:
2812 if (gfc_statement_label
!= NULL
)
2814 new_st
.op
= EXEC_END_NESTED_BLOCK
;
2819 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
2820 one parallel block. Thus, we add the special code to the nested block
2821 itself, instead of the parent one. */
2823 case ST_END_ASSOCIATE
:
2824 if (gfc_statement_label
!= NULL
)
2826 new_st
.op
= EXEC_END_BLOCK
;
2831 /* The end-of-program unit statements do not get the special
2832 marker and require a statement of some sort if they are a
2835 case ST_END_PROGRAM
:
2836 case ST_END_FUNCTION
:
2837 case ST_END_SUBROUTINE
:
2838 if (gfc_statement_label
!= NULL
)
2840 new_st
.op
= EXEC_RETURN
;
2845 new_st
.op
= EXEC_END_PROCEDURE
;
2861 gfc_commit_symbols ();
2862 gfc_warning_check ();
2863 gfc_clear_new_st ();
2867 /* Undo anything tentative that has been built for the current statement,
2868 except if a gfc_charlen structure has been added to current namespace's
2869 list of gfc_charlen structure. */
2872 reject_statement (void)
2874 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
2875 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
2877 gfc_reject_data (gfc_current_ns
);
2879 gfc_new_block
= NULL
;
2880 gfc_undo_symbols ();
2881 gfc_clear_warning ();
2882 undo_new_statement ();
2886 /* Generic complaint about an out of order statement. We also do
2887 whatever is necessary to clean up. */
2890 unexpected_statement (gfc_statement st
)
2892 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
2894 reject_statement ();
2898 /* Given the next statement seen by the matcher, make sure that it is
2899 in proper order with the last. This subroutine is initialized by
2900 calling it with an argument of ST_NONE. If there is a problem, we
2901 issue an error and return false. Otherwise we return true.
2903 Individual parsers need to verify that the statements seen are
2904 valid before calling here, i.e., ENTRY statements are not allowed in
2905 INTERFACE blocks. The following diagram is taken from the standard:
2907 +---------------------------------------+
2908 | program subroutine function module |
2909 +---------------------------------------+
2911 +---------------------------------------+
2913 +---------------------------------------+
2915 | +-----------+------------------+
2916 | | parameter | implicit |
2917 | +-----------+------------------+
2918 | format | | derived type |
2919 | entry | parameter | interface |
2920 | | data | specification |
2921 | | | statement func |
2922 | +-----------+------------------+
2923 | | data | executable |
2924 +--------+-----------+------------------+
2926 +---------------------------------------+
2927 | internal module/subprogram |
2928 +---------------------------------------+
2930 +---------------------------------------+
2939 ORDER_IMPLICIT_NONE
,
2947 enum state_order state
;
2948 gfc_statement last_statement
;
2954 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
2960 p
->state
= ORDER_START
;
2964 if (p
->state
> ORDER_USE
)
2966 p
->state
= ORDER_USE
;
2970 if (p
->state
> ORDER_IMPORT
)
2972 p
->state
= ORDER_IMPORT
;
2975 case ST_IMPLICIT_NONE
:
2976 if (p
->state
> ORDER_IMPLICIT
)
2979 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
2980 statement disqualifies a USE but not an IMPLICIT NONE.
2981 Duplicate IMPLICIT NONEs are caught when the implicit types
2984 p
->state
= ORDER_IMPLICIT_NONE
;
2988 if (p
->state
> ORDER_IMPLICIT
)
2990 p
->state
= ORDER_IMPLICIT
;
2995 if (p
->state
< ORDER_IMPLICIT_NONE
)
2996 p
->state
= ORDER_IMPLICIT_NONE
;
3000 if (p
->state
>= ORDER_EXEC
)
3002 if (p
->state
< ORDER_IMPLICIT
)
3003 p
->state
= ORDER_IMPLICIT
;
3007 if (p
->state
< ORDER_SPEC
)
3008 p
->state
= ORDER_SPEC
;
3013 case ST_STRUCTURE_DECL
:
3014 case ST_DERIVED_DECL
:
3016 if (p
->state
>= ORDER_EXEC
)
3018 if (p
->state
< ORDER_SPEC
)
3019 p
->state
= ORDER_SPEC
;
3023 /* The OpenMP/OpenACC directives have to be somewhere in the specification
3024 part, but there are no further requirements on their ordering.
3025 Thus don't adjust p->state, just ignore them. */
3026 if (p
->state
>= ORDER_EXEC
)
3032 if (p
->state
< ORDER_EXEC
)
3033 p
->state
= ORDER_EXEC
;
3040 /* All is well, record the statement in case we need it next time. */
3041 p
->where
= gfc_current_locus
;
3042 p
->last_statement
= st
;
3047 gfc_error ("%s statement at %C cannot follow %s statement at %L",
3048 gfc_ascii_statement (st
),
3049 gfc_ascii_statement (p
->last_statement
), &p
->where
);
3055 /* Handle an unexpected end of file. This is a show-stopper... */
3057 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
3060 unexpected_eof (void)
3064 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
3066 /* Memory cleanup. Move to "second to last". */
3067 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
3070 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
3073 longjmp (eof_buf
, 1);
3075 /* Avoids build error on systems where longjmp is not declared noreturn. */
3080 /* Parse the CONTAINS section of a derived type definition. */
3082 gfc_access gfc_typebound_default_access
;
3085 parse_derived_contains (void)
3088 bool seen_private
= false;
3089 bool seen_comps
= false;
3090 bool error_flag
= false;
3093 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3094 gcc_assert (gfc_current_block ());
3096 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
3098 if (gfc_current_block ()->attr
.sequence
)
3099 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
3100 " section at %C", gfc_current_block ()->name
);
3101 if (gfc_current_block ()->attr
.is_bind_c
)
3102 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
3103 " section at %C", gfc_current_block ()->name
);
3105 accept_statement (ST_CONTAINS
);
3106 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
3108 gfc_typebound_default_access
= ACCESS_PUBLIC
;
3114 st
= next_statement ();
3122 gfc_error ("Components in TYPE at %C must precede CONTAINS");
3126 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
3129 accept_statement (ST_PROCEDURE
);
3134 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
3137 accept_statement (ST_GENERIC
);
3142 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
3146 accept_statement (ST_FINAL
);
3154 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
3155 "at %C with empty CONTAINS section")))
3158 /* ST_END_TYPE is accepted by parse_derived after return. */
3162 if (!gfc_find_state (COMP_MODULE
))
3164 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3171 gfc_error ("PRIVATE statement at %C must precede procedure"
3178 gfc_error ("Duplicate PRIVATE statement at %C");
3182 accept_statement (ST_PRIVATE
);
3183 gfc_typebound_default_access
= ACCESS_PRIVATE
;
3184 seen_private
= true;
3188 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
3192 gfc_error ("Already inside a CONTAINS block at %C");
3196 unexpected_statement (st
);
3204 reject_statement ();
3208 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3214 /* Set attributes for the parent symbol based on the attributes of a component
3215 and raise errors if conflicting attributes are found for the component. */
3218 check_component (gfc_symbol
*sym
, gfc_component
*c
, gfc_component
**lockp
,
3219 gfc_component
**eventp
)
3221 bool coarray
, lock_type
, event_type
, allocatable
, pointer
;
3222 coarray
= lock_type
= event_type
= allocatable
= pointer
= false;
3223 gfc_component
*lock_comp
= NULL
, *event_comp
= NULL
;
3225 if (lockp
) lock_comp
= *lockp
;
3226 if (eventp
) event_comp
= *eventp
;
3228 /* Look for allocatable components. */
3229 if (c
->attr
.allocatable
3230 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3231 && CLASS_DATA (c
)->attr
.allocatable
)
3232 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
3233 && c
->ts
.u
.derived
->attr
.alloc_comp
))
3236 sym
->attr
.alloc_comp
= 1;
3239 /* Look for pointer components. */
3241 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3242 && CLASS_DATA (c
)->attr
.class_pointer
)
3243 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
3246 sym
->attr
.pointer_comp
= 1;
3249 /* Look for procedure pointer components. */
3250 if (c
->attr
.proc_pointer
3251 || (c
->ts
.type
== BT_DERIVED
3252 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
3253 sym
->attr
.proc_pointer_comp
= 1;
3255 /* Looking for coarray components. */
3256 if (c
->attr
.codimension
3257 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3258 && CLASS_DATA (c
)->attr
.codimension
))
3261 sym
->attr
.coarray_comp
= 1;
3264 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
3265 && !c
->attr
.pointer
)
3268 sym
->attr
.coarray_comp
= 1;
3271 /* Looking for lock_type components. */
3272 if ((c
->ts
.type
== BT_DERIVED
3273 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3274 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
3275 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3276 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3277 == INTMOD_ISO_FORTRAN_ENV
3278 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3279 == ISOFORTRAN_LOCK_TYPE
)
3280 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
3281 && !allocatable
&& !pointer
))
3285 sym
->attr
.lock_comp
= 1;
3288 /* Looking for event_type components. */
3289 if ((c
->ts
.type
== BT_DERIVED
3290 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3291 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
3292 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3293 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3294 == INTMOD_ISO_FORTRAN_ENV
3295 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3296 == ISOFORTRAN_EVENT_TYPE
)
3297 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.event_comp
3298 && !allocatable
&& !pointer
))
3302 sym
->attr
.event_comp
= 1;
3305 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
3306 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
3307 unless there are nondirect [allocatable or pointer] components
3308 involved (cf. 1.3.33.1 and 1.3.33.3). */
3310 if (pointer
&& !coarray
&& lock_type
)
3311 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
3312 "codimension or be a subcomponent of a coarray, "
3313 "which is not possible as the component has the "
3314 "pointer attribute", c
->name
, &c
->loc
);
3315 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3316 && c
->ts
.u
.derived
->attr
.lock_comp
)
3317 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3318 "of type LOCK_TYPE, which must have a codimension or be a "
3319 "subcomponent of a coarray", c
->name
, &c
->loc
);
3321 if (lock_type
&& allocatable
&& !coarray
)
3322 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
3323 "a codimension", c
->name
, &c
->loc
);
3324 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3325 && c
->ts
.u
.derived
->attr
.lock_comp
)
3326 gfc_error ("Allocatable component %s at %L must have a codimension as "
3327 "it has a noncoarray subcomponent of type LOCK_TYPE",
3330 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
3331 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3332 "subcomponent of type LOCK_TYPE must have a codimension or "
3333 "be a subcomponent of a coarray. (Variables of type %s may "
3334 "not have a codimension as already a coarray "
3335 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3337 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
3338 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3339 "subcomponent of type LOCK_TYPE must have a codimension or "
3340 "be a subcomponent of a coarray. (Variables of type %s may "
3341 "not have a codimension as %s at %L has a codimension or a "
3342 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
3343 sym
->name
, c
->name
, &c
->loc
);
3345 /* Similarly for EVENT TYPE. */
3347 if (pointer
&& !coarray
&& event_type
)
3348 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
3349 "codimension or be a subcomponent of a coarray, "
3350 "which is not possible as the component has the "
3351 "pointer attribute", c
->name
, &c
->loc
);
3352 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3353 && c
->ts
.u
.derived
->attr
.event_comp
)
3354 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3355 "of type EVENT_TYPE, which must have a codimension or be a "
3356 "subcomponent of a coarray", c
->name
, &c
->loc
);
3358 if (event_type
&& allocatable
&& !coarray
)
3359 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
3360 "a codimension", c
->name
, &c
->loc
);
3361 else if (event_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3362 && c
->ts
.u
.derived
->attr
.event_comp
)
3363 gfc_error ("Allocatable component %s at %L must have a codimension as "
3364 "it has a noncoarray subcomponent of type EVENT_TYPE",
3367 if (sym
->attr
.coarray_comp
&& !coarray
&& event_type
)
3368 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3369 "subcomponent of type EVENT_TYPE must have a codimension or "
3370 "be a subcomponent of a coarray. (Variables of type %s may "
3371 "not have a codimension as already a coarray "
3372 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3374 if (sym
->attr
.event_comp
&& coarray
&& !event_type
)
3375 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3376 "subcomponent of type EVENT_TYPE must have a codimension or "
3377 "be a subcomponent of a coarray. (Variables of type %s may "
3378 "not have a codimension as %s at %L has a codimension or a "
3379 "coarray subcomponent)", event_comp
->name
, &event_comp
->loc
,
3380 sym
->name
, c
->name
, &c
->loc
);
3382 /* Look for private components. */
3383 if (sym
->component_access
== ACCESS_PRIVATE
3384 || c
->attr
.access
== ACCESS_PRIVATE
3385 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
3386 sym
->attr
.private_comp
= 1;
3388 if (lockp
) *lockp
= lock_comp
;
3389 if (eventp
) *eventp
= event_comp
;
3393 static void parse_struct_map (gfc_statement
);
3395 /* Parse a union component definition within a structure definition. */
3403 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3406 accept_statement(ST_UNION
);
3407 push_state (&s
, COMP_UNION
, gfc_new_block
);
3414 st
= next_statement ();
3415 /* Only MAP declarations valid within a union. */
3422 accept_statement (ST_MAP
);
3423 parse_struct_map (ST_MAP
);
3424 /* Add a component to the union for each map. */
3425 if (!gfc_add_component (un
, gfc_new_block
->name
, &c
))
3427 gfc_internal_error ("failed to create map component '%s'",
3428 gfc_new_block
->name
);
3429 reject_statement ();
3432 c
->ts
.type
= BT_DERIVED
;
3433 c
->ts
.u
.derived
= gfc_new_block
;
3434 /* Normally components get their initialization expressions when they
3435 are created in decl.cc (build_struct) so we can look through the
3436 flat component list for initializers during resolution. Unions and
3437 maps create components along with their type definitions so we
3438 have to generate initializers here. */
3439 c
->initializer
= gfc_default_initializer (&c
->ts
);
3444 accept_statement (ST_END_UNION
);
3448 unexpected_statement (st
);
3453 for (c
= un
->components
; c
; c
= c
->next
)
3454 check_component (un
, c
, &lock_comp
, &event_comp
);
3456 /* Add the union as a component in its parent structure. */
3458 if (!gfc_add_component (gfc_current_block (), un
->name
, &c
))
3460 gfc_internal_error ("failed to create union component '%s'", un
->name
);
3461 reject_statement ();
3464 c
->ts
.type
= BT_UNION
;
3465 c
->ts
.u
.derived
= un
;
3466 c
->initializer
= gfc_default_initializer (&c
->ts
);
3468 un
->attr
.zero_comp
= un
->components
== NULL
;
3472 /* Parse a STRUCTURE or MAP. */
3475 parse_struct_map (gfc_statement block
)
3481 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3482 gfc_compile_state comp
;
3485 if (block
== ST_STRUCTURE_DECL
)
3487 comp
= COMP_STRUCTURE
;
3488 ends
= ST_END_STRUCTURE
;
3492 gcc_assert (block
== ST_MAP
);
3497 accept_statement(block
);
3498 push_state (&s
, comp
, gfc_new_block
);
3500 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3503 while (compiling_type
)
3505 st
= next_statement ();
3511 /* Nested structure declarations will be captured as ST_DATA_DECL. */
3512 case ST_STRUCTURE_DECL
:
3513 /* Let a more specific error make it to decode_statement(). */
3514 if (gfc_error_check () == 0)
3515 gfc_error ("Syntax error in nested structure declaration at %C");
3516 reject_statement ();
3517 /* Skip the rest of this statement. */
3518 gfc_error_recovery ();
3522 accept_statement (ST_UNION
);
3527 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
3528 accept_statement (ST_DATA_DECL
);
3529 if (gfc_new_block
&& gfc_new_block
!= gfc_current_block ()
3530 && gfc_new_block
->attr
.flavor
== FL_STRUCT
)
3531 parse_struct_map (ST_STRUCTURE_DECL
);
3534 case ST_END_STRUCTURE
:
3538 accept_statement (st
);
3542 unexpected_statement (st
);
3546 unexpected_statement (st
);
3551 /* Validate each component. */
3552 sym
= gfc_current_block ();
3553 for (c
= sym
->components
; c
; c
= c
->next
)
3554 check_component (sym
, c
, &lock_comp
, &event_comp
);
3556 sym
->attr
.zero_comp
= (sym
->components
== NULL
);
3558 /* Allow parse_union to find this structure to add to its list of maps. */
3559 if (block
== ST_MAP
)
3560 gfc_new_block
= gfc_current_block ();
3566 /* Parse a derived type. */
3569 parse_derived (void)
3571 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
3575 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3577 accept_statement (ST_DERIVED_DECL
);
3578 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
3580 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3587 while (compiling_type
)
3589 st
= next_statement ();
3597 accept_statement (st
);
3602 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3609 if (!seen_component
)
3610 gfc_notify_std (GFC_STD_F2003
, "Derived type "
3611 "definition at %C without components");
3613 accept_statement (ST_END_TYPE
);
3617 if (!gfc_find_state (COMP_MODULE
))
3619 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3626 gfc_error ("PRIVATE statement at %C must precede "
3627 "structure components");
3632 gfc_error ("Duplicate PRIVATE statement at %C");
3634 s
.sym
->component_access
= ACCESS_PRIVATE
;
3636 accept_statement (ST_PRIVATE
);
3643 gfc_error ("SEQUENCE statement at %C must precede "
3644 "structure components");
3648 if (gfc_current_block ()->attr
.sequence
)
3649 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
3654 gfc_error ("Duplicate SEQUENCE statement at %C");
3658 gfc_add_sequence (&gfc_current_block ()->attr
,
3659 gfc_current_block ()->name
, NULL
);
3663 gfc_notify_std (GFC_STD_F2003
,
3664 "CONTAINS block in derived type"
3665 " definition at %C");
3667 accept_statement (ST_CONTAINS
);
3668 parse_derived_contains ();
3672 unexpected_statement (st
);
3677 /* need to verify that all fields of the derived type are
3678 * interoperable with C if the type is declared to be bind(c)
3680 sym
= gfc_current_block ();
3681 for (c
= sym
->components
; c
; c
= c
->next
)
3682 check_component (sym
, c
, &lock_comp
, &event_comp
);
3684 if (!seen_component
)
3685 sym
->attr
.zero_comp
= 1;
3691 /* Parse an ENUM. */
3699 int seen_enumerator
= 0;
3701 push_state (&s
, COMP_ENUM
, gfc_new_block
);
3705 while (compiling_enum
)
3707 st
= next_statement ();
3715 seen_enumerator
= 1;
3716 accept_statement (st
);
3721 if (!seen_enumerator
)
3722 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
3723 accept_statement (st
);
3727 gfc_free_enum_history ();
3728 unexpected_statement (st
);
3736 /* Parse an interface. We must be able to deal with the possibility
3737 of recursive interfaces. The parse_spec() subroutine is mutually
3738 recursive with parse_interface(). */
3740 static gfc_statement
parse_spec (gfc_statement
);
3743 parse_interface (void)
3745 gfc_compile_state new_state
= COMP_NONE
, current_state
;
3746 gfc_symbol
*prog_unit
, *sym
;
3747 gfc_interface_info save
;
3748 gfc_state_data s1
, s2
;
3751 accept_statement (ST_INTERFACE
);
3753 current_interface
.ns
= gfc_current_ns
;
3754 save
= current_interface
;
3756 sym
= (current_interface
.type
== INTERFACE_GENERIC
3757 || current_interface
.type
== INTERFACE_USER_OP
)
3758 ? gfc_new_block
: NULL
;
3760 push_state (&s1
, COMP_INTERFACE
, sym
);
3761 current_state
= COMP_NONE
;
3764 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
3766 st
= next_statement ();
3774 if (st
== ST_SUBROUTINE
)
3775 new_state
= COMP_SUBROUTINE
;
3776 else if (st
== ST_FUNCTION
)
3777 new_state
= COMP_FUNCTION
;
3778 if (gfc_new_block
->attr
.pointer
)
3780 gfc_new_block
->attr
.pointer
= 0;
3781 gfc_new_block
->attr
.proc_pointer
= 1;
3783 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
3784 gfc_new_block
->formal
, NULL
))
3786 reject_statement ();
3787 gfc_free_namespace (gfc_current_ns
);
3790 /* F2008 C1210 forbids the IMPORT statement in module procedure
3791 interface bodies and the flag is set to import symbols. */
3792 if (gfc_new_block
->attr
.module_procedure
)
3793 gfc_current_ns
->has_import_set
= 1;
3797 case ST_MODULE_PROC
: /* The module procedure matcher makes
3798 sure the context is correct. */
3799 accept_statement (st
);
3800 gfc_free_namespace (gfc_current_ns
);
3803 case ST_END_INTERFACE
:
3804 gfc_free_namespace (gfc_current_ns
);
3805 gfc_current_ns
= current_interface
.ns
;
3809 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
3810 gfc_ascii_statement (st
));
3811 reject_statement ();
3812 gfc_free_namespace (gfc_current_ns
);
3817 /* Make sure that the generic name has the right attribute. */
3818 if (current_interface
.type
== INTERFACE_GENERIC
3819 && current_state
== COMP_NONE
)
3821 if (new_state
== COMP_FUNCTION
&& sym
)
3822 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
3823 else if (new_state
== COMP_SUBROUTINE
&& sym
)
3824 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
3826 current_state
= new_state
;
3829 if (current_interface
.type
== INTERFACE_ABSTRACT
)
3831 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
3832 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
3833 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
3834 "cannot be the same as an intrinsic type",
3835 gfc_new_block
->name
);
3838 push_state (&s2
, new_state
, gfc_new_block
);
3839 accept_statement (st
);
3840 prog_unit
= gfc_new_block
;
3841 prog_unit
->formal_ns
= gfc_current_ns
;
3842 if (prog_unit
== prog_unit
->formal_ns
->proc_name
3843 && prog_unit
->ns
!= prog_unit
->formal_ns
)
3847 /* Read data declaration statements. */
3848 st
= parse_spec (ST_NONE
);
3849 in_specification_block
= true;
3851 /* Since the interface block does not permit an IMPLICIT statement,
3852 the default type for the function or the result must be taken
3853 from the formal namespace. */
3854 if (new_state
== COMP_FUNCTION
)
3856 if (prog_unit
->result
== prog_unit
3857 && prog_unit
->ts
.type
== BT_UNKNOWN
)
3858 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
3859 else if (prog_unit
->result
!= prog_unit
3860 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
3861 gfc_set_default_type (prog_unit
->result
, 1,
3862 prog_unit
->formal_ns
);
3865 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
3867 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
3868 gfc_ascii_statement (st
));
3869 reject_statement ();
3873 /* Add EXTERNAL attribute to function or subroutine. */
3874 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
3875 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
3877 current_interface
= save
;
3878 gfc_add_interface (prog_unit
);
3881 if (current_interface
.ns
3882 && current_interface
.ns
->proc_name
3883 && strcmp (current_interface
.ns
->proc_name
->name
,
3884 prog_unit
->name
) == 0)
3885 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
3886 "enclosing procedure", prog_unit
->name
,
3887 ¤t_interface
.ns
->proc_name
->declared_at
);
3896 /* Associate function characteristics by going back to the function
3897 declaration and rematching the prefix. */
3900 match_deferred_characteristics (gfc_typespec
* ts
)
3903 match m
= MATCH_ERROR
;
3904 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3906 loc
= gfc_current_locus
;
3908 gfc_current_locus
= gfc_current_block ()->declared_at
;
3911 gfc_buffer_error (true);
3912 m
= gfc_match_prefix (ts
);
3913 gfc_buffer_error (false);
3915 if (ts
->type
== BT_DERIVED
)
3923 /* Only permit one go at the characteristic association. */
3927 /* Set the function locus correctly. If we have not found the
3928 function name, there is an error. */
3930 && gfc_match ("function% %n", name
) == MATCH_YES
3931 && strcmp (name
, gfc_current_block ()->name
) == 0)
3933 gfc_current_block ()->declared_at
= gfc_current_locus
;
3934 gfc_commit_symbols ();
3939 gfc_undo_symbols ();
3942 gfc_current_locus
=loc
;
3947 /* Check specification-expressions in the function result of the currently
3948 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
3949 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
3950 scope are not yet parsed so this has to be delayed up to parse_spec. */
3953 check_function_result_typed (void)
3957 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
3959 if (!gfc_current_ns
->proc_name
->result
) return;
3961 ts
= gfc_current_ns
->proc_name
->result
->ts
;
3963 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
3964 /* TODO: Extend when KIND type parameters are implemented. */
3965 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
3966 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
3970 /* Parse a set of specification statements. Returns the statement
3971 that doesn't fit. */
3973 static gfc_statement
3974 parse_spec (gfc_statement st
)
3977 bool function_result_typed
= false;
3978 bool bad_characteristic
= false;
3981 in_specification_block
= true;
3983 verify_st_order (&ss
, ST_NONE
, false);
3985 st
= next_statement ();
3987 /* If we are not inside a function or don't have a result specified so far,
3988 do nothing special about it. */
3989 if (gfc_current_state () != COMP_FUNCTION
)
3990 function_result_typed
= true;
3993 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
3996 if (proc
->result
->ts
.type
== BT_UNKNOWN
)
3997 function_result_typed
= true;
4002 /* If we're inside a BLOCK construct, some statements are disallowed.
4003 Check this here. Attribute declaration statements like INTENT, OPTIONAL
4004 or VALUE are also disallowed, but they don't have a particular ST_*
4005 key so we have to check for them individually in their matcher routine. */
4006 if (gfc_current_state () == COMP_BLOCK
)
4010 case ST_IMPLICIT_NONE
:
4013 case ST_EQUIVALENCE
:
4014 case ST_STATEMENT_FUNCTION
:
4015 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
4016 gfc_ascii_statement (st
));
4017 reject_statement ();
4023 else if (gfc_current_state () == COMP_BLOCK_DATA
)
4024 /* Fortran 2008, C1116. */
4031 case ST_DERIVED_DECL
:
4032 case ST_END_BLOCK_DATA
:
4033 case ST_EQUIVALENCE
:
4035 case ST_IMPLICIT_NONE
:
4036 case ST_OMP_THREADPRIVATE
:
4038 case ST_STRUCTURE_DECL
:
4047 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
4048 gfc_ascii_statement (st
));
4049 reject_statement ();
4053 /* If we find a statement that cannot be followed by an IMPLICIT statement
4054 (and thus we can expect to see none any further), type the function result
4055 if it has not yet been typed. Be careful not to give the END statement
4056 to verify_st_order! */
4057 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
4059 bool verify_now
= false;
4061 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
4066 verify_st_order (&dummyss
, ST_NONE
, false);
4067 verify_st_order (&dummyss
, st
, false);
4069 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
4075 check_function_result_typed ();
4076 function_result_typed
= true;
4085 case ST_IMPLICIT_NONE
:
4087 if (!function_result_typed
)
4089 check_function_result_typed ();
4090 function_result_typed
= true;
4096 case ST_DATA
: /* Not allowed in interfaces */
4097 if (gfc_current_state () == COMP_INTERFACE
)
4107 case ST_STRUCTURE_DECL
:
4108 case ST_DERIVED_DECL
:
4112 if (!verify_st_order (&ss
, st
, false))
4114 reject_statement ();
4115 st
= next_statement ();
4125 case ST_STRUCTURE_DECL
:
4126 parse_struct_map (ST_STRUCTURE_DECL
);
4129 case ST_DERIVED_DECL
:
4135 if (gfc_current_state () != COMP_MODULE
)
4137 gfc_error ("%s statement must appear in a MODULE",
4138 gfc_ascii_statement (st
));
4139 reject_statement ();
4143 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
4145 gfc_error ("%s statement at %C follows another accessibility "
4146 "specification", gfc_ascii_statement (st
));
4147 reject_statement ();
4151 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
4152 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
4156 case ST_STATEMENT_FUNCTION
:
4157 if (gfc_current_state () == COMP_MODULE
4158 || gfc_current_state () == COMP_SUBMODULE
)
4160 unexpected_statement (st
);
4168 accept_statement (st
);
4169 st
= next_statement ();
4173 accept_statement (st
);
4175 st
= next_statement ();
4178 case ST_GET_FCN_CHARACTERISTICS
:
4179 /* This statement triggers the association of a function's result
4181 ts
= &gfc_current_block ()->result
->ts
;
4182 if (match_deferred_characteristics (ts
) != MATCH_YES
)
4183 bad_characteristic
= true;
4185 st
= next_statement ();
4192 /* If match_deferred_characteristics failed, then there is an error. */
4193 if (bad_characteristic
)
4195 ts
= &gfc_current_block ()->result
->ts
;
4196 if (ts
->type
!= BT_DERIVED
)
4197 gfc_error ("Bad kind expression for function %qs at %L",
4198 gfc_current_block ()->name
,
4199 &gfc_current_block ()->declared_at
);
4201 gfc_error ("The type for function %qs at %L is not accessible",
4202 gfc_current_block ()->name
,
4203 &gfc_current_block ()->declared_at
);
4205 gfc_current_block ()->ts
.kind
= 0;
4206 /* Keep the derived type; if it's bad, it will be discovered later. */
4207 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
4208 ts
->type
= BT_UNKNOWN
;
4211 in_specification_block
= false;
4217 /* Parse a WHERE block, (not a simple WHERE statement). */
4220 parse_where_block (void)
4222 int seen_empty_else
;
4227 accept_statement (ST_WHERE_BLOCK
);
4228 top
= gfc_state_stack
->tail
;
4230 push_state (&s
, COMP_WHERE
, gfc_new_block
);
4232 d
= add_statement ();
4233 d
->expr1
= top
->expr1
;
4239 seen_empty_else
= 0;
4243 st
= next_statement ();
4249 case ST_WHERE_BLOCK
:
4250 parse_where_block ();
4255 accept_statement (st
);
4259 if (seen_empty_else
)
4261 gfc_error ("ELSEWHERE statement at %C follows previous "
4262 "unmasked ELSEWHERE");
4263 reject_statement ();
4267 if (new_st
.expr1
== NULL
)
4268 seen_empty_else
= 1;
4270 d
= new_level (gfc_state_stack
->head
);
4272 d
->expr1
= new_st
.expr1
;
4274 accept_statement (st
);
4279 accept_statement (st
);
4283 gfc_error ("Unexpected %s statement in WHERE block at %C",
4284 gfc_ascii_statement (st
));
4285 reject_statement ();
4289 while (st
!= ST_END_WHERE
);
4295 /* Parse a FORALL block (not a simple FORALL statement). */
4298 parse_forall_block (void)
4304 accept_statement (ST_FORALL_BLOCK
);
4305 top
= gfc_state_stack
->tail
;
4307 push_state (&s
, COMP_FORALL
, gfc_new_block
);
4309 d
= add_statement ();
4310 d
->op
= EXEC_FORALL
;
4315 st
= next_statement ();
4320 case ST_POINTER_ASSIGNMENT
:
4323 accept_statement (st
);
4326 case ST_WHERE_BLOCK
:
4327 parse_where_block ();
4330 case ST_FORALL_BLOCK
:
4331 parse_forall_block ();
4335 accept_statement (st
);
4342 gfc_error ("Unexpected %s statement in FORALL block at %C",
4343 gfc_ascii_statement (st
));
4345 reject_statement ();
4349 while (st
!= ST_END_FORALL
);
4355 static gfc_statement
parse_executable (gfc_statement
);
4357 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
4360 parse_if_block (void)
4369 accept_statement (ST_IF_BLOCK
);
4371 top
= gfc_state_stack
->tail
;
4372 push_state (&s
, COMP_IF
, gfc_new_block
);
4374 new_st
.op
= EXEC_IF
;
4375 d
= add_statement ();
4377 d
->expr1
= top
->expr1
;
4383 st
= parse_executable (ST_NONE
);
4393 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
4394 "statement at %L", &else_locus
);
4396 reject_statement ();
4400 d
= new_level (gfc_state_stack
->head
);
4402 d
->expr1
= new_st
.expr1
;
4404 accept_statement (st
);
4411 gfc_error ("Duplicate ELSE statements at %L and %C",
4413 reject_statement ();
4418 else_locus
= gfc_current_locus
;
4420 d
= new_level (gfc_state_stack
->head
);
4423 accept_statement (st
);
4431 unexpected_statement (st
);
4435 while (st
!= ST_ENDIF
);
4438 accept_statement (st
);
4442 /* Parse a SELECT block. */
4445 parse_select_block (void)
4451 accept_statement (ST_SELECT_CASE
);
4453 cp
= gfc_state_stack
->tail
;
4454 push_state (&s
, COMP_SELECT
, gfc_new_block
);
4456 /* Make sure that the next statement is a CASE or END SELECT. */
4459 st
= next_statement ();
4462 if (st
== ST_END_SELECT
)
4464 /* Empty SELECT CASE is OK. */
4465 accept_statement (st
);
4472 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
4475 reject_statement ();
4478 /* At this point, we've got a nonempty select block. */
4479 cp
= new_level (cp
);
4482 accept_statement (st
);
4486 st
= parse_executable (ST_NONE
);
4493 cp
= new_level (gfc_state_stack
->head
);
4495 gfc_clear_new_st ();
4497 accept_statement (st
);
4503 /* Can't have an executable statement because of
4504 parse_executable(). */
4506 unexpected_statement (st
);
4510 while (st
!= ST_END_SELECT
);
4513 accept_statement (st
);
4517 /* Pop the current selector from the SELECT TYPE stack. */
4520 select_type_pop (void)
4522 gfc_select_type_stack
*old
= select_type_stack
;
4523 select_type_stack
= old
->prev
;
4528 /* Parse a SELECT TYPE construct (F03:R821). */
4531 parse_select_type_block (void)
4537 gfc_current_ns
= new_st
.ext
.block
.ns
;
4538 accept_statement (ST_SELECT_TYPE
);
4540 cp
= gfc_state_stack
->tail
;
4541 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
4543 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4547 st
= next_statement ();
4550 if (st
== ST_END_SELECT
)
4551 /* Empty SELECT CASE is OK. */
4553 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
4556 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4557 "following SELECT TYPE at %C");
4559 reject_statement ();
4562 /* At this point, we've got a nonempty select block. */
4563 cp
= new_level (cp
);
4566 accept_statement (st
);
4570 st
= parse_executable (ST_NONE
);
4578 cp
= new_level (gfc_state_stack
->head
);
4580 gfc_clear_new_st ();
4582 accept_statement (st
);
4588 /* Can't have an executable statement because of
4589 parse_executable(). */
4591 unexpected_statement (st
);
4595 while (st
!= ST_END_SELECT
);
4599 accept_statement (st
);
4600 gfc_current_ns
= gfc_current_ns
->parent
;
4605 /* Parse a SELECT RANK construct. */
4608 parse_select_rank_block (void)
4614 gfc_current_ns
= new_st
.ext
.block
.ns
;
4615 accept_statement (ST_SELECT_RANK
);
4617 cp
= gfc_state_stack
->tail
;
4618 push_state (&s
, COMP_SELECT_RANK
, gfc_new_block
);
4620 /* Make sure that the next statement is a RANK IS or RANK DEFAULT. */
4623 st
= next_statement ();
4626 if (st
== ST_END_SELECT
)
4627 /* Empty SELECT CASE is OK. */
4632 gfc_error ("Expected RANK or RANK DEFAULT "
4633 "following SELECT RANK at %C");
4635 reject_statement ();
4638 /* At this point, we've got a nonempty select block. */
4639 cp
= new_level (cp
);
4642 accept_statement (st
);
4646 st
= parse_executable (ST_NONE
);
4653 cp
= new_level (gfc_state_stack
->head
);
4655 gfc_clear_new_st ();
4657 accept_statement (st
);
4663 /* Can't have an executable statement because of
4664 parse_executable(). */
4666 unexpected_statement (st
);
4670 while (st
!= ST_END_SELECT
);
4674 accept_statement (st
);
4675 gfc_current_ns
= gfc_current_ns
->parent
;
4680 /* Given a symbol, make sure it is not an iteration variable for a DO
4681 statement. This subroutine is called when the symbol is seen in a
4682 context that causes it to become redefined. If the symbol is an
4683 iterator, we generate an error message and return nonzero. */
4686 gfc_check_do_variable (gfc_symtree
*st
)
4693 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
4694 if (s
->do_variable
== st
)
4696 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
4697 "loop beginning at %L", st
->name
, &s
->head
->loc
);
4705 /* Checks to see if the current statement label closes an enddo.
4706 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
4707 an error) if it incorrectly closes an ENDDO. */
4710 check_do_closure (void)
4714 if (gfc_statement_label
== NULL
)
4717 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
4718 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4722 return 0; /* No loops to close */
4724 if (p
->ext
.end_do_label
== gfc_statement_label
)
4726 if (p
== gfc_state_stack
)
4729 gfc_error ("End of nonblock DO statement at %C is within another block");
4733 /* At this point, the label doesn't terminate the innermost loop.
4734 Make sure it doesn't terminate another one. */
4735 for (; p
; p
= p
->previous
)
4736 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4737 && p
->ext
.end_do_label
== gfc_statement_label
)
4739 gfc_error ("End of nonblock DO statement at %C is interwoven "
4740 "with another DO loop");
4748 /* Parse a series of contained program units. */
4750 static void parse_progunit (gfc_statement
);
4753 /* Parse a CRITICAL block. */
4756 parse_critical_block (void)
4759 gfc_state_data s
, *sd
;
4762 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4763 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
4764 gfc_error_now (is_oacc (sd
)
4765 ? G_("CRITICAL block inside of OpenACC region at %C")
4766 : G_("CRITICAL block inside of OpenMP region at %C"));
4768 s
.ext
.end_do_label
= new_st
.label1
;
4770 accept_statement (ST_CRITICAL
);
4771 top
= gfc_state_stack
->tail
;
4773 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
4775 d
= add_statement ();
4776 d
->op
= EXEC_CRITICAL
;
4781 st
= parse_executable (ST_NONE
);
4789 case ST_END_CRITICAL
:
4790 if (s
.ext
.end_do_label
!= NULL
4791 && s
.ext
.end_do_label
!= gfc_statement_label
)
4792 gfc_error_now ("Statement label in END CRITICAL at %C does not "
4793 "match CRITICAL label");
4795 if (gfc_statement_label
!= NULL
)
4797 new_st
.op
= EXEC_NOP
;
4803 unexpected_statement (st
);
4807 while (st
!= ST_END_CRITICAL
);
4810 accept_statement (st
);
4814 /* Set up the local namespace for a BLOCK construct. */
4817 gfc_build_block_ns (gfc_namespace
*parent_ns
)
4819 gfc_namespace
* my_ns
;
4820 static int numblock
= 1;
4822 my_ns
= gfc_get_namespace (parent_ns
, 1);
4823 my_ns
->construct_entities
= 1;
4825 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
4826 code generation (so it must not be NULL).
4827 We set its recursive argument if our container procedure is recursive, so
4828 that local variables are accordingly placed on the stack when it
4829 will be necessary. */
4831 my_ns
->proc_name
= gfc_new_block
;
4835 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
4837 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
4838 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
4839 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
4840 my_ns
->proc_name
->name
, NULL
);
4842 gfc_commit_symbol (my_ns
->proc_name
);
4845 if (parent_ns
->proc_name
)
4846 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
4852 /* Parse a BLOCK construct. */
4855 parse_block_construct (void)
4857 gfc_namespace
* my_ns
;
4858 gfc_namespace
* my_parent
;
4861 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
4863 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4865 new_st
.op
= EXEC_BLOCK
;
4866 new_st
.ext
.block
.ns
= my_ns
;
4867 new_st
.ext
.block
.assoc
= NULL
;
4868 accept_statement (ST_BLOCK
);
4870 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
4871 gfc_current_ns
= my_ns
;
4872 my_parent
= my_ns
->parent
;
4874 parse_progunit (ST_NONE
);
4876 /* Don't depend on the value of gfc_current_ns; it might have been
4877 reset if the block had errors and was cleaned up. */
4878 gfc_current_ns
= my_parent
;
4884 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
4885 behind the scenes with compiler-generated variables. */
4888 parse_associate (void)
4890 gfc_namespace
* my_ns
;
4893 gfc_association_list
* a
;
4895 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
4897 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4899 new_st
.op
= EXEC_BLOCK
;
4900 new_st
.ext
.block
.ns
= my_ns
;
4901 gcc_assert (new_st
.ext
.block
.assoc
);
4903 /* Add all associate-names as BLOCK variables. Creating them is enough
4904 for now, they'll get their values during trans-* phase. */
4905 gfc_current_ns
= my_ns
;
4906 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
4910 gfc_array_ref
*array_ref
;
4912 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
4916 sym
->attr
.flavor
= FL_VARIABLE
;
4918 sym
->declared_at
= a
->where
;
4919 gfc_set_sym_referenced (sym
);
4921 /* Initialize the typespec. It is not available in all cases,
4922 however, as it may only be set on the target during resolution.
4923 Still, sometimes it helps to have it right now -- especially
4924 for parsing component references on the associate-name
4925 in case of association to a derived-type. */
4926 sym
->ts
= a
->target
->ts
;
4928 /* Don’t share the character length information between associate
4929 variable and target if the length is not a compile-time constant,
4930 as we don’t want to touch some other character length variable when
4931 we try to initialize the associate variable’s character length
4933 We do it here rather than later so that expressions referencing the
4934 associate variable will automatically have the correctly setup length
4935 information. If we did it at resolution stage the expressions would
4936 use the original length information, and the variable a new different
4937 one, but only the latter one would be correctly initialized at
4938 translation stage, and the former one would need some additional setup
4940 if (sym
->ts
.type
== BT_CHARACTER
4942 && !(sym
->ts
.u
.cl
->length
4943 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
))
4944 sym
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4946 /* Check if the target expression is array valued. This cannot always
4947 be done by looking at target.rank, because that might not have been
4948 set yet. Therefore traverse the chain of refs, looking for the last
4949 array ref and evaluate that. */
4951 for (ref
= a
->target
->ref
; ref
; ref
= ref
->next
)
4952 if (ref
->type
== REF_ARRAY
)
4953 array_ref
= &ref
->u
.ar
;
4954 if (array_ref
|| a
->target
->rank
)
4961 /* Count the dimension, that have a non-scalar extend. */
4962 for (dim
= 0; dim
< array_ref
->dimen
; ++dim
)
4963 if (array_ref
->dimen_type
[dim
] != DIMEN_ELEMENT
4964 && !(array_ref
->dimen_type
[dim
] == DIMEN_UNKNOWN
4965 && array_ref
->end
[dim
] == NULL
4966 && array_ref
->start
[dim
] != NULL
))
4970 rank
= a
->target
->rank
;
4971 /* When the rank is greater than zero then sym will be an array. */
4972 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
4974 if ((!CLASS_DATA (sym
)->as
&& rank
!= 0)
4975 || (CLASS_DATA (sym
)->as
4976 && CLASS_DATA (sym
)->as
->rank
!= rank
))
4978 /* Don't just (re-)set the attr and as in the sym.ts,
4979 because this modifies the target's attr and as. Copy the
4980 data and do a build_class_symbol. */
4981 symbol_attribute attr
= CLASS_DATA (a
->target
)->attr
;
4982 int corank
= gfc_get_corank (a
->target
);
4987 as
= gfc_get_array_spec ();
4988 as
->type
= AS_DEFERRED
;
4990 as
->corank
= corank
;
4991 attr
.dimension
= rank
? 1 : 0;
4992 attr
.codimension
= corank
? 1 : 0;
4997 attr
.dimension
= attr
.codimension
= 0;
5000 type
= CLASS_DATA (sym
)->ts
;
5001 if (!gfc_build_class_symbol (&type
,
5005 sym
->ts
.type
= BT_CLASS
;
5006 sym
->attr
.class_ok
= 1;
5009 sym
->attr
.class_ok
= 1;
5011 else if ((!sym
->as
&& rank
!= 0)
5012 || (sym
->as
&& sym
->as
->rank
!= rank
))
5014 as
= gfc_get_array_spec ();
5015 as
->type
= AS_DEFERRED
;
5017 as
->corank
= gfc_get_corank (a
->target
);
5019 sym
->attr
.dimension
= 1;
5021 sym
->attr
.codimension
= 1;
5026 accept_statement (ST_ASSOCIATE
);
5027 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
5030 st
= parse_executable (ST_NONE
);
5037 accept_statement (st
);
5038 my_ns
->code
= gfc_state_stack
->head
;
5042 unexpected_statement (st
);
5046 gfc_current_ns
= gfc_current_ns
->parent
;
5051 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
5052 handled inside of parse_executable(), because they aren't really
5056 parse_do_block (void)
5065 s
.ext
.end_do_label
= new_st
.label1
;
5067 if (new_st
.ext
.iterator
!= NULL
)
5069 stree
= new_st
.ext
.iterator
->var
->symtree
;
5070 if (directive_unroll
!= -1)
5072 new_st
.ext
.iterator
->unroll
= directive_unroll
;
5073 directive_unroll
= -1;
5075 if (directive_ivdep
)
5077 new_st
.ext
.iterator
->ivdep
= directive_ivdep
;
5078 directive_ivdep
= false;
5080 if (directive_vector
)
5082 new_st
.ext
.iterator
->vector
= directive_vector
;
5083 directive_vector
= false;
5085 if (directive_novector
)
5087 new_st
.ext
.iterator
->novector
= directive_novector
;
5088 directive_novector
= false;
5094 accept_statement (ST_DO
);
5096 top
= gfc_state_stack
->tail
;
5097 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
5100 s
.do_variable
= stree
;
5102 top
->block
= new_level (top
);
5103 top
->block
->op
= EXEC_DO
;
5106 st
= parse_executable (ST_NONE
);
5114 if (s
.ext
.end_do_label
!= NULL
5115 && s
.ext
.end_do_label
!= gfc_statement_label
)
5116 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
5119 if (gfc_statement_label
!= NULL
)
5121 new_st
.op
= EXEC_NOP
;
5126 case ST_IMPLIED_ENDDO
:
5127 /* If the do-stmt of this DO construct has a do-construct-name,
5128 the corresponding end-do must be an end-do-stmt (with a matching
5129 name, but in that case we must have seen ST_ENDDO first).
5130 We only complain about this in pedantic mode. */
5131 if (gfc_current_block () != NULL
)
5132 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
5133 &gfc_current_block()->declared_at
);
5138 unexpected_statement (st
);
5143 accept_statement (st
);
5147 /* Parse the statements of OpenMP do/parallel do. */
5149 static gfc_statement
5150 parse_omp_do (gfc_statement omp_st
)
5156 accept_statement (omp_st
);
5158 cp
= gfc_state_stack
->tail
;
5159 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5160 np
= new_level (cp
);
5166 st
= next_statement ();
5169 else if (st
== ST_DO
)
5172 unexpected_statement (st
);
5176 if (gfc_statement_label
!= NULL
5177 && gfc_state_stack
->previous
!= NULL
5178 && gfc_state_stack
->previous
->state
== COMP_DO
5179 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5187 there should be no !$OMP END DO. */
5189 return ST_IMPLIED_ENDDO
;
5192 check_do_closure ();
5195 st
= next_statement ();
5196 gfc_statement omp_end_st
= ST_OMP_END_DO
;
5199 case ST_OMP_DISTRIBUTE
: omp_end_st
= ST_OMP_END_DISTRIBUTE
; break;
5200 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5201 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
5203 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5204 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
5206 case ST_OMP_DISTRIBUTE_SIMD
:
5207 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
5209 case ST_OMP_DO
: omp_end_st
= ST_OMP_END_DO
; break;
5210 case ST_OMP_DO_SIMD
: omp_end_st
= ST_OMP_END_DO_SIMD
; break;
5211 case ST_OMP_LOOP
: omp_end_st
= ST_OMP_END_LOOP
; break;
5212 case ST_OMP_PARALLEL_DO
: omp_end_st
= ST_OMP_END_PARALLEL_DO
; break;
5213 case ST_OMP_PARALLEL_DO_SIMD
:
5214 omp_end_st
= ST_OMP_END_PARALLEL_DO_SIMD
;
5216 case ST_OMP_PARALLEL_LOOP
:
5217 omp_end_st
= ST_OMP_END_PARALLEL_LOOP
;
5219 case ST_OMP_SIMD
: omp_end_st
= ST_OMP_END_SIMD
; break;
5220 case ST_OMP_TARGET_PARALLEL_DO
:
5221 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO
;
5223 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5224 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO_SIMD
;
5226 case ST_OMP_TARGET_PARALLEL_LOOP
:
5227 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_LOOP
;
5229 case ST_OMP_TARGET_SIMD
: omp_end_st
= ST_OMP_END_TARGET_SIMD
; break;
5230 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5231 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
5233 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5234 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5236 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5237 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5239 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5240 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
5242 case ST_OMP_TARGET_TEAMS_LOOP
:
5243 omp_end_st
= ST_OMP_END_TARGET_TEAMS_LOOP
;
5245 case ST_OMP_TASKLOOP
: omp_end_st
= ST_OMP_END_TASKLOOP
; break;
5246 case ST_OMP_TASKLOOP_SIMD
: omp_end_st
= ST_OMP_END_TASKLOOP_SIMD
; break;
5247 case ST_OMP_MASKED_TASKLOOP
: omp_end_st
= ST_OMP_END_MASKED_TASKLOOP
; break;
5248 case ST_OMP_MASKED_TASKLOOP_SIMD
:
5249 omp_end_st
= ST_OMP_END_MASKED_TASKLOOP_SIMD
;
5251 case ST_OMP_MASTER_TASKLOOP
: omp_end_st
= ST_OMP_END_MASTER_TASKLOOP
; break;
5252 case ST_OMP_MASTER_TASKLOOP_SIMD
:
5253 omp_end_st
= ST_OMP_END_MASTER_TASKLOOP_SIMD
;
5255 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
5256 omp_end_st
= ST_OMP_END_PARALLEL_MASKED_TASKLOOP
;
5258 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
5259 omp_end_st
= ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
;
5261 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
5262 omp_end_st
= ST_OMP_END_PARALLEL_MASTER_TASKLOOP
;
5264 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
5265 omp_end_st
= ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
;
5267 case ST_OMP_TEAMS_DISTRIBUTE
:
5268 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5270 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5271 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5273 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5274 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5276 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5277 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
5279 case ST_OMP_TEAMS_LOOP
:
5280 omp_end_st
= ST_OMP_END_TEAMS_LOOP
;
5282 default: gcc_unreachable ();
5284 if (st
== omp_end_st
)
5286 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
5287 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5289 gcc_assert (new_st
.op
== EXEC_NOP
);
5290 gfc_clear_new_st ();
5291 gfc_commit_symbols ();
5292 gfc_warning_check ();
5293 st
= next_statement ();
5299 /* Parse the statements of OpenMP atomic directive. */
5301 static gfc_statement
5302 parse_omp_oacc_atomic (bool omp_p
)
5304 gfc_statement st
, st_atomic
, st_end_atomic
;
5311 st_atomic
= ST_OMP_ATOMIC
;
5312 st_end_atomic
= ST_OMP_END_ATOMIC
;
5316 st_atomic
= ST_OACC_ATOMIC
;
5317 st_end_atomic
= ST_OACC_END_ATOMIC
;
5319 accept_statement (st_atomic
);
5321 cp
= gfc_state_stack
->tail
;
5322 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5323 np
= new_level (cp
);
5326 np
->ext
.omp_clauses
= cp
->ext
.omp_clauses
;
5327 cp
->ext
.omp_clauses
= NULL
;
5328 count
= 1 + np
->ext
.omp_clauses
->capture
;
5332 st
= next_statement ();
5335 else if (np
->ext
.omp_clauses
->compare
5336 && (st
== ST_SIMPLE_IF
|| st
== ST_IF_BLOCK
))
5339 if (st
== ST_IF_BLOCK
)
5342 /* With else (or elseif). */
5343 if (gfc_state_stack
->tail
->block
->block
)
5346 accept_statement (st
);
5348 else if (st
== ST_ASSIGNMENT
5349 && (!np
->ext
.omp_clauses
->compare
5350 || np
->ext
.omp_clauses
->capture
))
5352 accept_statement (st
);
5356 unexpected_statement (st
);
5361 st
= next_statement ();
5362 if (st
== st_end_atomic
)
5364 gfc_clear_new_st ();
5365 gfc_commit_symbols ();
5366 gfc_warning_check ();
5367 st
= next_statement ();
5373 /* Parse the statements of an OpenACC structured block. */
5376 parse_oacc_structured_block (gfc_statement acc_st
)
5378 gfc_statement st
, acc_end_st
;
5380 gfc_state_data s
, *sd
;
5382 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5383 if (sd
->state
== COMP_CRITICAL
)
5384 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5386 accept_statement (acc_st
);
5388 cp
= gfc_state_stack
->tail
;
5389 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5390 np
= new_level (cp
);
5395 case ST_OACC_PARALLEL
:
5396 acc_end_st
= ST_OACC_END_PARALLEL
;
5398 case ST_OACC_KERNELS
:
5399 acc_end_st
= ST_OACC_END_KERNELS
;
5401 case ST_OACC_SERIAL
:
5402 acc_end_st
= ST_OACC_END_SERIAL
;
5405 acc_end_st
= ST_OACC_END_DATA
;
5407 case ST_OACC_HOST_DATA
:
5408 acc_end_st
= ST_OACC_END_HOST_DATA
;
5416 st
= parse_executable (ST_NONE
);
5419 else if (st
!= acc_end_st
)
5421 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
5422 reject_statement ();
5425 while (st
!= acc_end_st
);
5427 gcc_assert (new_st
.op
== EXEC_NOP
);
5429 gfc_clear_new_st ();
5430 gfc_commit_symbols ();
5431 gfc_warning_check ();
5435 /* Parse the statements of OpenACC 'loop', or combined compute 'loop'. */
5437 static gfc_statement
5438 parse_oacc_loop (gfc_statement acc_st
)
5442 gfc_state_data s
, *sd
;
5444 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5445 if (sd
->state
== COMP_CRITICAL
)
5446 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5448 accept_statement (acc_st
);
5450 cp
= gfc_state_stack
->tail
;
5451 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5452 np
= new_level (cp
);
5458 st
= next_statement ();
5461 else if (st
== ST_DO
)
5465 gfc_error ("Expected DO loop at %C");
5466 reject_statement ();
5471 if (gfc_statement_label
!= NULL
5472 && gfc_state_stack
->previous
!= NULL
5473 && gfc_state_stack
->previous
->state
== COMP_DO
5474 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5477 return ST_IMPLIED_ENDDO
;
5480 check_do_closure ();
5483 st
= next_statement ();
5484 if (st
== ST_OACC_END_LOOP
)
5485 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
5486 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
5487 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
5488 (acc_st
== ST_OACC_SERIAL_LOOP
&& st
== ST_OACC_END_SERIAL_LOOP
) ||
5489 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
5491 gcc_assert (new_st
.op
== EXEC_NOP
);
5492 gfc_clear_new_st ();
5493 gfc_commit_symbols ();
5494 gfc_warning_check ();
5495 st
= next_statement ();
5501 /* Parse the statements of an OpenMP structured block. */
5503 static gfc_statement
5504 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
5506 gfc_statement st
, omp_end_st
;
5510 accept_statement (omp_st
);
5512 cp
= gfc_state_stack
->tail
;
5513 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5514 np
= new_level (cp
);
5520 case ST_OMP_PARALLEL
:
5521 omp_end_st
= ST_OMP_END_PARALLEL
;
5523 case ST_OMP_PARALLEL_MASKED
:
5524 omp_end_st
= ST_OMP_END_PARALLEL_MASKED
;
5526 case ST_OMP_PARALLEL_MASTER
:
5527 omp_end_st
= ST_OMP_END_PARALLEL_MASTER
;
5529 case ST_OMP_PARALLEL_SECTIONS
:
5530 omp_end_st
= ST_OMP_END_PARALLEL_SECTIONS
;
5533 omp_end_st
= ST_OMP_END_SCOPE
;
5535 case ST_OMP_SECTIONS
:
5536 omp_end_st
= ST_OMP_END_SECTIONS
;
5538 case ST_OMP_ORDERED
:
5539 omp_end_st
= ST_OMP_END_ORDERED
;
5541 case ST_OMP_CRITICAL
:
5542 omp_end_st
= ST_OMP_END_CRITICAL
;
5545 omp_end_st
= ST_OMP_END_MASKED
;
5548 omp_end_st
= ST_OMP_END_MASTER
;
5551 omp_end_st
= ST_OMP_END_SINGLE
;
5554 omp_end_st
= ST_OMP_END_TARGET
;
5556 case ST_OMP_TARGET_DATA
:
5557 omp_end_st
= ST_OMP_END_TARGET_DATA
;
5559 case ST_OMP_TARGET_PARALLEL
:
5560 omp_end_st
= ST_OMP_END_TARGET_PARALLEL
;
5562 case ST_OMP_TARGET_TEAMS
:
5563 omp_end_st
= ST_OMP_END_TARGET_TEAMS
;
5566 omp_end_st
= ST_OMP_END_TASK
;
5568 case ST_OMP_TASKGROUP
:
5569 omp_end_st
= ST_OMP_END_TASKGROUP
;
5572 omp_end_st
= ST_OMP_END_TEAMS
;
5574 case ST_OMP_TEAMS_DISTRIBUTE
:
5575 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5577 case ST_OMP_DISTRIBUTE
:
5578 omp_end_st
= ST_OMP_END_DISTRIBUTE
;
5580 case ST_OMP_WORKSHARE
:
5581 omp_end_st
= ST_OMP_END_WORKSHARE
;
5583 case ST_OMP_PARALLEL_WORKSHARE
:
5584 omp_end_st
= ST_OMP_END_PARALLEL_WORKSHARE
;
5590 bool block_construct
= false;
5591 gfc_namespace
*my_ns
= NULL
;
5592 gfc_namespace
*my_parent
= NULL
;
5594 st
= next_statement ();
5598 /* Adjust state to a strictly-structured block, now that we found that
5599 the body starts with a BLOCK construct. */
5600 s
.state
= COMP_OMP_STRICTLY_STRUCTURED_BLOCK
;
5602 block_construct
= true;
5603 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
5605 my_ns
= gfc_build_block_ns (gfc_current_ns
);
5606 gfc_current_ns
= my_ns
;
5607 my_parent
= my_ns
->parent
;
5609 new_st
.op
= EXEC_BLOCK
;
5610 new_st
.ext
.block
.ns
= my_ns
;
5611 new_st
.ext
.block
.assoc
= NULL
;
5612 accept_statement (ST_BLOCK
);
5613 st
= parse_spec (ST_NONE
);
5618 if (workshare_stmts_only
)
5620 /* Inside of !$omp workshare, only
5623 where statements and constructs
5624 forall statements and constructs
5628 are allowed. For !$omp critical these
5629 restrictions apply recursively. */
5642 accept_statement (st
);
5645 case ST_WHERE_BLOCK
:
5646 parse_where_block ();
5649 case ST_FORALL_BLOCK
:
5650 parse_forall_block ();
5653 case ST_OMP_PARALLEL
:
5654 case ST_OMP_PARALLEL_MASKED
:
5655 case ST_OMP_PARALLEL_MASTER
:
5656 case ST_OMP_PARALLEL_SECTIONS
:
5657 st
= parse_omp_structured_block (st
, false);
5660 case ST_OMP_PARALLEL_WORKSHARE
:
5661 case ST_OMP_CRITICAL
:
5662 st
= parse_omp_structured_block (st
, true);
5665 case ST_OMP_PARALLEL_DO
:
5666 case ST_OMP_PARALLEL_DO_SIMD
:
5667 st
= parse_omp_do (st
);
5671 st
= parse_omp_oacc_atomic (true);
5682 st
= next_statement ();
5686 st
= parse_executable (st
);
5689 else if (st
== ST_OMP_SECTION
5690 && (omp_st
== ST_OMP_SECTIONS
5691 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
5693 np
= new_level (np
);
5696 st
= next_statement ();
5698 else if (block_construct
&& st
== ST_END_BLOCK
)
5700 accept_statement (st
);
5701 gfc_current_ns
= my_parent
;
5704 st
= next_statement ();
5705 if (st
== omp_end_st
)
5707 accept_statement (st
);
5708 st
= next_statement ();
5712 else if (st
!= omp_end_st
)
5714 unexpected_statement (st
);
5715 st
= next_statement ();
5718 while (st
!= omp_end_st
);
5722 case EXEC_OMP_END_NOWAIT
:
5723 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5725 case EXEC_OMP_END_CRITICAL
:
5726 if (((cp
->ext
.omp_clauses
->critical_name
== NULL
)
5727 ^ (new_st
.ext
.omp_name
== NULL
))
5728 || (new_st
.ext
.omp_name
!= NULL
5729 && strcmp (cp
->ext
.omp_clauses
->critical_name
,
5730 new_st
.ext
.omp_name
) != 0))
5731 gfc_error ("Name after !$omp critical and !$omp end critical does "
5733 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
5734 new_st
.ext
.omp_name
= NULL
;
5736 case EXEC_OMP_END_SINGLE
:
5737 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
5738 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
5739 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
5740 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
5748 gfc_clear_new_st ();
5749 gfc_commit_symbols ();
5750 gfc_warning_check ();
5752 st
= next_statement ();
5757 /* Accept a series of executable statements. We return the first
5758 statement that doesn't fit to the caller. Any block statements are
5759 passed on to the correct handler, which usually passes the buck
5762 static gfc_statement
5763 parse_executable (gfc_statement st
)
5768 st
= next_statement ();
5772 close_flag
= check_do_closure ();
5777 case ST_END_PROGRAM
:
5780 case ST_END_FUNCTION
:
5785 case ST_END_SUBROUTINE
:
5790 case ST_SELECT_CASE
:
5791 gfc_error ("%s statement at %C cannot terminate a non-block "
5792 "DO loop", gfc_ascii_statement (st
));
5805 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
5806 "first executable statement");
5812 accept_statement (st
);
5813 if (close_flag
== 1)
5814 return ST_IMPLIED_ENDDO
;
5818 parse_block_construct ();
5829 case ST_SELECT_CASE
:
5830 parse_select_block ();
5833 case ST_SELECT_TYPE
:
5834 parse_select_type_block ();
5837 case ST_SELECT_RANK
:
5838 parse_select_rank_block ();
5843 if (check_do_closure () == 1)
5844 return ST_IMPLIED_ENDDO
;
5848 parse_critical_block ();
5851 case ST_WHERE_BLOCK
:
5852 parse_where_block ();
5855 case ST_FORALL_BLOCK
:
5856 parse_forall_block ();
5859 case ST_OACC_PARALLEL_LOOP
:
5860 case ST_OACC_KERNELS_LOOP
:
5861 case ST_OACC_SERIAL_LOOP
:
5863 st
= parse_oacc_loop (st
);
5864 if (st
== ST_IMPLIED_ENDDO
)
5868 case ST_OACC_PARALLEL
:
5869 case ST_OACC_KERNELS
:
5870 case ST_OACC_SERIAL
:
5872 case ST_OACC_HOST_DATA
:
5873 parse_oacc_structured_block (st
);
5876 case ST_OMP_PARALLEL
:
5877 case ST_OMP_PARALLEL_MASKED
:
5878 case ST_OMP_PARALLEL_MASTER
:
5879 case ST_OMP_PARALLEL_SECTIONS
:
5880 case ST_OMP_ORDERED
:
5881 case ST_OMP_CRITICAL
:
5885 case ST_OMP_SECTIONS
:
5888 case ST_OMP_TARGET_DATA
:
5889 case ST_OMP_TARGET_PARALLEL
:
5890 case ST_OMP_TARGET_TEAMS
:
5893 case ST_OMP_TASKGROUP
:
5894 st
= parse_omp_structured_block (st
, false);
5897 case ST_OMP_WORKSHARE
:
5898 case ST_OMP_PARALLEL_WORKSHARE
:
5899 st
= parse_omp_structured_block (st
, true);
5902 case ST_OMP_DISTRIBUTE
:
5903 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5904 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5905 case ST_OMP_DISTRIBUTE_SIMD
:
5907 case ST_OMP_DO_SIMD
:
5909 case ST_OMP_PARALLEL_DO
:
5910 case ST_OMP_PARALLEL_DO_SIMD
:
5911 case ST_OMP_PARALLEL_LOOP
:
5912 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
5913 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
5914 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
5915 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
5916 case ST_OMP_MASKED_TASKLOOP
:
5917 case ST_OMP_MASKED_TASKLOOP_SIMD
:
5918 case ST_OMP_MASTER_TASKLOOP
:
5919 case ST_OMP_MASTER_TASKLOOP_SIMD
:
5921 case ST_OMP_TARGET_PARALLEL_DO
:
5922 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5923 case ST_OMP_TARGET_PARALLEL_LOOP
:
5924 case ST_OMP_TARGET_SIMD
:
5925 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5926 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5927 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5928 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5929 case ST_OMP_TARGET_TEAMS_LOOP
:
5930 case ST_OMP_TASKLOOP
:
5931 case ST_OMP_TASKLOOP_SIMD
:
5932 case ST_OMP_TEAMS_DISTRIBUTE
:
5933 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5934 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5935 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5936 case ST_OMP_TEAMS_LOOP
:
5937 st
= parse_omp_do (st
);
5938 if (st
== ST_IMPLIED_ENDDO
)
5942 case ST_OACC_ATOMIC
:
5943 st
= parse_omp_oacc_atomic (false);
5947 st
= parse_omp_oacc_atomic (true);
5954 if (directive_unroll
!= -1)
5955 gfc_error ("%<GCC unroll%> directive not at the start of a loop at %C");
5957 if (directive_ivdep
)
5958 gfc_error ("%<GCC ivdep%> directive not at the start of a loop at %C");
5960 if (directive_vector
)
5961 gfc_error ("%<GCC vector%> directive not at the start of a loop at %C");
5963 if (directive_novector
)
5964 gfc_error ("%<GCC novector%> "
5965 "directive not at the start of a loop at %C");
5967 st
= next_statement ();
5972 /* Fix the symbols for sibling functions. These are incorrectly added to
5973 the child namespace as the parser didn't know about this procedure. */
5976 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
5980 gfc_symbol
*old_sym
;
5982 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
5984 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
5986 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
5987 goto fixup_contained
;
5989 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
5990 && sym
->attr
.generic
&& sym
->attr
.function
)
5991 ||(sym
->attr
.flavor
== FL_DERIVED
5992 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
5993 goto fixup_contained
;
5995 old_sym
= st
->n
.sym
;
5996 if (old_sym
->ns
== ns
5997 && !old_sym
->attr
.contained
5999 /* By 14.6.1.3, host association should be excluded
6000 for the following. */
6001 && !(old_sym
->attr
.external
6002 || (old_sym
->ts
.type
!= BT_UNKNOWN
6003 && !old_sym
->attr
.implicit_type
)
6004 || old_sym
->attr
.flavor
== FL_PARAMETER
6005 || old_sym
->attr
.use_assoc
6006 || old_sym
->attr
.in_common
6007 || old_sym
->attr
.in_equivalence
6008 || old_sym
->attr
.data
6009 || old_sym
->attr
.dummy
6010 || old_sym
->attr
.result
6011 || old_sym
->attr
.dimension
6012 || old_sym
->attr
.allocatable
6013 || old_sym
->attr
.intrinsic
6014 || old_sym
->attr
.generic
6015 || old_sym
->attr
.flavor
== FL_NAMELIST
6016 || old_sym
->attr
.flavor
== FL_LABEL
6017 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
6019 /* Replace it with the symbol from the parent namespace. */
6023 gfc_release_symbol (old_sym
);
6027 /* Do the same for any contained procedures. */
6028 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
6033 parse_contained (int module
)
6035 gfc_namespace
*ns
, *parent_ns
, *tmp
;
6036 gfc_state_data s1
, s2
;
6041 int contains_statements
= 0;
6044 push_state (&s1
, COMP_CONTAINS
, NULL
);
6045 parent_ns
= gfc_current_ns
;
6049 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
6051 gfc_current_ns
->sibling
= parent_ns
->contained
;
6052 parent_ns
->contained
= gfc_current_ns
;
6055 /* Process the next available statement. We come here if we got an error
6056 and rejected the last statement. */
6057 old_loc
= gfc_current_locus
;
6058 st
= next_statement ();
6067 contains_statements
= 1;
6068 accept_statement (st
);
6071 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
6074 /* For internal procedures, create/update the symbol in the
6075 parent namespace. */
6079 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
6080 gfc_error ("Contained procedure %qs at %C is already "
6081 "ambiguous", gfc_new_block
->name
);
6084 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
6086 &gfc_new_block
->declared_at
))
6088 if (st
== ST_FUNCTION
)
6089 gfc_add_function (&sym
->attr
, sym
->name
,
6090 &gfc_new_block
->declared_at
);
6092 gfc_add_subroutine (&sym
->attr
, sym
->name
,
6093 &gfc_new_block
->declared_at
);
6097 gfc_commit_symbols ();
6100 sym
= gfc_new_block
;
6102 /* Mark this as a contained function, so it isn't replaced
6103 by other module functions. */
6104 sym
->attr
.contained
= 1;
6106 /* Set implicit_pure so that it can be reset if any of the
6107 tests for purity fail. This is used for some optimisation
6108 during translation. */
6109 if (!sym
->attr
.pure
)
6110 sym
->attr
.implicit_pure
= 1;
6112 parse_progunit (ST_NONE
);
6114 /* Fix up any sibling functions that refer to this one. */
6115 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
6116 /* Or refer to any of its alternate entry points. */
6117 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
6118 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
6120 gfc_current_ns
->code
= s2
.head
;
6121 gfc_current_ns
= parent_ns
;
6126 /* These statements are associated with the end of the host unit. */
6127 case ST_END_FUNCTION
:
6129 case ST_END_SUBMODULE
:
6130 case ST_END_PROGRAM
:
6131 case ST_END_SUBROUTINE
:
6132 accept_statement (st
);
6133 gfc_current_ns
->code
= s1
.head
;
6137 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
6138 gfc_ascii_statement (st
));
6139 reject_statement ();
6145 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
6146 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
6147 && st
!= ST_END_PROGRAM
);
6149 /* The first namespace in the list is guaranteed to not have
6150 anything (worthwhile) in it. */
6151 tmp
= gfc_current_ns
;
6152 gfc_current_ns
= parent_ns
;
6153 if (seen_error
&& tmp
->refs
> 1)
6154 gfc_free_namespace (tmp
);
6156 ns
= gfc_current_ns
->contained
;
6157 gfc_current_ns
->contained
= ns
->sibling
;
6158 gfc_free_namespace (ns
);
6161 if (!contains_statements
)
6162 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
6163 "FUNCTION or SUBROUTINE statement at %L", &old_loc
);
6167 /* The result variable in a MODULE PROCEDURE needs to be created and
6168 its characteristics copied from the interface since it is neither
6169 declared in the procedure declaration nor in the specification
6173 get_modproc_result (void)
6176 if (gfc_state_stack
->previous
6177 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
6178 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
6180 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
6182 && proc
->attr
.function
6184 && proc
->tlink
->result
6185 && proc
->tlink
->result
!= proc
->tlink
)
6187 gfc_copy_dummy_sym (&proc
->result
, proc
->tlink
->result
, 1);
6188 gfc_set_sym_referenced (proc
->result
);
6189 proc
->result
->attr
.if_source
= IFSRC_DECL
;
6190 gfc_commit_symbol (proc
->result
);
6196 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
6199 parse_progunit (gfc_statement st
)
6204 gfc_adjust_builtins ();
6207 && gfc_new_block
->abr_modproc_decl
6208 && gfc_new_block
->attr
.function
)
6209 get_modproc_result ();
6211 st
= parse_spec (st
);
6218 /* This is not allowed within BLOCK! */
6219 if (gfc_current_state () != COMP_BLOCK
)
6224 accept_statement (st
);
6231 if (gfc_current_state () == COMP_FUNCTION
)
6232 gfc_check_function_type (gfc_current_ns
);
6237 st
= parse_executable (st
);
6245 /* This is not allowed within BLOCK! */
6246 if (gfc_current_state () != COMP_BLOCK
)
6251 accept_statement (st
);
6258 unexpected_statement (st
);
6259 reject_statement ();
6260 st
= next_statement ();
6266 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
6267 if (p
->state
== COMP_CONTAINS
)
6270 if (gfc_find_state (COMP_MODULE
) == true
6271 || gfc_find_state (COMP_SUBMODULE
) == true)
6276 gfc_error ("CONTAINS statement at %C is already in a contained "
6278 reject_statement ();
6279 st
= next_statement ();
6283 parse_contained (0);
6286 gfc_current_ns
->code
= gfc_state_stack
->head
;
6290 /* Come here to complain about a global symbol already in use as
6294 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
6299 where
= &gfc_current_locus
;
6309 case GSYM_SUBROUTINE
:
6310 name
= "SUBROUTINE";
6315 case GSYM_BLOCK_DATA
:
6316 name
= "BLOCK DATA";
6327 if (sym
->binding_label
)
6328 gfc_error ("Global binding name %qs at %L is already being used "
6329 "as a %s at %L", sym
->binding_label
, where
, name
,
6332 gfc_error ("Global name %qs at %L is already being used as "
6333 "a %s at %L", sym
->name
, where
, name
, &sym
->where
);
6337 if (sym
->binding_label
)
6338 gfc_error ("Global binding name %qs at %L is already being used "
6339 "at %L", sym
->binding_label
, where
, &sym
->where
);
6341 gfc_error ("Global name %qs at %L is already being used at %L",
6342 sym
->name
, where
, &sym
->where
);
6347 /* Parse a block data program unit. */
6350 parse_block_data (void)
6353 static locus blank_locus
;
6354 static int blank_block
=0;
6357 gfc_current_ns
->proc_name
= gfc_new_block
;
6358 gfc_current_ns
->is_block_data
= 1;
6360 if (gfc_new_block
== NULL
)
6363 gfc_error ("Blank BLOCK DATA at %C conflicts with "
6364 "prior BLOCK DATA at %L", &blank_locus
);
6368 blank_locus
= gfc_current_locus
;
6373 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6375 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
6376 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6379 s
->type
= GSYM_BLOCK_DATA
;
6380 s
->where
= gfc_new_block
->declared_at
;
6385 st
= parse_spec (ST_NONE
);
6387 while (st
!= ST_END_BLOCK_DATA
)
6389 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
6390 gfc_ascii_statement (st
));
6391 reject_statement ();
6392 st
= next_statement ();
6397 /* Following the association of the ancestor (sub)module symbols, they
6398 must be set host rather than use associated and all must be public.
6399 They are flagged up by 'used_in_submodule' so that they can be set
6400 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
6401 linker chokes on multiple symbol definitions. */
6404 set_syms_host_assoc (gfc_symbol
*sym
)
6407 const char dot
[2] = ".";
6408 /* Symbols take the form module.submodule_ or module.name_. */
6409 char parent1
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
6410 char parent2
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
6415 if (sym
->attr
.module_procedure
)
6416 sym
->attr
.external
= 0;
6418 sym
->attr
.use_assoc
= 0;
6419 sym
->attr
.host_assoc
= 1;
6420 sym
->attr
.used_in_submodule
=1;
6422 if (sym
->attr
.flavor
== FL_DERIVED
)
6424 /* Derived types with PRIVATE components that are declared in
6425 modules other than the parent module must not be changed to be
6426 PUBLIC. The 'use-assoc' attribute must be reset so that the
6427 test in symbol.cc(gfc_find_component) works correctly. This is
6428 not necessary for PRIVATE symbols since they are not read from
6430 memset(parent1
, '\0', sizeof(parent1
));
6431 memset(parent2
, '\0', sizeof(parent2
));
6432 strcpy (parent1
, gfc_new_block
->name
);
6433 strcpy (parent2
, sym
->module
);
6434 if (strcmp (strtok (parent1
, dot
), strtok (parent2
, dot
)) == 0)
6436 for (c
= sym
->components
; c
; c
= c
->next
)
6437 c
->attr
.access
= ACCESS_PUBLIC
;
6441 sym
->attr
.use_assoc
= 1;
6442 sym
->attr
.host_assoc
= 0;
6447 /* Parse a module subprogram. */
6456 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6457 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
6458 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6461 s
->type
= GSYM_MODULE
;
6462 s
->where
= gfc_new_block
->declared_at
;
6466 /* Something is nulling the module_list after this point. This is good
6467 since it allows us to 'USE' the parent modules that the submodule
6468 inherits and to set (most) of the symbols as host associated. */
6469 if (gfc_current_state () == COMP_SUBMODULE
)
6472 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
6475 st
= parse_spec (ST_NONE
);
6485 parse_contained (1);
6489 case ST_END_SUBMODULE
:
6490 accept_statement (st
);
6494 gfc_error ("Unexpected %s statement in MODULE at %C",
6495 gfc_ascii_statement (st
));
6498 reject_statement ();
6499 st
= next_statement ();
6503 /* Make sure not to free the namespace twice on error. */
6505 s
->ns
= gfc_current_ns
;
6509 /* Add a procedure name to the global symbol table. */
6512 add_global_procedure (bool sub
)
6516 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
6517 name is a global identifier. */
6518 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
6520 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6523 || (s
->type
!= GSYM_UNKNOWN
6524 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
6526 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6527 /* Silence follow-up errors. */
6528 gfc_new_block
->binding_label
= NULL
;
6532 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
6533 s
->sym_name
= gfc_new_block
->name
;
6534 s
->where
= gfc_new_block
->declared_at
;
6536 s
->ns
= gfc_current_ns
;
6540 /* Don't add the symbol multiple times. */
6541 if (gfc_new_block
->binding_label
6542 && (!gfc_notification_std (GFC_STD_F2008
)
6543 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
6545 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
, true);
6548 || (s
->type
!= GSYM_UNKNOWN
6549 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
6551 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6552 /* Silence follow-up errors. */
6553 gfc_new_block
->binding_label
= NULL
;
6557 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
6558 s
->sym_name
= gfc_new_block
->name
;
6559 s
->binding_label
= gfc_new_block
->binding_label
;
6560 s
->where
= gfc_new_block
->declared_at
;
6562 s
->ns
= gfc_current_ns
;
6568 /* Add a program to the global symbol table. */
6571 add_global_program (void)
6575 if (gfc_new_block
== NULL
)
6577 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6579 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
6580 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6583 s
->type
= GSYM_PROGRAM
;
6584 s
->where
= gfc_new_block
->declared_at
;
6586 s
->ns
= gfc_current_ns
;
6591 /* Resolve all the program units. */
6593 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6595 gfc_derived_types
= NULL
;
6596 gfc_current_ns
= gfc_global_ns_list
;
6597 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6599 if (gfc_current_ns
->proc_name
6600 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6601 continue; /* Already resolved. */
6603 if (gfc_current_ns
->proc_name
)
6604 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6605 gfc_resolve (gfc_current_ns
);
6606 gfc_current_ns
->derived_types
= gfc_derived_types
;
6607 gfc_derived_types
= NULL
;
6613 clean_up_modules (gfc_gsymbol
*&gsym
)
6618 clean_up_modules (gsym
->left
);
6619 clean_up_modules (gsym
->right
);
6621 if (gsym
->type
!= GSYM_MODULE
)
6626 gfc_current_ns
= gsym
->ns
;
6627 gfc_derived_types
= gfc_current_ns
->derived_types
;
6636 /* Translate all the program units. This could be in a different order
6637 to resolution if there are forward references in the file. */
6639 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6643 gfc_current_ns
= gfc_global_ns_list
;
6644 gfc_get_errors (NULL
, &errors
);
6646 /* We first translate all modules to make sure that later parts
6647 of the program can use the decl. Then we translate the nonmodules. */
6649 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6651 if (!gfc_current_ns
->proc_name
6652 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6655 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6656 gfc_derived_types
= gfc_current_ns
->derived_types
;
6657 gfc_generate_module_code (gfc_current_ns
);
6658 gfc_current_ns
->translated
= 1;
6661 gfc_current_ns
= gfc_global_ns_list
;
6662 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6664 if (gfc_current_ns
->proc_name
6665 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6668 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6669 gfc_derived_types
= gfc_current_ns
->derived_types
;
6670 gfc_generate_code (gfc_current_ns
);
6671 gfc_current_ns
->translated
= 1;
6674 /* Clean up all the namespaces after translation. */
6675 gfc_current_ns
= gfc_global_ns_list
;
6676 for (;gfc_current_ns
;)
6680 if (gfc_current_ns
->proc_name
6681 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6683 gfc_current_ns
= gfc_current_ns
->sibling
;
6687 ns
= gfc_current_ns
->sibling
;
6688 gfc_derived_types
= gfc_current_ns
->derived_types
;
6690 gfc_current_ns
= ns
;
6693 clean_up_modules (gfc_gsym_root
);
6697 /* Top level parser. */
6700 gfc_parse_file (void)
6702 int seen_program
, errors_before
, errors
;
6703 gfc_state_data top
, s
;
6706 gfc_namespace
*next
;
6708 gfc_start_source_files ();
6710 top
.state
= COMP_NONE
;
6712 top
.previous
= NULL
;
6713 top
.head
= top
.tail
= NULL
;
6714 top
.do_variable
= NULL
;
6716 gfc_state_stack
= &top
;
6718 gfc_clear_new_st ();
6720 gfc_statement_label
= NULL
;
6722 if (setjmp (eof_buf
))
6723 return false; /* Come here on unexpected EOF */
6725 /* Prepare the global namespace that will contain the
6727 gfc_global_ns_list
= next
= NULL
;
6732 /* Exit early for empty files. */
6736 in_specification_block
= true;
6739 st
= next_statement ();
6748 goto duplicate_main
;
6750 prog_locus
= gfc_current_locus
;
6752 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6753 main_program_symbol (gfc_current_ns
, gfc_new_block
->name
);
6754 accept_statement (st
);
6755 add_global_program ();
6756 parse_progunit (ST_NONE
);
6760 add_global_procedure (true);
6761 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
6762 accept_statement (st
);
6763 parse_progunit (ST_NONE
);
6767 add_global_procedure (false);
6768 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
6769 accept_statement (st
);
6770 parse_progunit (ST_NONE
);
6774 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
6775 accept_statement (st
);
6776 parse_block_data ();
6780 push_state (&s
, COMP_MODULE
, gfc_new_block
);
6781 accept_statement (st
);
6783 gfc_get_errors (NULL
, &errors_before
);
6788 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
6789 accept_statement (st
);
6791 gfc_get_errors (NULL
, &errors_before
);
6795 /* Anything else starts a nameless main program block. */
6798 goto duplicate_main
;
6800 prog_locus
= gfc_current_locus
;
6802 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6803 main_program_symbol (gfc_current_ns
, "MAIN__");
6804 parse_progunit (st
);
6808 /* Handle the non-program units. */
6809 gfc_current_ns
->code
= s
.head
;
6811 gfc_resolve (gfc_current_ns
);
6813 /* Fix the implicit_pure attribute for those procedures who should
6815 while (gfc_fix_implicit_pure (gfc_current_ns
))
6818 /* Dump the parse tree if requested. */
6819 if (flag_dump_fortran_original
)
6820 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6822 gfc_get_errors (NULL
, &errors
);
6823 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
6825 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
6826 gfc_current_ns
->derived_types
= gfc_derived_types
;
6827 gfc_derived_types
= NULL
;
6833 gfc_generate_code (gfc_current_ns
);
6841 /* The main program and non-contained procedures are put
6842 in the global namespace list, so that they can be processed
6843 later and all their interfaces resolved. */
6844 gfc_current_ns
->code
= s
.head
;
6847 for (; next
->sibling
; next
= next
->sibling
)
6849 next
->sibling
= gfc_current_ns
;
6852 gfc_global_ns_list
= gfc_current_ns
;
6854 next
= gfc_current_ns
;
6860 /* Do the resolution. */
6861 resolve_all_program_units (gfc_global_ns_list
);
6863 /* Go through all top-level namespaces and unset the implicit_pure
6864 attribute for any procedures that call something not pure or
6865 implicit_pure. Because the a procedure marked as not implicit_pure
6866 in one sweep may be called by another routine, we repeat this
6867 process until there are no more changes. */
6872 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6873 gfc_current_ns
= gfc_current_ns
->sibling
)
6875 if (gfc_fix_implicit_pure (gfc_current_ns
))
6881 /* Fixup for external procedures and resolve 'omp requires'. */
6883 bool omp_target_seen
;
6885 omp_target_seen
= false;
6886 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6887 gfc_current_ns
= gfc_current_ns
->sibling
)
6889 omp_requires
|= gfc_current_ns
->omp_requires
;
6890 omp_target_seen
|= gfc_current_ns
->omp_target_seen
;
6891 gfc_check_externals (gfc_current_ns
);
6893 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6894 gfc_current_ns
= gfc_current_ns
->sibling
)
6895 gfc_check_omp_requires (gfc_current_ns
, omp_requires
);
6897 /* Populate omp_requires_mask (needed for resolving OpenMP
6898 metadirectives and declare variant). */
6899 switch (omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
6901 case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST
:
6903 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_SEQ_CST
);
6905 case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL
:
6907 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_ACQ_REL
);
6909 case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED
:
6911 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_RELAXED
);
6915 if (omp_target_seen
)
6916 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
6917 | OMP_REQUIRES_TARGET_USED
);
6918 if (omp_requires
& OMP_REQ_REVERSE_OFFLOAD
)
6919 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
6920 | OMP_REQUIRES_REVERSE_OFFLOAD
);
6921 if (omp_requires
& OMP_REQ_UNIFIED_ADDRESS
)
6922 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
6923 | OMP_REQUIRES_UNIFIED_ADDRESS
);
6924 if (omp_requires
& OMP_REQ_UNIFIED_SHARED_MEMORY
)
6926 = (enum omp_requires
) (omp_requires_mask
6927 | OMP_REQUIRES_UNIFIED_SHARED_MEMORY
);
6928 if (omp_requires
& OMP_REQ_DYNAMIC_ALLOCATORS
)
6929 omp_requires_mask
= (enum omp_requires
) (omp_requires_mask
6930 | OMP_REQUIRES_DYNAMIC_ALLOCATORS
);
6931 /* Do the parse tree dump. */
6932 gfc_current_ns
= flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
6934 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6935 if (!gfc_current_ns
->proc_name
6936 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6938 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6939 fputs ("------------------------------------------\n\n", stdout
);
6942 /* Dump C prototypes. */
6943 if (flag_c_prototypes
|| flag_c_prototypes_external
)
6946 "#include <stddef.h>\n"
6947 "#ifdef __cplusplus\n"
6948 "#include <complex>\n"
6949 "#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n"
6950 "#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n"
6951 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n"
6954 "#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n"
6955 "#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n"
6956 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n"
6960 /* First dump BIND(C) prototypes. */
6961 if (flag_c_prototypes
)
6963 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6964 gfc_current_ns
= gfc_current_ns
->sibling
)
6965 gfc_dump_c_prototypes (gfc_current_ns
, stdout
);
6968 /* Dump external prototypes. */
6969 if (flag_c_prototypes_external
)
6970 gfc_dump_external_c_prototypes (stdout
);
6972 if (flag_c_prototypes
|| flag_c_prototypes_external
)
6973 fprintf (stdout
, "\n#ifdef __cplusplus\n}\n#endif\n");
6975 /* Do the translation. */
6976 translate_all_program_units (gfc_global_ns_list
);
6978 /* Dump the global symbol ist. We only do this here because part
6979 of it is generated after mangling the identifiers in
6982 if (flag_dump_fortran_global
)
6983 gfc_dump_global_symbols (stdout
);
6985 gfc_end_source_files ();
6989 /* If we see a duplicate main program, shut down. If the second
6990 instance is an implied main program, i.e. data decls or executable
6991 statements, we're in for lots of errors. */
6992 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
6993 reject_statement ();
6998 /* Return true if this state data represents an OpenACC region. */
7000 is_oacc (gfc_state_data
*sd
)
7002 switch (sd
->construct
->op
)
7004 case EXEC_OACC_PARALLEL_LOOP
:
7005 case EXEC_OACC_PARALLEL
:
7006 case EXEC_OACC_KERNELS_LOOP
:
7007 case EXEC_OACC_KERNELS
:
7008 case EXEC_OACC_SERIAL_LOOP
:
7009 case EXEC_OACC_SERIAL
:
7010 case EXEC_OACC_DATA
:
7011 case EXEC_OACC_HOST_DATA
:
7012 case EXEC_OACC_LOOP
:
7013 case EXEC_OACC_UPDATE
:
7014 case EXEC_OACC_WAIT
:
7015 case EXEC_OACC_CACHE
:
7016 case EXEC_OACC_ENTER_DATA
:
7017 case EXEC_OACC_EXIT_DATA
:
7018 case EXEC_OACC_ATOMIC
:
7019 case EXEC_OACC_ROUTINE
: